Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.devcontainer
/docker-compose.override.yml
.DS_Store

# VSCode specific
*.code-workspace
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Run Stable Diffusion on your machine with a nice UI without any hassle!

## TODO ##

- [ ] Fix compose build context for non-m1
- [ ] Link results to mounted output volume
- [ ] Clean up Dockerfile
- [ ] Convert `*.py` and `*.sh` file changes to `sed` commands, so whole files dont need to be stored
- ...or at least make them a sub-dir `./services/AUTOMATIC1111/m1_modified_files/.`

## Setup & Usage

Visit the wiki for [Setup](https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/Setup) and [Usage](https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/Usage) instructions, checkout the [FAQ](https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/FAQ) page if you face any problems, or create a new issue!
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,11 @@ services:
deploy: {}
environment:
- CLI_ARGS=--cpu


auto-m1:
<<: *automatic
profiles: ["auto-m1"]
deploy: {}
environment:
- CLI_ARGS=--skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate
161 changes: 132 additions & 29 deletions services/AUTOMATIC1111/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM alpine/git:2.36.2 as download

COPY clone.sh /clone.sh


# RUN . /clone.sh stable-diffusion-stability-ai https://github.com/Stability-AI/stablediffusion.git cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf
RUN . /clone.sh stable-diffusion-stability-ai https://github.com/Stability-AI/stablediffusion.git cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf \
&& rm -rf assets data/**/*.png data/**/*.jpg data/**/*.gif

Expand All @@ -13,57 +13,160 @@ RUN . /clone.sh BLIP https://github.com/salesforce/BLIP.git 48211a1594f1321b00f1
RUN . /clone.sh k-diffusion https://github.com/crowsonkb/k-diffusion.git ab527a9a6d347f364e3d185ba6d714e22d80cb3c
RUN . /clone.sh clip-interrogator https://github.com/pharmapsychotic/clip-interrogator 2cf03aaf6e704197fd0dae7c7f96aa59cf1b11c9
RUN . /clone.sh generative-models https://github.com/Stability-AI/generative-models 45c443b316737a4ab6e40413d7794a7f5657c19f
RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets.git 6f7db241d2f8ba7457bac5ca9753331f0c266917

# Image for Mac M1 arch
FROM ubuntu:22.04

FROM pytorch/pytorch:2.1.2-cuda12.1-cudnn8-runtime
# Set env vars
ARG GRADIO_SERVER_PORT=7860

ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1
# These settings prevent a timezone prompt when Python installs
ENV TZ=US/Pacific \
DEBIAN_FRONTEND=noninteractive \
GRADIO_SERVER_PORT=${GRADIO_SERVER_PORT} \
PIP_PREFER_BINARY=1

RUN --mount=type=cache,target=/var/cache/apt \
apt-get update && \
# we need those
apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \
# extensions needs those
ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential

apt-get update && \
# we need those
apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \
# extensions needs those
ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential \
# Install AUTOMATIC1111 pre-requisites
cmake rustc git-all wget apt-utils pip \
# Install Python pre-requisites, including Python 3.x; Google perftools includes TCMalloc, which helps with CPU memory usage
software-properties-common python3 python3-pip python3-ipykernel libopencv-dev python3-opencv python3.10-venv google-perftools sudo

# Install AUTOMATIC1111 pre-requisites
# RUN apt-get install -y jq
RUN apt -y autoremove && apt autoclean

# Configure git
RUN git config --global user.name "Some One" &&\
git config --global user.email [email protected] &&\
git config --global init.defaultBranch main

RUN sudo apt purge -y gcc libomp-dev
# RUN export USE_OPENMP=1
# ENV USE_OPENMP=1
RUN sudo apt-get install gcc libomp-dev -y

# # Check versions
# RUN echo |cpp -fopenmp -dM |grep -i open
# RUN gcc --version

RUN echo "deb http://public.dhe.ibm.com/software/server/POWER/Linux/xl-compiler/eval/ppc64le/ubuntu/ trusty main" | sudo tee /etc/apt/sources.list.d/ibm-xl-compiler-eval.list
# RUN sudo apt-get update

RUN "/usr/bin/python3" -m pip install torch==2.1.2 torchvision==0.16.2 --extra-index-url https://download.pytorch.org/whl/cu121

WORKDIR /
RUN --mount=type=cache,target=/root/.cache/pip \
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && \
cd stable-diffusion-webui && \
git reset --hard cf2772fab0af5573da775e7437e6acdca424f26e && \
pip install -r requirements_versions.txt

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && \
cd stable-diffusion-webui && \
git reset --hard bef51aed032c0aaa5cfd80445bc4cf0d85b408b5 && \
pip install -r requirements_versions.txt

ENV ROOT=/stable-diffusion-webui

COPY --from=download /repositories/ ${ROOT}/repositories/
# COPY --from=download /models/ ${ROOT}/models/
RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r ${ROOT}/repositories/CodeFormer/requirements.txt

RUN --mount=type=cache,target=/root/.cache/pip \
pip install pyngrok xformers==0.0.23.post1 \
pip install pyngrok \
git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \
git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \
git+https://github.com/mlfoundations/[email protected]

# there seems to be a memory leak (or maybe just memory not being freed fast enough) that is fixed by this version of malloc
# maybe move this up to the dependencies list.
RUN apt-get -y install libgoogle-perftools-dev && apt-get clean
ENV LD_PRELOAD=libtcmalloc.so
# TODO: Use `sed` instead of copying files
# Modify code from AUTOMATIC1111 repo as needed for Mac M1
COPY paths_internal.py /stable-diffusion-webui/modules/paths_internal.py
COPY sd_models.py /stable-diffusion-webui/modules/sd_models.py
COPY webui-macos-env.sh /stable-diffusion-webui/webui-macos-env.sh
COPY webui-user.sh /stable-diffusion-webui/webui-user.sh

# ENTRYPOINT [ "/bin/bash" ]

# IS THIS NEEDED?
COPY webui.sh /stable-diffusion-webui/webui.sh

RUN chmod 777 -R /stable-diffusion-webui/

EXPOSE 7860

RUN export OPENBLAS_NUM_THREADS=1
WORKDIR /stable-diffusion-webui
RUN git config --global --add safe.directory "*"

# RUN useradd -s /bin/bash -d /home/sdwui/ -m -G sudo sdwui
# USER sdwui
# RUN git config --global --add safe.directory "*"

####################################################################################################
# TODO: Clean this mess
##################################################
# RUN site_pkg_loc=`python -m site | grep 'site-packages' | head -1 | awk -F"'" '{print $2}' -`; mv frpc_linux_aarch64_v0.2 `echo $site_pkg_loc`/gradio/frpc_linux_aarch64_v0.2; chmod +x `echo $site_pkg_loc`/gradio/frpc_linux_aarch64_v0.2
RUN "/usr/bin/python3" -m pip install gradio==3.41.2 && \
curl -LS https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_linux_aarch64 -o frpc_linux_aarch64_v0.2 && \
chmod +x frpc_linux_aarch64_v0.2
##################################################
RUN if [ -d /usr/local/lib/python3.10/dist-packages/gradio/ ]; then scp frpc_linux_aarch64_v0.2 /usr/local/lib/python3.10/dist-packages/gradio/.; fi
RUN if [ -d /usr/lib/python3/dist-packages/gradio ]; then scp frpc_linux_aarch64_v0.2 /usr/lib/python3.10/dist-packages/gradio/.; fi
RUN if [ -d /usr/lib/python3.10/dist-packages/gradio ]; then scp frpc_linux_aarch64_v0.2 /usr/lib/python3.10/dist-packages/gradio/.; fi
RUN if [ -d /home/sdwui/.local/lib/python3.10/site-packages/gradio ]; then scp frpc_linux_aarch64_v0.2 /home/sdwui/.local/lib/python3.10/site-packages/gradio/.; fi
##################################################
RUN if [ -d /home/sdwui/.local/lib/python3.10/site-packages/gradio ]; then \
GRADIO_DIR_PATH=/home/sdwui/.local/lib/python3.10/site-packages/gradio \
else \
GRADIO_DIR_PATH=/usr/lib/python3/dist-packages/gradio; fi && \
mv frpc_linux_aarch64_v0.2 ${GRADIO_DIR_PATH}/frpc_linux_aarch64_v0.2 && \
chmod +x ${GRADIO_DIR_PATH}/frpc_linux_aarch64_v0.2
####################################################################################################

RUN export USE_OPENMP=1
RUN export OPENBLAS_NUM_THREADS=1
ENV USE_OPENMP=1 \
OPENBLAS_NUM_THREADS=1


####################################################################################################
### This is done above, in `download`
##################################################
# RUN mkdir -p ${ROOT}/repositories
# COPY clone.sh ${ROOT}/.
# WORKDIR ${ROOT}
# RUN chmod +x ${ROOT}/clone.sh


# RUN ./clone.sh CodeFormer https://github.com/sczhou/CodeFormer.git c5b4593074ba6214284d6acd5f1719b6c5d739af \
# && rm -rf assets inputs
# RUN ./clone.sh stable-diffusion-stability-ai https://github.com/Stability-AI/stablediffusion.git cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf
# RUN ./clone.sh BLIP https://github.com/salesforce/BLIP.git 48211a1594f1321b00f14c9f7a5b4813144b2fb9
# RUN ./clone.sh k-diffusion https://github.com/crowsonkb/k-diffusion.git ab527a9a6d347f364e3d185ba6d714e22d80cb3c
# RUN ./clone.sh clip-interrogator https://github.com/pharmapsychotic/clip-interrogator 2cf03aaf6e704197fd0dae7c7f96aa59cf1b11c9
# RUN ./clone.sh generative-models https://github.com/Stability-AI/generative-models 45c443b316737a4ab6e40413d7794a7f5657c19f

# RUN ./clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets.git 6f7db241d2f8ba7457bac5ca9753331f0c266917
# # Copy them over, cuz stable-diffusion-webui-assets isnt getting added proplerly
# RUN scp -r /repositories/* ${ROOT}/repositories/.
####################################################################################################

# TODO: test if this is needed
RUN "/usr/bin/python3" -m pip install clip
# VERSION: clip @ git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1


COPY . /docker

RUN \
# mv ${ROOT}/style.css ${ROOT}/user.css && \
# one of the ugliest hacks I ever wrote \
sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \
git config --global --add safe.directory '*'
# TMP DO THIS SO DOWNLOAD TIMES ARE FASTER WHILE TESTING; for local dev
# COPY sd-v1-4.ckpt ${ROOT}/models/Stable-diffusion/sd-v1-4.ckpt

WORKDIR ${ROOT}
ENV NVIDIA_VISIBLE_DEVICES=all
ENV CLI_ARGS=""
EXPOSE 7860
ENTRYPOINT ["/docker/entrypoint.sh"]
CMD python -u webui.py --listen --port 7860 ${CLI_ARGS}
# ENTRYPOINT [ "/bin/bash" ]
RUN ln -s /data/models/Stable-diffusion ${ROOT}/models/Stable-diffusion
# TODO: link outputs to mounted output volume
CMD /usr/bin/python3 -u webui.py --listen --port 7860
Loading