Running Stable Diffusion on your M1/M2 Mac
What you need:
- An M1 or M2 system
- A lot of ram. The more the better.
- At least 15GB - 20 GB of free Disk Space
- A little bit of time. I advise 1 - 2 hours to have a little bit of wiggle room. Depending on your connection speed downloading the needed packages can take it’s time
I’m no developer and got it to work with the help of someone with experience. Thank you @Deniz and thank you @Tobias. I do not think that you can break something with this installation process. But i cannot be held liable 😅 It worked for me does not mean that it’ll work for you. The best way would be to create a time machine backup beforhand. Continue on your own risk.
Regarding the size of this tutorial
This tutorial seems to be long, but it’s only looking huge because I created a dummies guide and tried to add every detail worth mentioning for someone who has no development background. A developers tutorial would fit on one paper napkin easly ;)
With that out of the way. Here is a short explanation of what we want to achieve: For SD to work locally we need python, a virtual machine, stable diffusion itself and its weights.
Let’s start installing!
First you need to have python installed. Open up your terminal window …
…and type in
It should give you this error msg since normally you don’t have it:
Let’s install it. The best way is to use Homebrew (https://brew.sh/).
Enter this command into your terminal
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
It will ask for permission and your password. Enter it and hit 'Enter'. Now the installation process will begin.
After a short moment. It again asks for permission which you can give by hitting 'Enter' again
This can take a little bit of time as brew will need to download and install Command line tools for Xcode (or parts of it) https://developer.apple.com/xcode/
After that it will install Homebrew. It’s just one long process. Here are two screenshots taken during this process.
Feel free to use this time to enjoy my newest animation showreel ;)
After the installation is done, the terminal should look like this.
Beware! Sometimes it can ask you for two additional commands under ‘Next Steps’ so read it carefully.
Let’s test if brew is working by entering
Wonderful! Now you can start installing python. First Update brew:
Since we just installed it, it should be up to date. Just checking 😅
BTW you can create great effects with the help of AI Check out this small animation I did
Then install python
brew install python
Looks like it worked. Test it by entering
Normally it will return “Python 3.8.9” which is an old version. You have to close and reopen terminal and enter the code again
Now it should show you the version number 3.10.6
Next step ist to install the repository directly from github. Enter this code in full.
git clone -b apple-silicon-mps-support https://github.com/bfirsh/stable-diffusion.git cd stable-diffusion mkdir -p models/ldm/stable-diffusion-v1/
It should look like this:
This time the installation will be faster. At the end it should look like this
Now let’s setup a virtual environment
python3 -m pip install virtualenv
Then enter the second command
python3 -m virtualenv venv
Now we cans tart the virtual environment
You successfully started the virtual environment when you see (venv) at the beginning.
Almost done. Now we need to enter and let it run. After enteringthe command and hitting enter at the beginning it seems to stop but just give it time.
pip install -r requirements.txt
While it’s working you could think about how a great animation / explainer can benefit explaining and selling your process or product. I create simple and highly detailed movies for every kind of use case with the goal of engaging your viewers.
It should look like this when its done. Just delete the ‘21-pipn’ command.
The last thing you’ll need to do ist entering this command
brew install Cmake protobuf rust
It will start downloading again 😅 This again will take a few minutes.
Finally we can put the weights into the newly created folder folder. You can download the weights here. Beware they have a size of about 4 GB
Rename the downloaded file to model.ckpt and place it in this folder:
[your user name]/stable-diffusion/models/ldm/stable-diffusion-v1
Make sure you put it into the right folder (!) since there is also a wrong LDM folder in the main folder stable-diffsuion.
Now. Close your terminal window and open a new one. Here you will enter the following to commands to start prompting.
Jump into the stable diffusion folder by entering:
Activate the virtual environment:
That’s it. You can now write your first prompt. How about this one.
python scripts/txt2img.py --prompt "haesthetic award winning commission, antrho shiba inu wearing, orange hoodie, art, greg rutkowski, character design, charles bowater, ross tran, hyperdetailed, photorealistoc, detailed face 4k, cute, artstation, deviantart" --H 512 --W 512 --ddim_steps 60 --n_iter 1 --skip_grid --scale 7.5
- Depending on your GPUs memory you can enlarge the image in steps of 64px
- If you start a prompt the first time, SD will again download some packges. But this is a one time thing.
- If you get an error message, please check if your model.ckpt file is in the right directory
While waiting for your first prompt to finish. Take a look at this animation I created some time ago. All visuals were created by midjourney.
Please share your creations and speeds with me by adding me or using the hashtag #jacquesalomo I’m looking forward to your creations.
This was my prompt result:
These are my speeds
- My M1 Max Studio with 64GB Ram takes about 35 Seconds to create a 512x512 px image
- My 2019 16” Mac Book Pro (8Core 2,3Ghz i9 64GB AMD 5500M 8GB) takes about 4 minutes
If you have any further questions regarding …
- this tutorial
- great animation and film projects
- ai experiments I’m doing
…feel free to
Award wining Motion and User Interface Designer
I develop innovative explainers and imagefilms for corporations and startups.
I support you in the entire creation process - from analysis and conception to visual and technical implementation and qa. My products are used by BMW, Intel, Bertelsmann, Siemens, VW, PAYBACK and successful startups.