Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rhasselbaum/1e71aeb6428b7a0c44cc37cb6bac2322 to your computer and use it in GitHub Desktop.
Save rhasselbaum/1e71aeb6428b7a0c44cc37cb6bac2322 to your computer and use it in GitHub Desktop.
Stable Diffusion WebUI on AMD Radeon RX 5700 XT

Docker must be installed and working.

In shell:

docker pull rocm/pytorch:rocm5.2_ubuntu20.04_py3.7_pytorch_1.11.0_navi21
docker run -it --name stable-diffusion-webui --network=host --device=/dev/kfd --device=/dev/dri \
  --group-add=video --ipc=host --cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
  -v $HOME/dev/stable-diffusion-docker:/dockerx rocm/pytorch:rocm5.2_ubuntu20.04_py3.7_pytorch_1.11.0_navi21

Alternatively, replace --network=host with a different network if you don't want the container sharing the host's interface.

In the container:

# Upgrade Python
apt install python3.9-full # Confirm every prompt
update-alternatives --install /usr/local/bin/python python /usr/bin/python3.9 1
echo 'PATH=/usr/local/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

# Install Stable Diffusion
cd /dockerx
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
cd stable-diffusion-webui
python -m pip install --upgrade pip wheel

# First run
HSA_OVERRIDE_GFX_VERSION=10.3.0 REQS_FILE='requirements.txt' python launch.py \
  --precision full --no-half --skip-torch-cuda-test

Add --listen to make it available to other machines on the same network.

Test: http://127.0.0.1:7860

If it works, make it easier to run next time. Create container file /dockerx/start-ui with:

#!/bin/bash
cd /dockerx/stable-diffusion-webui
HSA_OVERRIDE_GFX_VERSION=10.3.0 REQS_FILE='requirements.txt' python launch.py \
  --precision full --no-half --skip-torch-cuda-test

Make it executable.

chmod +x /dockerx/start-ui

Later, after exiting container, from shell:

docker container restart stable-diffusion-webui
docker exec -it stable-diffusion-webui bash
/dockerx/start-ui

Refs:

  1. https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-AMD-GPUs#running-inside-docker
  2. AUTOMATIC1111/stable-diffusion-webui#6420 (comment)
  3. AUTOMATIC1111/stable-diffusion-webui#10360
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment