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
@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