As we shared in the posts earlier Stable Diffusion is quite the hype at the moment. There are numerous Google Colab notebooks available for anyone to use (you need a Google Colab subscription) but as the Stable Diffusion model is open source people have discovered many different ways to run Stable Diffusion on their PCs.

Now in the post we share how to run Stable Diffusion on a M1 or M2 Mac

Minimum Requirements

  • A Mac with M1 or M2 chip.
  • 16GB RAM or more.
  • macOS Monterey 12.3 or higher.

Setup

Open the Terminal and follow the following steps. Install Homebrew using the command below, unless you already have Python 3.10 already installed on your Mac. You can check your version using the command (-V is capital): python3 -V or python3 --version

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

Run the below commands to ensure you have latest versions if you already have Python or HomeBrew installed before.

brew update
brew install python

Next step is to clone the Stable Diffusion repository and setup the virtual environment

git clone -b apple-silicon-mps-support https://github.com/bfirsh/stable-diffusion.git
cd stable-diffusion
mkdir -p models/ldm/stable-diffusion-v1/
python3 -m pip install virtualenv
python3 -m virtualenv venv

Activate the virtualenv just created. Afterwards whenever you want to run Stable Diffusion you will need to run this

source venv/bin/activate
brew install cmake protobuf rust

UPDATE: 29 Sept – Some people have shared that using ‘pip install protobuf==3.19.4’ has helped resolve their errors, so there must be some incompatibility with latest version. So you could modify the above command to be: brew install cmake protobuf==3.19.4 rust or run it separately as well but then exclude it from above.

Install the dependencies using:

pip install -r requirements.txt

Now this step you need to do in your browser. Navigate to the site Hugging Face, register if you don’t have an account as you need this to download the Stable Diffusion model.

Download sd-v1-4.ckpt (4 GB) from the site and save it with the name “model.ckpt” under models/ldm/stable-diffusion-v1/model.ckpt in the directory you created above.

Run Stable Diffusion

Now you are ready to run Stable Diffusion and start creating your own art.

python scripts/txt2img.py --prompt "a beautiful dense amazon forest with tall trees and thick cannopy, moss on tree trunks and rocks, big rocks on the ground, a lonely boy stands staring into the path that leads into the forrest, trending on Artstation" --n_samples 1 --n_iter 1 --plms

Generated images will appear in folder outputs/txt2img-samples/. You can also fine tune and use other parameters in the script by referring to the details provided on this page.

If you'd like to support our site please consider buying us a Ko-fi, grab a product or subscribe.