Created
April 19, 2024 12:36
-
-
Save hinablue/2f8e5c42d23ca3eae34e40612579784a to your computer and use it in GitHub Desktop.
Forge Docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
forge: | |
image: forge:hina | |
environment: | |
- PYTORCH_CUDA_ALLOC_CONF=garbage_collection_threshold:0.95,max_split_size_mb:512 | |
- CLI_ARGS=--xformers --enable-insecure-extension-access | |
tty: true | |
ipc: host | |
ports: | |
- "7860:7860" | |
volumes: | |
- ./webui-user.sh:/app/sd-webui/webui-user.sh | |
- .cache:/data/.cache | |
- ./config/forge:/data/config | |
- ./models:/data/models | |
- ./embeddings:/data/embeddings | |
- ./output:/output | |
stop_signal: SIGINT | |
deploy: | |
resources: | |
reservations: | |
devices: | |
- driver: nvidia | |
device_ids: ['0'] | |
capabilities: [gpu] | |
restart_policy: | |
condition: unless-stopped | |
delay: 5s | |
window: 120s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM nvidia/cuda:12.3.2-runtime-ubuntu22.04 | |
WORKDIR /app | |
RUN apt update && apt upgrade -y | |
RUN apt install -y wget git python3 python3-dev python3-pip python3-venv libgl1 libglib2.0-0 apt-transport-https libgoogle-perftools-dev libgoogle-perftools4 libtcmalloc-minimal4 bc jq | |
COPY entrypoint.sh /app/entrypoint.sh | |
RUN chmod +x /app/entrypoint.sh | |
RUN useradd -m webui | |
RUN chown -R webui:webui /app \ | |
&& mkdir /data \ | |
&& chown -R webui:webui /data \ | |
&& mkdir -p /app/sd-webui \ | |
&& chown -R webui:webui /app/sd-webui | |
COPY config.py /data/config.py | |
USER webui | |
ARG SHA=main | |
RUN git clone https://github.com/lllyasviel/stable-diffusion-webui-forge.git /app/sd-webui \ | |
&& chmod +x /app/sd-webui/webui.sh \ | |
&& cd /app/sd-webui \ | |
&& git reset --hard ${SHA} \ | |
&& chmod +x webui.sh \ | |
&& chmod +x webui-user.sh \ | |
&& git config --global --add safe.directory '*' | |
WORKDIR /app/sd-webui | |
RUN cd /app/sd-webui \ | |
&& python3 -m venv --system-site-packages venv \ | |
&& . venv/bin/activate \ | |
&& echo 'clone_dir="../../app/sd-webui"' >> webui-user.sh \ | |
&& pip3 install -r requirements.txt | |
# RUN sed -i 's/in_app_dir = .*/in_app_dir = True/g' /usr/local/lib/python3.10/site-packages/gradio/routes.py | |
# Install xformers | |
RUN cd /app/sd-webui \ | |
&& . venv/bin/activate \ | |
&& pip3 install -U xformers | |
ENV ROOT=/app/sd-webui | |
ENV PATH="/home/webui/.local/bin:/usr/sbin:/usr/sbin/ldconfig:$PATH" | |
ENV NVIDIA_VISIBLE_DEVICES=all | |
ENV CLI_ARGS="" | |
EXPOSE 7860 | |
ENTRYPOINT ["/app/entrypoint.sh"] | |
CMD /app/sd-webui/webui.sh --listen --port 7860 ${CLI_ARGS}% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat entrypoint.sh | |
#!/bin/bash | |
set -Eeuo pipefail | |
find "${ROOT}/scripts/" -maxdepth 1 -type l -delete | |
cp -vrfTs /data/config/scripts/ "${ROOT}/scripts/" | |
if [ ! -f /data/config/ui-config.json ]; then | |
echo '{}' >/data/config/ui-config.json | |
fi | |
if [ ! -f /data/config/styles.csv ]; then | |
touch /data/config/styles.csv | |
fi | |
declare -A MOUNTS | |
MOUNTS["/home/webui/.cache"]="/data/.cache" | |
# main | |
MOUNTS["${ROOT}/models"]="/data/models" | |
MOUNTS["${ROOT}/embeddings"]="/data/embeddings" | |
MOUNTS["${ROOT}/extensions"]="/data/config/extensions" | |
MOUNTS["${ROOT}/config.json"]="/data/config/config.json" | |
MOUNTS["${ROOT}/ui-config.json"]="/data/config/ui-config.json" | |
MOUNTS["${ROOT}/styles.csv"]="/data/config/styles.csv" | |
MOUNTS["${ROOT}/config_states"]="/data/config/config_states" | |
MOUNTS["${ROOT}/interrogate"]="/data/config/interrogate" | |
# extra hacks | |
MOUNTS["${ROOT}/repositories/CodeFormer/weights/facelib"]="/data/.cache" | |
for to_path in "${!MOUNTS[@]}"; do | |
set -Eeuo pipefail | |
from_path="${MOUNTS[${to_path}]}" | |
rm -rf "${to_path}" | |
if [ ! -f "$from_path" ]; then | |
mkdir -vp "$from_path" | |
fi | |
mkdir -vp "$(dirname "${to_path}")" | |
ln -sT "${from_path}" "${to_path}" | |
echo Mounted $(basename "${from_path}") | |
done | |
echo "Installing extension dependencies (if any)" | |
if [ -f "/data/config/startup.sh" ]; then | |
pushd ${ROOT} | |
echo "Running startup script" | |
. /data/config/startup.sh | |
popd | |
fi | |
shopt -s nullglob | |
# For install.py, please refer to https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Developing-extensions#installpy | |
list=(./extensions/*/install.py) | |
for installscript in "${list[@]}"; do | |
EXTNAME=$(echo $installscript | cut -d '/' -f 3) | |
# Skip installing dependencies if extension is disabled in config | |
if $(jq -e ".disabled_extensions|any(. == \"$EXTNAME\")" config.json); then | |
echo "Skipping disabled extension ($EXTNAME)" | |
continue | |
fi | |
PYTHONPATH=${ROOT} python3 "$installscript" | |
done | |
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd /app/sd-webui && source venv/bin/activate && pip3 install -U insightface fastapi && pip3 install albumentations==1.4.3 pydantic==1.10.15 spandrel==0.2.2 | |
# Issue: https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/11458 | |
sed -i 's/pytorch_lightning.utilities.distributed/pytorch_lightning.utilities.rank_zero/g' /app/sd-webui/repositories/stable-diffusion-stability-ai/ldm/models/diffusion/ddpm.py | |
sed -i 's/pytorch_lightning.utilities.distributed/pytorch_lightning.utilities.rank_zero/g' /app/sd-webui/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment