DEV Community

Cover image for How to install Stable Difussion WebUI and ControlNet 1.1 on Ubuntu
Juan Felipe Lujan
Juan Felipe Lujan

Posted on • Edited on

How to install Stable Difussion WebUI and ControlNet 1.1 on Ubuntu

In this tutorial, I will explain how to configure Ubuntu 22.04 to take advantage of an Nvidia GPU and run stable Diffusion via Stable-diffusion-webui.
This is a permanent alternative as Google might restrict the use of Colab for Stable Difussion in the future.

Stable-diffusion-webui Prerequisites:

  • Python 3.10.6 (Comes with Ubuntu 22.04).
  • Git (Comes with Ubuntu 22.04).
  • Python venv
  • Nvidia drivers

Since I don't have a Linux Machine At home, I will use a virtual machine on Google Compute Engine. If you're not using a VM and just want to know how to install stable difussion feel free to skip this section.

Creating the virtual machine.

Sign in to Google Cloud and type Compute Engine on the search bar located on the top of your screen.
Make sure that billing is enabled for your Cloud project.
Enable the Compute Engine API if prompted.
On the Compute Engine page, click Create an instance.
In the Machine Configuration section, click on the GPUs tab, select NVIDIA T4, and 1 in the number of GPUs.
Under Machine type, select n1-standard-4.

Click Change in the Boot Disk section to begin configuring your boot disk and Ubuntu 22.04 LTS from the version list.

Creating a VM for Stable Difussion
Configure any additional settings as needed, such as allowing HTTP traffic in the Firewall section.
Click Create to create the VM.
Once the VM is ready, click the SSH button to enter the command line terminal.

How to SSH into Ubuntu VM

Preparing Ubuntu 22.04

From this point on, make sure to run all the commands on the same directory:

Update and upgrade system packages

sudo apt update && sudo apt upgrade -y

Enter fullscreen mode Exit fullscreen mode

you might encounter a couple of purple screens like the following:

How to update Ubuntu Kernel

Hit enter without changing the defaults.

Install Nvidia drivers.

Run the following commands

sudo apt -y install nvidia-driver-525-server && sudo apt -y install nvidia-utils-525-server \ sudo apt -y install nvidia-cuda-toolkit 
Enter fullscreen mode Exit fullscreen mode

Reboot

sudo reboot
Enter fullscreen mode Exit fullscreen mode

Install Python-venv

Once the machine is back up, install Python3-venv with the following command:

sudo apt install python3.10-venv -y

Enter fullscreen mode Exit fullscreen mode

Prerequisites check.

To verify that the prerequisites are correctly installed and available on the local machine run:

python3 -V

Enter fullscreen mode Exit fullscreen mode

Expected output: Python 3.10.6

nvidia-smi
Enter fullscreen mode Exit fullscreen mode

Expected output (similar):

nvidia-smi correctly installed

Running the following command should not output any errors

python3 -c 'import venv'
Enter fullscreen mode Exit fullscreen mode

Installing and running Automatic1111's Stable-Difussion-Webui.

Run the following command (source). It might take a few minutes while it downloads and prepares the application components:

bash <(wget -qO- https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.sh) --listen --enable-insecure-extension-access 
Enter fullscreen mode Exit fullscreen mode

note: The --listen and --enable-insecure-extension-access command line arguments allow you to access and install Stable difussion extionsions remotely, if you are using a physical Ubuntu Machine, feel free to remove them.

Installation is complete when you see:
Running on local URL: http://0.0.0.0:7860

If you're following along in Google Cloud, grab the virtual machine's public IP from Google Compute Engine, paste it on your browser's address bar, followed by :7860, and press enter. In a physical ubuntu machine enter localhost:7860 in your web browser.

Welcome to Automatic1111's Stable Diffusion Webui.

Happy prompting!

Enable ControlNet

With ControlNet, you have much more power regarding image-to-image generation. It enables things such as pose transfer and style transfer.

Installing ControlNet.

On Automatic1111's webui, go to the Extensions tab, hit Available, and then Load From.
Find sd-webui-controlnet in the list populates and click install.
Wait until processing finishes.
Go back to the Installed tab right next to Available, Click Apply and restart UI.

Wait a couple of minutes before refreshing the website.
You should see the ControlNet section when the UI reloads.

ControlNet extension Installed on Stable Difussion

To complete the installation of Controlnet you need to download the models that go along with it.
Start a new SSH session (or open a new terminal on a physical computer), Paste the following commands on the new command line terminal to download the ControlNet models from HuggingFace.

sudo apt-get install git-lfs
git lfs install
git clone https://huggingface.co/lllyasviel/ControlNet-v1-1
mv  ControlNet-v1-1/* stable-diffusion-webui/models/ControlNet/

Enter fullscreen mode Exit fullscreen mode

If the models in the ControlNet section show up in the models dropdow, then you're set!!!

ControlNet models installed

With that, we've finished the installation of stable-diffusion-webui and ControlNet version 1.1
Some good resources for finding the Stable Diffusion models and tutorials are:

  • Stable Diffusion Subreddit
  • Hugging Face

Please let me know if you have any issues replicating this procedure.
Cheers!

Top comments (0)