Automatic1111 - OSX
Automatic1111 is considered the best implementation for Stable Diffusion right now. It is a Python program that you’d start from the command prompt, and you use it via a Web UI on your browser. It runs on all flavors of OS: Windows, Mac (M1/M2), or Linux.
For this doc, I will focus on Macs only since that’s what this page is about, and likely the only reason you are reading this page because the information on how to do it properly on M1/M2 Mac is not readily available.
Before you begin
None of these commands require sudo
. Do NOT ever run any of these commands with sudo
because instead of installing libraries into the environment, it might end up installing them into the Python env that comes with your Mac, which is a very bad idea.
Remember, no sudo with any of these.
Read Instructions
Read the instructions below but don’t do anything yet, it’s better to read through all the advanced config before you start your process, such as creating your own virtual environment, and installing pytorch nightly. These are all optional but recommended if you want to get the most out of your M1/M2 Mac for Stable Diffusion.
Read all the instructions on the repo: https://github.com/AUTOMATIC1111/stable-diffusion-webui
If this is all very alien to you then you can also Google or search for YouTube videos on automatic1111 installation
. There are hundreds of them. But you really don’t need videos. Just read the instructions on the repo and you will be fine.
Specifically, for Macs, there’s a special page for Installation on Apple Silicon. Read it.
Virtual Environment
You should always run Python programs inside their own virtual environment. Never install anything to your system directly. Thankfully, the automatic1111 install will create a virtual environment for you if you aren’t inside one when the installation started.
Do not do these steps if you don’t know what you’re doing. These are for geeks and nerds only. Yes, I identify as a nerd. You are free to call me a nerd if you like. I consider it as a compliment — likely the only gay guy you know who don’t mind it.
Automatic1111 will install fine without creating your custom virtual env. Not having your own custom env just meant that you are now dependent on whatever A1111 creates for you, and I don’t know what that venv is and where it will create it. I haven’t read the source thoroughly. I might some day…. I think that it would use the Python standard library venv
which imo is very clunky.
pyenv
If you are familiar with pyenv, I recommend that you just create your own pyenv with 3.10.9
(as of this writing) before the installation starts. Automatic1111 will then install to that custom venv that’s active. This gives far better flexibility.
Do not install 3.11
and above, even if it seems “newer”. There are some compatibility issues when I tried to do it in the past. Stick with 3.10
. There are new minor revisions e.g. 3.10.12
but I can’t guarantee if they will work since I’m running 3.10.9
myself with automatic1111. You can try it if you really want to, but I can’t help you if you run into issues.
# Make the specific Python version available to pyenv
pyenv install 3.10.9
# Create a virtualenv called automatic1111 and Python 3.10.9 into it
pyenv virtualenv 3.10.9 automatic1111
If the above is gibberish to you, please don’t do anything about these because it‘s very dangerous to run shell commands unless you know what they are for!
conda
You can alternatively use conda but I personally don’t use it and can’t give you any advice if you run into issues.
Do not ever install conda simultaneously with pyenv or be prepared to run into environment hell. You have been warned.
- If you don’t heed my warnings and are now in hell, you can get out of it by not running the init scripts for conda.
- The init scripts should be in your
~/.zshrc
assuming that your OS is relatively fresh and is usingzsh
as the default shell. - If you’re using bash as your default shell (which is the default in older OSX), then the inits are either in
~/.bashrc
or~/.bash_profile
. - Comment them out and restart your terminal.
Install Automatic1111
Clone the repo, switch to the virtualenv that you created earlier, and then install automatic1111.
You can clone the repo anywhere but if you just don’t want to think about it, then just clone it to your home directory — though I highly recommend that you create a top level folder and put all your SD stuff inside coz it would make your life easier later on.
There are so many things that you would need / want to download with SD, and having a folder that has everything would keep things neatly organized.
# Make top level folder just for sd
mkdir ~/sd
# Change to that folder
cd ~/sd
# ~ is just an alias to your home directory
# If your username is gymdreams on OSX,
# then ~ is /Users/gymdreams
# The above is equivalent to
# cd /Users/gymdreams/sd
# Clone the repo
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
# Switch to the repo folder
cd stable-diffusion-webui
# If somehow you are not doing this step after cloning the repo,
# then here’s the full path
cd ~/sd/stable-diffusion-webui
# Switch to the automatic1111 env in the shell
# If you don’t do this then automatic1111 will create an environment for you
# greatly reducing your flexibility
pyenv shell automatic1111
# Run webui.sh to install automatic1111
# You will get errors but that’s normal
# because you haven’t added the required configs yet
# You should still run this step because
# it will install all the necessary dependencies
./webui.sh
The above will run automatic1111 but it will generate errors immediately upon first run. This is normal because we haven’t added the required configs yet, but you should still do the step above because it installs all the necessary dependencies. It will take a while.
By a while, I meant it will be noticeable, because besides the libraries, it will download models. So if it has been running for 10-30 minutes, don’t fret. It’s normal.
Optimizations for Mac
Pytorch Nightly
Do this step after you have run ./webui.sh at least once so that the Pytorch Nightly in this step will overwrite the pytorch that was installed by automatic1111.
If you want your M1/M2 mac to generate images at an optimal speed, then you should install the Pytorch Nightly into your virtualenv. This is why it’s far better to set up your own virtualenv up manually with pyenv.
There’s official instructions on Apple.com: Accelerated PyTorch training on Mac for how to do this. But here’s a gist.
First, switch to the virtualenv that you created earlier:
# Switch to the automatic1111 env in the shell
pyenv shell automatic1111
If you didn’t use pyenv
to create your own environment, I don’t actually know where automatic1111 install your venv so you probably should skip this part completely because while this will greatly improve the image generation speed, it’s not necessary, and I’d rather that you have a slow experience rather than messing up your entire machine.
Then install pytorch nightly with pip:
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
Change Config
In order for Macs to actually use Automatic1111, you need to start it with a custom parameter.
Edit webui-user.sh
that’s included in the root folder of the repo, then edit the custom arguments in this line:
# Commandline arguments for webui.py, for example: export COMMANDLINE_ARGS="--medvram --opt-split-attention"
export COMMANDLINE_ARGS="
--no-half
--skip-torch-cuda-test
"
I split them into multiple lines because it’s easier for me to add my long options. The list of options that I personally use span 20 lines. You can keep them on one line if you want:
export COMMANDLINE_ARGS=" --no-half --skip-torch-cuda-test "
Here are some explanation of the flags:
--no-half
— this is the most important flag for Macs. It tells Automatic1111 to not use half precision. If you don’t use this flag, you will get an error immediately when you try to generate images.--skip-torch-cuda-test
— This tells Automatic1111 to skip the CUDA test. CUDA is a set of libraries that allows nVidia GPU to be used for computation. Since Macs don’t use nVidia GPUs, this test will always fail. You can skip it to save some time during boot.
Start Automatic1111
And that’s it! You can now start Automatic1111 with ./webui.sh
in the shell and start playing with it. Remember to switch to your virtualenv before you start Automatic1111 or it will install a new one for you, which then will not come with all the optimizations that you have done.
cd ~/sd/stable-diffusion-webui
pyenv shell automatic1111
./webui.sh
Questions
If you have any questions, please feel free to reach out to me on social media. For these technical things, it’s best to do it on Discord.
- My Discord username is
gymdreams
— it’s the new style without the Discriminator.
You can find my other contact info at the end of the About Me page of my main website.