Skip to content

Instantly share code, notes, and snippets.

@samstride
Last active August 24, 2023 08:14
Show Gist options
  • Save samstride/335caa028775b8868acb851a052c310a to your computer and use it in GitHub Desktop.
Save samstride/335caa028775b8868acb851a052c310a to your computer and use it in GitHub Desktop.
Dockerfile to run Stable Diffusion on AMD64 CPUs.

How to run

mkdir -p ~/stable-diffusion
cd ~/stable-diffusion

# Create a file called Dockerfile and copy the contents of the Dockerfile below.

# Build
docker build -f Dockerfile -t stable-diffusion .

# Run
docker run --dns 0.0.0.0 -t -p 7860:7860 stable-diffusion

Access http://localhost:7860

ARG USERNAME=ownage
ARG USER_UID=1000
ARG USER_GID=$USER_UID
FROM ubuntu:22.04
ARG USERNAME
ARG USER_UID
ARG USER_GID
# Create the user
RUN groupadd --gid ${USER_GID} ${USERNAME} \
&& useradd --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME}
ARG DEBIAN_FRONTEND=noninteractive
# Upgrade
RUN apt-get update && \
apt-get install -y \
wget \
git \
python3 \
python3-venv \
python3-pip
USER ${USERNAME}
WORKDIR /home/${USERNAME}
# Clone official repo
RUN git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && cd stable-diffusion-webui
WORKDIR /home/${USERNAME}/stable-diffusion-webui
# Download necessary model.
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/sd_models.py
RUN wget -q -P models/Stable-diffusion/ https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors
# Install CPU oriented version of torch and torchvision.
# https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/launch_utils.py
RUN python3 -m pip install torch==2.0.1+cpu torchvision==0.15.2+cpu --extra-index-url https://download.pytorch.org/whl/cpu
# Test fire?
RUN COMMANDLINE_ARGS="--skip-torch-cuda-test --exit" python3 launch.py
# Install non-gui version of Open CV.
RUN pip3 install opencv-python-headless
EXPOSE 7860
CMD [ "bash", "-c", "python3 launch.py --listen --port 7860 --no-half --precision full --use-cpu SD GFPGAN BSRGAN ESRGAN SCUNet CodeFormer --skip-torch-cuda-test" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment