Installing Stable Diffusion on the RTX 4090

DISCLAIMER: As an Amazon Associate, I earn from qualifying purchases. Mostly Harmless may receive a commission at no extra cost to you. Thank you for your support!

In this post we’ll cover how to set up Stable Diffusion on a PC with an NVIDIA RTX 4090 using Ubuntu 22.04. This assumes you have basic tools set up like Python (I’m using 3.10), git etc., and have already installed the NVIDIA drivers for your RTX 4090. I’m running Ubuntu as a server, and connecting to it via my MacBook, for the simple reason I want all my GPU working for Stable Diffusion, and not driving monitors.

First make sure NVIDIA is installed:

nvidia-smi

This should show you something like this:

Next make sure CUDA is installed:

nvcc --version

If it’s not, run the below and try again:

sudo apt install nvidia-cuda-toolkit

The fastest, easiest way to install is using AUTOMATIC1111’s webui, here: https://github.com/AUTOMATIC1111/stable-diffusion-webui.

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

This tool requires certain more recent versions of the xformers and pytorch libraries, so to ensure you have the correct versions, the first time run:

python3 launch.py --xformers --listen --reinstall-xformers --reinstall-torch

You can omit the –reinstall-* args on future runs. A successful run looks something like this:

Note the Running on local URL: http://0.0.0.0:7860 – this means that any machine on your local network can connect to Stable Diffusion by replacing 0.0.0.0 with the ip address of your Ubuntu machine. If you get a connection time out, it’s most likely a ufw (Uncomplicated FireWall) issue, you need to unblock port 7860, more details can be found here: https://help.ubuntu.com/community/UFW.

It’s that simple. A 512×512 image takes less than a second to generate. We’ll cover more in depth in future posts.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top