Running Stable Diffusion on AMD Radeon GPU in Docker

To start, we need Ubuntu with git, make, docker and ROCm installed.

ROCm will be set by instructions.

Brief installation instructions for ROCm
sudo apt install "linux-headers-$(uname -r)" "linux-modules-extra-$(uname -r)"
sudo usermod -a -G render,video $LOGNAME
wget https://repo.radeon.com/amdgpu-install/6.1.2/ubuntu/jammy/amdgpu-install_6.1.60102-1_all.deb
sudo apt install ./amdgpu-install_6.1.60102-1_all.deb

# If an error occurs, you must run:
sudo chown -Rv _apt:root /var/cache/apt/archives/partial/
sudo chmod -Rv 700 /var/cache/apt/archives/partial/

sudo apt update
sudo apt install amdgpu-dkms
sudo apt install rocm-hip-libraries
sudo reboot

Let's copy the project that allows you to configure and run Stable Diffusion in a docker container:

git clone https://github.com/HardAndHeavy/stable-diffusion-webui-rocm-docker
cd stable-diffusion-webui-rocm-docker

Let's launch Stable Diffusion using the command make run. When you first start, there will be a lengthy initialization process. Once this process is complete, Stable Diffusion will be available at http://localhost.

The text transformation model is ready, and now you can create the cover for the article. I propose this idea for the cover: an image of a truck with a container with the words “Stable Diffusion” written on it. The truck sits at the port, ready to be loaded onto a container ship named “docker AMD.”

To simplify the drawing process we need an extension ControlNet. To install it, you need to go to the “Extensions” – “Available” tab. Then click the “Load from” button. After this, a list of available extensions will open, in which you need to select “sd-webui-controlnet” and click the “Install” button. Next, you need to go to the “Installed” tab and click the “Apply and quit” button. After this, the container will stop, and to start it again, you need to run the command make run.

For drawing I will use a model Level4 XL. Her and other models can be found on the website civitai.com.

Based on the idea, the industrial design will be like this: “container ship, container truck, oil painting, heavy brush strokes dominate the canvas, calm colors, pier.” Negative promt – “watercolour”. Select Sampling method DPM++ SDE, Sampling steps – 15, CFG Scale – 2. Now you can create an image by clicking on the “Generate” button.

Generation result

Generation result

Since the painting doesn't have inscriptions or a ship in port as intended, we need to make changes. To do this, we will use contour drawing and also find a suitable image on the Internet:

A suitable image found on the Internet

A suitable image found on the Internet

To draw around the office, download the file diffusers_xl_canny_full.safetensors, which should be placed in the ./data/stable-diffusion/models/ControlNet directory. Before copying the file, you must provide access to the data directory, since the container was run as root. To do this you need to run the command sudo chmod -R 777./data.

On the “ControlNet” tab we will upload the image that we found on the Internet. Set the Pixel Perfect flag. Control Type select Canny, Preprocessor – canny, Model – diffusers_xl_canny_full [2b69fca4], Control Weight – 0.7, Ending Control Step – 0.5. Let's increase the canvas size in proportion to the loaded image: Width – 828, Height – 476. As a result of generation, we will get two images: a drawing and a preprocessor representation for the canny mode. The preprocessor view can be edited in any graphic editor by removing unnecessary lines and adding necessary ones. The preprocessor representation can then be immediately loaded into the image for ControlNet.

Generation result
Generated image

Generated image

Preprocessor view

Preprocessor view

In the graphic editor, we change the lines presented in the preprocessor and add labels in a separate layer. We then save the result as two images: one without the first layer and one without the second.

Working in a graphic editor
Edited preprocessor view

Edited preprocessor view

Inscriptions

Inscriptions

Instead of the original image, we will upload the edited outline. Let's go to the second tab “ControlNet Unit 1” and add an image of the inscriptions. Control Type select Canny, Preprocessor – canny, Model – diffusers_xl_canny_full [2b69fca4]Control Weight – 1, Ending Control Step – 1. Please note that the weight and stopping step are set to 1 to ensure that the labels are clear and do not disappear.

Click generate image and get the cover for the article.

Comment

To replace faces, I recommend using ReActor. After installation, the error is corrected by downloading the file inswapper_128.onnx By recommendations to the .data/stable-diffusion/models/insightface directory.

It also replaces faces well IP-Adapter FaceID, Instant ID and already described here Canny.

Similar Posts

Leave a Reply

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