I wanted to set up a running Stable Diffusion installation at home for a long time. The whole thing I have now started over Easter with two goals that I have pursued. First I want to learn how to write good prompts so that the generated images also look good in my eyes because whether art is beautiful or not is in the eye of the beholder. The second goal I am pursuing is to train a net myself with my specific requirements. I would like to generate images of PFM-1 anti-personnel mines for a mine detection project, which can be used as synthetic data to improve the detection rate of neural networks. Since the geometry of stable diffusion does not necessarily correspond to the original, at least false positive tests could be possible. With Stable Diffusion this is exactly the exciting part for me, if I can teach an already trained model even more capabilities. So I’ll start right now with the installation and setup of an appropriate environment on a freshly installed Ubuntu 22.04 LTS system.
Installation Guide – Stable Diffusion web UI
This section deals with the installation of the Stable Diffusion web UI which, thanks to the AUTOMATIC1111 repository, sets up a web interface based on the Gradio library on the target system. To say it in advance, this works really easy and without any problems.
Hardware note: As I understand the project, a NVIDIA GPU with at least 12GB of ram is mandatory. The CPU and the system memory should not be too tight but will not be used much for this project. The description of the system I use for this project can be found here: Deep Learning PC.
Note MIFCOM Deep Learning PC: If you want to buy a ready-built PC without screwing yourself, you will surely find it at the Munich-based company MIFCOM, which manufactures very high-quality and powerful computers for the broad field of artificial intelligence, also according to individual requirements. From my professional life, I have made very good experiences with the company MIFCOM and appreciate the high quality in the construction of the computers as well as the very good service.
Time required for installation (30 to 40 minutes)
I would like to give a short estimation of the time needed. Depending on the internet connection the installation of AUTOMATIC1111 takes about 30 to 40 minutes and 9GB of disk space are used. In addition to the 9GB of disk space, there is also the space required for the various trained models that are still needed to be able to generate images. So after a few evenings I had a good 50GB of space occupied just for models I was trying out. During the installation you don’t have to sit in front of the computer. In principle, the installation runs fully automatically without the user having to contribute anything.
Preparation of virtual environment, drivers and co.
As I wrote in the beginning, I used a freshly installed Ubuntu 22.04 system for this report. It always makes sense for such projects to install them in a virtual environment. This is optional but I recommend to do it this way. I also had to install all drivers from NVIDIA and CUDA to get Stable Diffusion running with GPU support. So now here is my description of what preparations I made.
Set up Anaconda
Since I install everything in a virtual Anaconda environment to be able to delete these environments without changing my Ubuntu system itself here are the commands to set up a virtual environment called stable-diffusion. First of all you have to check which Anaconda version is the right one for your Linux system. To do this open the following link.
In April 2023 it was the version of the installation script Anaconda3-2023.03-Linux-x86_64.sh which has the following URL. You have to copy the current URL into the clipboard. We need this later for the installation.
Now once bring the system up to date with the following command.
sudo apt-get update
Then please install curl as we need curl to download and run the installation script.
sudo apt install curl -y
I then created a working folder with the following two commands and also went directly to it in the terminal window.
Now execute the following command in the working folder anaconda. Here you have to paste the URL to the installation script. You have copied this to the clipboard before.
curl --output anaconda.sh https://repo.anaconda.com/archive/Anaconda3-2023.03-Linux-x86_64.sh
Now you can generate the checksum from the script and compare it with the information on the Anaconda archive page. This way you can be reasonably sure to run the right script for the installation.
You can now start the installation with the following command. Anaconda is then installed on your system.
You have to answer YES a few times and at the end I would suggest No at the question if the Anaconda environment should always start. If you answered all questions with YES you can deactivate the automatic start of the Anaconda environment with the following optional command.
conda config --set auto_activate_base false
Many of the commands to operate Anaconda are summarized in the following PDF. This will help you to get started with Anaconda as a software.
First of all conda must be activated. If you do not want to restart the computer, please execute the following command.
Now create a virtual environment called “stable-diffusion” with the following command. We will now install everything in this environment.
conda create --name stable-diffusion
You start this environment again with the following command.
conda activate stable-diffusion
If you want to leave the virtual environment, use this command to exit Anaconda.
Now you have the virtual environment running and can install drivers and do whatever you want in it without affecting the actual Ubuntu environment with your actions.
CUDA und Treiber von NVIDIA
I did the installation on a completely freshly set up Ubuntu 22.04. Therefore, I also had to install the necessary NVIDIA drivers. I installed the NVIDIA drivers for my graphics card via Ubuntu’s software manager. This works great and is very simple. Afterwards I installed CUDA 11.7 in the virtual Anaconda environment. If you choose the same procedure then it’s best to follow the NVIDIA guide here to install the 11.7 CUDA support under Ubuntu 22.04:
Note: At the end of April I still had problems getting AUTOMATIC1111 to work with CUDA 12.1.1. Therefore I recommend to use the somewhat older CUDA version 11.7. With this version there will be less problems with the finetuning with Dreambooth. As soon as everything runs without problems with the new 12.X version I will update my manual here (as of 2023.05.01).
Here is the link to the CUDA archive at NVIDIA to install later versions.
URL: Deb Network Archive
Below is the link to the CUDA 11.7 version which worked fine for me and which I also used for my tutorial here.
Now everything is set up and the installation of AUTOMATIC1111 can start. More about this in the second part of the installation instructions.
Article overview - Stable Diffusion:Stable Diffusion - AUTOMATIC1111 Ubuntu installation part 1/2
Stable Diffusion - AUTOMATIC1111 Ubuntu installation part 2/2
Stable Diffusion - Generate images locally with prompt examples
Stable Diffusion - Dreambooth Training Finetuning Setup Part 1/2
Stable Diffusion - Dreambooth Training Finetuning Run Part 2/2