I recently started learning Stable Diffusion (SD), which is a generative AI tool for art. This blog records how I set up SD in my local linux system.
Step 0. Prerequisite
To run SD locally essentially is to run a package on the computer. It requires the right hardware and software.
For hardware, both CPU and GPU will work, with GPU being much faster than CPU. My computer has one NVIDIA 3090 GPU.
For software, we are talking about the environment in which the SD package can successfully execute. We need the correct python version and all supportive packages. I have a Linux system with conda installed. I created an environment with the recommended python version (3.10.6) to run SD:
conda create -n py3.10 python=3.10.6
We also need git to get the SD related packages. With conda, git is installed in the new environment by default.
All other supportive packages (eg. pytorch) will be installed automatically in the next step.
Step 1. Install UI
Honestly, it’s not necessary to use a UI to run SD as a package. It’s totally fine to call SD in command line. However, a UI makes it much easier to tune parameters and to view results on the fly. As a beginner, it’s much more friendly to start with a UI.
There are several UIs available for SD. I went with the most popular one, called Automatic1111. It’s an open source package. It can be obtained by using “git clone”. Detailed information about the package can be found on the git page: https://github.com/AUTOMATIC1111/stable-diffusion-webui
Run the commands below in a terminal to get and launch Automatic1111.
conda activate py3.10 git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git cd stable-diffusion-webui ./webui.sh
I ran into some time out error and had to re-run the last line above. But everything turned out fine. And the UI started automatically afterwards in the browser.
The Automatic1111 package came with a default SD model v1.5 ready to use.
I tried a very simple prompt “a dog running in the park” and everything else with default settings, except the batch size to be 4. Below are the four images I got. I can tell they are all dogs. But they are all wrong in an apparent way. Tuning the dogs to look correct and nice is what I’ll learn to do next.
Reference
Automatic1111 git page: https://github.com/AUTOMATIC1111/stable-diffusion-webui
YouTube channel: Sebastian Kamph, Stable Diffusion Beginner Guide