Skip to content

Instantly share code, notes, and snippets.

@In-line
Last active November 1, 2024 18:28
Show Gist options
  • Save In-line/c1225f05d5164a4be9b39de68e99ee2b to your computer and use it in GitHub Desktop.
Save In-line/c1225f05d5164a4be9b39de68e99ee2b to your computer and use it in GitHub Desktop.
AMD 7900 XTX Stable Diffusion Web UI docker container (ROCM 5.5_rc4)

To use this container you would first need to install docker and docker-compose.

After that you would need deleted rocm/composable_kernel:ck_ub20.04_rocm5.5_rc4 docker image (alpha build of ROCM). You can download the image, using bittorect magnet link in the files of the gist. After downloading the image load it with docker load --input rocm5.5.tar.gz

Running is as simple as: sudo docker-compose up --build. After that Stable Diffusion Web UI could be accessed in http://127.0.0.1:3000

Many thanks to @wsippel for putting up step by step guide to get it working.

Disclaimer

This is tested on kernel 6.2.10 and mesa 23.0.0

version: "3.9"
services:
sd:
build: .
ports:
- "3000:7860"
volumes:
- ./models:/SD/stable-diffusion-webui/models/
- ./repositories:/SD/stable-diffusion-webui/repositories/
- ./extensions:/SD/stable-diffusion-webui/extensions/
- ./outputs:/SD/stable-diffusion-webui/outputs/
devices:
- '/dev/kfd:/dev/kfd'
- '/dev/dri:/dev/dri'
security_opt:
- seccomp:unconfined
group_add:
- video
FROM rocm/composable_kernel:ck_ub20.04_rocm5.5_rc4
RUN mkdir /SD
# Clone SD
WORKDIR /SD
RUN git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
WORKDIR /SD/stable-diffusion-webui
RUN git reset --hard 22bcc7be428c94e9408f589966c2040187245d81
RUN apt update && apt install python3.8-venv
RUN python3 -m venv venv
# Activate VENV
ENV VIRTUAL_ENV=/SD/stable-diffusion-webui/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN python3 -m pip install --upgrade pip wheel
ENV HIP_VISIBLE_DEVICES=0
ENV PYTORCH_ROCM_ARCH="gfx1100"
ENV CMAKE_PREFIX_PATH=/SD/stable-diffusion-webui/venv/
ENV USE_CUDA=0
# Setup patched folder & compile dependencies
RUN mkdir -p /SD/stable-diffusion-webui/patched
RUN pip install cmake ninja
WORKDIR patched
# Remove old torch and torchvision
RUN pip uninstall -y torch torchvision
# Build pytorch
RUN wget https://github.com/pytorch/pytorch/releases/download/v2.0.0/pytorch-v2.0.0.tar.gz
RUN tar -xzvf pytorch-v2.0.0.tar.gz
WORKDIR /SD/stable-diffusion-webui/patched/pytorch-v2.0.0
RUN pip install -r requirements.txt
RUN pip install mkl mkl-include
RUN python3 tools/amd_build/build_amd.py
RUN python3 setup.py install
# Build vision
WORKDIR /SD/stable-diffusion-webui/patched/
RUN wget https://github.com/pytorch/vision/archive/refs/tags/v0.15.1.tar.gz
RUN tar -xzvf v0.15.1.tar.gz
WORKDIR /SD/stable-diffusion-webui/patched/vision-0.15.1
RUN python3 setup.py install
WORKDIR /SD/stable-diffusion-webui
# Patch requirements.txt to remove torch
RUN sed '/torch/d' requirements.txt
RUN pip install -r requirements.txt
EXPOSE 7860/tcp
# Fix for "detected dubious ownership in repository" by rom1win.
RUN git config --global --add safe.directory '*'
CMD python3 launch.py --listen --disable-safe-unpickle
@Sega999
Copy link

Sega999 commented Jul 27, 2023

I cant get it to build I keep getting a python error

`(vvv) system-name:~/dockstab$ sudo docker-compose up --build
Building sd
Sending build context to Docker daemon 18.7GB
Step 1/38 : FROM rocm/composable_kernel:ck_ub20.04_rocm5.5_rc4
---> 3593424bfc2d
Step 2/38 : RUN mkdir /SD
---> Using cache
---> 8ed3bb34be5b
Step 3/38 : WORKDIR /SD
---> Using cache
---> 0e8b06d6e215
Step 4/38 : RUN git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
---> Using cache
---> 0157c649186d
Step 5/38 : WORKDIR /SD/stable-diffusion-webui
---> Using cache
---> af2b8fdbdcf9
Step 6/38 : RUN git reset --hard 22bcc7be428c94e9408f589966c2040187245d81
---> Using cache
---> 417df67433a2
Step 7/38 : RUN apt update && apt install python3.8-venv
---> Running in d0dc73637440

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Err:2 http://compute-artifactory.amd.com/artifactory/list/rocm-release-archive-20.04-deb 5.5 InRelease
Something wicked happened resolving 'compute-artifactory.amd.com:http' (-5 - No address associated with hostname)
Err:3 http://artifactory-cdn.amd.com/artifactory/list/amdgpu-deb-remote focal/builds InRelease
Something wicked happened resolving 'artifactory-cdn.amd.com:http' (-5 - No address associated with hostname)
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:1 http://mirrors.edge.kernel.org/ubuntu focal InRelease [265 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [2597 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:8 http://mirrors.edge.kernel.org/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:9 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:11 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:12 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:13 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [2909 kB]
Get:14 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [1083 kB]
Get:15 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [29.3 kB]
Get:16 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]
Get:17 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [32.0 kB]
Get:18 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [2738 kB]
Get:19 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [3390 kB]
Get:20 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1383 kB]
Get:21 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [28.6 kB]
Get:22 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [55.2 kB]
Get:23 http://mirrors.edge.kernel.org/ubuntu focal/main amd64 Packages [1275 kB]
Fetched 40.6 MB in 48s (837 kB/s)
Reading package lists...
Building dependency tree...
Reading state information...
W: Failed to fetch http://artifactory-cdn.amd.com/artifactory/list/amdgpu-deb-remote/dists/focal/builds/InRelease Something wicked happened resolving 'artifactory-cdn.amd.com:http' (-5 - No address associated with hostname)
W: Failed to fetch http://compute-artifactory.amd.com/artifactory/list/rocm-release-archive-20.04-deb/dists/5.5/InRelease Something wicked happened resolving 'compute-artifactory.amd.com:http' (-5 - No address associated with hostname)
W: Some index files failed to download. They have been ignored, or old ones used instead.
87 packages can be upgraded. Run 'apt list --upgradable' to see them.

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
libpython3.8 libpython3.8-dev libpython3.8-minimal libpython3.8-stdlib
python3.8 python3.8-dev python3.8-minimal
Suggested packages:
python3.8-doc
The following NEW packages will be installed:
python3.8-venv
The following packages will be upgraded:
libpython3.8 libpython3.8-dev libpython3.8-minimal libpython3.8-stdlib
python3.8 python3.8-dev python3.8-minimal
7 upgraded, 1 newly installed, 0 to remove and 80 not upgraded.
Need to get 10.8 MB of archives.
After this operation, 26.6 kB of additional disk space will be used.
Do you want to continue? [Y/n] Abort.
The command '/bin/sh -c apt update && apt install python3.8-venv' returned a non-zero code: 1
ERROR: Service 'sd' failed to build : Build failed
`

@evshiron
Copy link

evshiron commented Jul 27, 2023

Change RUN apt update && apt install python3.8-venv to RUN apt update && apt install -y python3.8-venv.

Btw, the tutorial is outdated as of now. If you aren't a big fan of Docker containers, an easy guide can be found here:

Which is a compilation of comments above.

@Sega999
Copy link

Sega999 commented Jul 27, 2023

thank you

@f1am3d
Copy link

f1am3d commented Aug 28, 2023

@evshiron thanks! This is working. 👍

@f1am3d
Copy link

f1am3d commented Aug 28, 2023

Failed on step #21.

@f1am3d
Copy link

f1am3d commented Aug 28, 2023

I cant get it to build I keep getting a python error

The command '/bin/sh -c apt update && apt install python3.8-venv' returned a non-zero code: 1 ERROR: Service 'sd' failed to build : Build failed

Shame here. Hey author, did you test it at all? @In-line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment