install stable diffusion webui on ubuntu 22.04

Environment

  • CPU: Xeon E5-2696 v4
  • GPU: Nvidia GTX 1660 (6G)

Nvidia GPU Prepare

Install Nvidia Drivers

1
2
sudo apt update
sudo apt install nvidia-driver-525

Disable/blacklist Nouveau nvidia driver

First step is to Blacklist Nvidia nouveau driver. Open up terminal and enter the following commands:

1
2
sudo bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
sudo bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nvidia-nouveau.conf"

Confirm the content of the newly created modeprobe file blacklist-nvidia-nouveau.conf:

1
2
3
$ cat /etc/modprobe.d/blacklist-nvidia-nouveau.conf
blacklist nouveau
options nouveau modeset=0

Enter the following Linux command to update kernel initramfs:

sudo update-initramfs -u

Last step is to reboot your system:

sudo reboot +0

Install CUDA

Install CUDA 11.5 that is provided from Ubuntu 22.04 official repository.

apt update
apt install nvidia-cuda-toolkit
1
2
3
4
5
6
7
8
9
finuks@u22-gpu:~/Downloads$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:45:30_PST_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0

# check GPU status
nvidia-smi

Download Stable Diffusion models

Go to HuggingFace or Civitai to find a model.

suggest start from “Anything” model if want to draw anime artworks.

Install Stable Diffusion WebUI

install python, wget, git

sudo apt install python3 python3-pip python3-virtualenv wget git

# configure git to use a proxy
git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port
cat ~/.gitconfig

install Anaconda

Download MiniConda Script

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

Install MiniConda3 on Ubuntu 22.04

chmod +x ./Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

Hit the Enter key to start the installation process. Soon, the installer will ask to accept the License, press q, and then type Yes to accept it.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Check Conda Version
conda --v

# create a New environment
conda create -n myfirstenv python

# activate the environment
conda activate myenv

# deactivate the environment
conda deactivate

Create a virtual environment of Python 3.10.10

conda create --name sdwebui python=3.10.10

clone Stable Diffusion WebUI repository

1.Clone the repository of Stable Diffusion WebUI

cd ~
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git ./stable-diffusion-webui

2.Move .ckpt models to stable-diffusion-webui

mv ~/anything-v4.5-pruned.ckpt  ~/stable-diffusion-webui/models/Stable-diffusion/

3.Enter the virtual enviroment

conda activate sdwebui

4.If want to activate virtual environment in a bash script, add these on the top of webui-user.sh

eval "$(conda shell.bash hook)"
conda activate sdwebui

launch Stable Diffusion WebUI

  • If the VRAM of GPU is lower than 4GB, add: COMMANDLINE_ARGS=--medvram --opt-split-attention
  • If your PC has RAM lower than 8GB, add: COMMANDLINE_ARGS=--lowvram --opt-split-attention You could also add --listen so you can access the WebUI from other PC on the same network. Or add –share to generate a public Gradio link for accessing WebUI while deploying SD WebUI to servers.

Run webui.sh, it will install all the dependencies. Then a link should pop up:

./webui.sh --lowvram --opt-split-attention --listen

how to update Stable Diffusion WebUI

1.Get current branch

git rev-parse --short HEAD

2.Pull latest files

git pull

3.If something is broken after updating, roll back to the previous branch

git checkout "branch"

How to use Stable Diffusion WebUI

prompts

Use Prompts and Ngative Prompts to tell AI what to draw.

See Vodly Artist name and Danbooru tags for choosing prompts.

For example, to draw Jeanne from Fate/Grand Order, we type the name of the character and characteristics of her body in the prompt fields.

jeanne d'arc from fate grand order, girl, (best quality), (masterpiece), (high detail), ((full face)), sharp, ((looking at viewer)), ((detailed pupils)), (thick thighs), (((full body))), (large breasts), vagina, nude, nipples

Then type negative prompts.

lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts,signature, watermark, username, blurry, artist name

Some interesting plugins

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
git clone --recursive https://github.com/TencentARC/T2I-Adapter.git ./T2I-Adapter
git clone --recursive https://github.com/KohakuBlueleaf/a1111-sd-webui-lycoris.git ./a1111-sd-webui-lycoris
git clone --recursive   https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git ./a1111-sd-webui-tagcomplete
git clone --recursive  https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111.git ./multidiffusion-upscaler-for-automatic1111
git clone --recursive   https://github.com/fkunn1326/openpose-editor.git  ./openpose-editor
git clone --recursive    https://github.com/adieyal/sd-dynamic-prompts.git ./sd-dynamic-prompts
git clone --recursive    https://github.com/ototadana/sd-face-editor.git ./sd-face-editor
git clone --recursive   https://github.com/vnrat/sd-webui-3d-open-pose-editor.git ./sd-webui-3d-open-pose-editor
git clone --recursive    https://github.com/ClockZinc/sd-webui-IS-NET-pro.git ./sd-webui-IS-NET-pro
git clone --recursive    https://github.com/kohya-ss/sd-webui-additional-networks.git ./sd-webui-additional-networks
git clone --recursive  https://github.com/Mikubill/sd-webui-controlnet.git ./sd-webui-controlnet
git clone --recursive   https://github.com/hnmr293/sd-webui-cutoff.git ./sd-webui-cutoff
git clone --recursive  https://github.com/yfszzx/stable-diffusion-webui-images-browser.git ./stable-diffusion-webui-images-browser
git clone --recursive  https://github.com/hako-mikan/sd-webui-lora-block-weight.git  ./sd-webui-lora-block-weight
git clone --recursive  https://github.com/Akegarasu/sd-webui-model-converter.git  ./sd-webui-model-converter
git clone --recursive  https://github.com/Scholar01/sd-webui-mov2mov.git   ./sd-webui-mov2mov
git clone --recursive  https://github.com/opparco/stable-diffusion-webui-composable-lora.git  ./stable-diffusion-webui-composable-lora
git clone --recursive  https://github.com/opparco/stable-diffusion-webui-two-shot.git ./stable-diffusion-webui-two-shot
git clone --recursive  https://github.com/toriato/stable-diffusion-webui-wd14-tagger.git  ./stable-diffusion-webui-wd14-tagger
git clone --recursive  https://github.com/Coyote-A/ultimate-upscale-for-automatic1111.git ./ultimate-upscale-for-automatic1111
git clone --recursive    https://github.com/continue-revolution/sd-webui-segment-anything.git ./sd-webui-segment-anything
git clone --recursive https://gitcode.net/ranting8323/stable-diffusion-webui-localization-zh_CN.git ./stable-diffusion-webui-localization-zh_CN