Since yesterday evening, when I finally perfected the process for converting existing
#StableDiffusion models (in either CKPT or SAFETENSOR format) to CoreML format, Iโve converted six models. Of them, all except for one work fine ๐
So, in case this helps anybody else, here are the important things to remember:
1. You *must* use Python 3.8. If you any other Python version, you will end up with errors. (Not that Iโve tested all Python versions, but I did have errors with Python 3.9 and have read reports of others โฆ)
2. You should be on Ventura 13.1 or higher.
3. You need the models to be in Diffusers format to run the conversion, but the easiest way that has worked for me is to download a CKPT file, convert it to Diffusers and point the script at the local folder with the Diffusers format model.
4. HuggingFace folks have a bunch of conversion scripts here:
https://github.com/huggingface/diffusers/tree/main/scripts5. The above scripts donโt mention SAFETENSOR format in the file names but SAFETENSOR is just CKPT with some changes. The CKPT conversion file has an extra argument named โ--from_safetensorsโ so you can use the same script for CKPT to convert SAFETENSOR files with that extra argument.
6. You can use the Apple conversion script to convert one element at at a time using the different arguments such as โ--convert-unetโ, โ--convert-text-encoderโ etc. You donโt have to run all of them together. In fact, it turned out when I ran them all together, sometimes a component might be left out โ generally the text encoder.
7. Once youโve converted all the components and have them in one folder, you have to run the Apple conversion script once more with the โ--bundle-resources-for-swift-cliโ argument (pointing at your output folder) to create the final compiled CoreML model files (.mlmodelc) from your .mlpackage files.
Thatโs it ๐ If you do all of the above, it should be fairly straightforward to create new CoreML models from existing StableDiffusion models.
Feel free to hit me up should you run into issues. Since Iโve gone through all this, Iโd be happy to help anybody else facing the same issues โฆ.
#CoreML #StableDiffusion #MachineLearning #DeepLearning #ModelConversion