Skip to content

Instantly share code, notes, and snippets.

@akehir
Created May 12, 2023 14:11
Show Gist options
  • Save akehir/8a122526e6687e246882bc00701e42de to your computer and use it in GitHub Desktop.
Save akehir/8a122526e6687e246882bc00701e42de to your computer and use it in GitHub Desktop.
## UBUNTU
FROM ubuntu:jammy
## Prerequisites
RUN apt update
RUN apt upgrade -y
RUN apt install -y git curl wget python3-pip python3-venv python3-dev libstdc++-12-dev libpng-dev libjpeg-dev
RUN python3 -m pip install --upgrade pip wheel
## Add amdgpu
RUN wget https://repo.radeon.com/amdgpu-install/5.5/ubuntu/jammy/amdgpu-install_5.5.50500-1_all.deb
RUN DEBIAN_FRONTEND=noninteractive apt install -y ./amdgpu-install_5.5.50500-1_all.deb
RUN DEBIAN_FRONTEND=noninteractive amdgpu-install -y --usecase=rocm --no-dkms --no-32
## Container
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
## Activate VENV
ENV VIRTUAL_ENV=/SD/stable-diffusion-webui/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
## Compile pytorch
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.1/pytorch-v2.0.1.tar.gz
RUN tar -xzvf pytorch-v2.0.1.tar.gz
WORKDIR /SD/stable-diffusion-webui/patched/pytorch-v2.0.1
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
ENV FORCE_CUDA=1
WORKDIR /SD/stable-diffusion-webui/patched/
RUN wget https://github.com/pytorch/vision/archive/refs/tags/v0.15.2.tar.gz
RUN tar -xzvf v0.15.2.tar.gz
WORKDIR /SD/stable-diffusion-webui/patched/vision-0.15.2
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 --no-half-vae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment