Running Stable Diffusion on macOS with M1
Environment Setup
I'm using Homebrew as my local package manager but you'll need some basic things installed in order to run these initial commands.
brew install cmake
brew install protobuf
brew install wget
Install Rust
I also use asdf
as a version manager so that's how I've decided to install the latest version of Rust.
asdf install rust 1.63.0
Install Conda
Stable Diffusion seems to prefer Conda as an environment manager as well which is built for Python but also supports other languages.
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh
bash Miniconda3-latest-MacOSX-arm64.sh
Clone the Repository
git clone https://github.com/magnusviri/stable-diffusion
cd stable-diffusion
git fetch origin apple-mps-support
git checkout apple-mps-support
Setup the Conda Environment
conda env create -f environment-mac.yaml
conda activate ldm
Customization
Add contiguous()
to the end of line 27 here:
attr = attr.to(torch.float32).to(torch.device(self.device)).contiguous()
Download Weights
curl "https://www.googleapis.com/storage/v1/b/aai-blog-files/o/sd-v1-4.ckpt?alt=media" > sd-v1-4.ckpt
Install Libraries
Note here that installing via the requirements.txt
file actually led to a ton of version conflicts so I found it easier to do it one by one.
pip install torch
pip install numpy
pip install omegaconf
pip install Pillow
pip install einops
pip install torchvision
pip install pytorch_lightning
pip install git+[https://github.com/crowsonkb/k-diffusion/](https://github.com/crowsonkb/k-diffusion/)
Preload Models
python scripts/preload_models.py
Test
python scripts/orig_scripts/txt2img.py --prompt "grimace from mcdonalds riding a dragon" --plms --ckpt sd-v1-4.ckpt --skip_grid --n_samples 1