Zabriskije / SD-to-CoreML

Shell script to convert Stable Diffusion 1.5 models to Core ML
GNU General Public License v3.0
51 stars 6 forks source link
apple bash bash-script coreml coreml-models ml-stable-diffusion shell shell-script stable-diffusion

SD to Core ML

The neatest script for converting Stable Diffusion 1.5 models to Core ML

Features β€’ Usage β€’ Prerequisites β€’ Troubleshooting

Features

Usage

Before running: be sure to meet the prerequisites, place the script in the same folder as the model you want to convert, and open it with a code editor since there is two folder paths that need to be adjusted. You'll find both at the start of the script:

When done, the script is ready to be used.

You can run it by dragging it into the Terminal app and then pressing Enter, or set it to (always) open with the Terminal App: right-click on the file β†’ "Get Info" β†’ "Open with" β†’ "Terminal".

Once started, it will prompt you to specify your model's name:

When set, the script will proceed to display all the possible conversion options:

  1. CKPT β†’ All
  2. CKPT β†’ Diffusers
  3. SafeTensors β†’ All
  4. SafeTensors β†’ Diffusers
  5. Diffusers β†’ ORIGINAL
  6. Diffusers β†’ ORIGINAL 512x768
  7. Diffusers β†’ ORIGINAL 768x512
  8. Diffusers β†’ SPLIT_EINSUM
  9. Change model name

The CKPT β†’ All and SafeTensors β†’ All options will convert your model to Diffusers, then Diffusers to ORIGINAL, ORIGINAL 512x768, ORIGINAL 768x512, and SPLIT_EINSUM β€” all in one go.

All the steps will show a success or failure log message, including a visual and auditory system notification. In case you don't like the latter, you can change its behavior by going to "System Settings..." β†’ "Notifications" β†’ "Script Editor"; or by deleting all the lines in the script starting with osascript.


Prerequisites

The script assumes you have Homebrew, Wget, Xcode, and Miniconda (with the ml-stable-diffusion environment) already installed. If not, please proceed as follows:

  1. Install Homebrew and remember to follow the instructions under "Next steps"

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install Wget

    brew install wget
  3. Download and install Xcode

  4. Download and Install Miniconda

  5. Once done, run the commands below according to their display order

    git clone https://github.com/apple/ml-stable-diffusion.git
    conda create -n coreml_stable_diffusion python=3.8 -y
    conda activate coreml_stable_diffusion
    cd ml-stable-diffusion
    pip install -e .
    pip install omegaconf
    pip install safetensors
  6. Download this Python script and place it in the same folder as the model

Troubleshooting

File

Miniconda

Terminal errors

Terminal warnings