Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse filesOptimizing loading
- Dockerfile +58 -43
Dockerfile
CHANGED
@@ -1,56 +1,71 @@
|
|
1 |
-
#
|
|
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
ENV DEBIAN_FRONTEND noninteractive
|
8 |
-
|
9 |
-
RUN apt-get update -y && apt-get upgrade -y && apt-get install -y libgl1 libglib2.0-0 wget git git-lfs python3-pip python-is-python3 && rm -rf /var/lib/apt/lists/*
|
10 |
-
|
11 |
-
RUN adduser --disabled-password --gecos '' user
|
12 |
-
RUN mkdir /content && chown -R user:user /content
|
13 |
WORKDIR /content
|
14 |
USER user
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
RUN
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
RUN sed -i '$a fastapi==0.90.0' /content/stable-diffusion-webui/requirements_versions.txt
|
27 |
-
RUN sed -i -e '''/prepare_environment()/a\ os.system\(f\"""sed -i -e ''\"s/dict()))/dict())).cuda()/g\"'' /content/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/util.py""")''' /content/stable-diffusion-webui/launch.py
|
28 |
-
RUN sed -i -e 's/ start()/ #start()/g' /content/stable-diffusion-webui/launch.py
|
29 |
-
RUN cd stable-diffusion-webui && python launch.py --skip-torch-cuda-test
|
30 |
|
31 |
-
|
32 |
-
RUN
|
33 |
-
|
34 |
-
|
|
|
35 |
|
36 |
-
|
37 |
-
RUN
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
ADD --chown=user https://github.com/camenduru/webui-docker/raw/main/
|
|
|
|
|
|
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
|
|
|
|
53 |
|
54 |
EXPOSE 7860
|
55 |
-
|
56 |
-
CMD cd /content/stable-diffusion-webui && python webui.py --xformers --listen --disable-console-progressbars --enable-console-prompts --no-progressbar-hiding --ui-config-file /content/shared-ui-config.json --ui-settings-file /content/shared-config.json
|
|
|
1 |
+
# Use a smaller base image if possible, but maintain CUDA compatibility
|
2 |
+
FROM nvidia/cuda:11.7.1-base-ubuntu22.04 AS base
|
3 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
4 |
|
5 |
+
# Create user and directories early to leverage caching
|
6 |
+
RUN adduser --disabled-password --gecos '' user && \
|
7 |
+
mkdir -p /content/stable-diffusion-webui/models/Stable-diffusion && \
|
8 |
+
chown -R user:user /content
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
WORKDIR /content
|
10 |
USER user
|
11 |
|
12 |
+
# Pre-download model in a separate stage for better caching
|
13 |
+
FROM base AS model-downloader
|
14 |
+
ADD https://huggingface.co/darkstorm2150/OpenGen/resolve/main/OpenGen%20v1.0.safetensors /tmp/model.safetensors
|
15 |
+
USER root
|
16 |
+
RUN mv /tmp/model.safetensors /content/stable-diffusion-webui/models/Stable-diffusion/
|
17 |
+
USER user
|
18 |
|
19 |
+
# Main build stage with optimized layers
|
20 |
+
FROM base AS final
|
21 |
+
COPY --from=model-downloader /content/stable-diffusion-webui/models/Stable-diffusion/OpenGen%20v1.0.safetensors /content/stable-diffusion-webui/models/Stable-diffusion/
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
# Install system dependencies efficiently
|
24 |
+
RUN apt-get update && \
|
25 |
+
apt-get install -y --no-install-recommends \
|
26 |
+
libgl1 libglib2.0-0 wget git git-lfs python3-pip python-is-python3 && \
|
27 |
+
rm -rf /var/lib/apt/lists/*
|
28 |
|
29 |
+
# Combine pip installations into a single layer
|
30 |
+
RUN pip3 install --upgrade pip==23.3.1 && \
|
31 |
+
pip install --no-cache-dir \
|
32 |
+
torchmetrics==0.11.4 \
|
33 |
+
numexpr \
|
34 |
+
httpx==0.24.1 \
|
35 |
+
pytorch_lightning==1.7.6 \
|
36 |
+
https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.16/xformers-0.0.16+814314d.d20230118-cp310-cp310-linux_x86_64.whl \
|
37 |
+
--pre triton
|
38 |
|
39 |
+
# Clone repository and apply patches in a single step
|
40 |
+
RUN git clone -b v1.6 https://github.com/camenduru/stable-diffusion-webui && \
|
41 |
+
cd stable-diffusion-webui && \
|
42 |
+
sed -i 's/dict()))/dict())).cuda()/g' repositories/stable-diffusion-stability-ai/ldm/util.py && \
|
43 |
+
sed -i '/prepare_environment()/a os.system("sed -i -e '\''s/dict()))/dict())).cuda()/g'\'' repositories/stable-diffusion-stability-ai/ldm/util.py")' launch.py && \
|
44 |
+
sed -i 's/start()/#start()/g' launch.py && \
|
45 |
+
echo "fastapi==0.90.0" >> requirements_versions.txt && \
|
46 |
+
python launch.py --skip-torch-cuda-test
|
47 |
|
48 |
+
# Apply configuration patches
|
49 |
+
ADD --chown=user https://github.com/camenduru/webui-docker/raw/main/env_patch.py /content/
|
50 |
+
ADD --chown=user https://raw.githubusercontent.com/darkstorm2150/webui/main/header_patch.py /content/
|
51 |
+
RUN sed -i '/import image_from_url_text/r /content/env_patch.py' stable-diffusion-webui/modules/ui.py && \
|
52 |
+
sed -i '/demo:/r /content/header_patch.py' stable-diffusion-webui/modules/ui.py
|
53 |
|
54 |
+
# Cleanup and optimizations
|
55 |
+
RUN rm -rf stable-diffusion-webui/scripts && \
|
56 |
+
sed -i -e '/(modelmerger_interface, "Checkpoint Merger", "modelmerger"),/d' \
|
57 |
+
-e '/(train_interface, "Train", "ti"),/d' \
|
58 |
+
-e '/extensions_interface, "Extensions", "extensions"/d' \
|
59 |
+
-e '/settings_interface, "Settings", "settings"/d' \
|
60 |
+
-e 's/document.getElementsByTagName.*shadowRoot/!!& ? & : document/g' stable-diffusion-webui/script.js && \
|
61 |
+
sed -i 's/show_progress=False/show_progress=True/g' stable-diffusion-webui/modules/ui.py && \
|
62 |
+
sed -i 's/default_enabled=False/default_enabled=True/g' stable-diffusion-webui/webui.py && \
|
63 |
+
sed -i 's/ outputs=\[/queue=False, &/g' stable-diffusion-webui/modules/ui.py && \
|
64 |
+
sed -i 's/queue=False, //g' stable-diffusion-webui/modules/ui.py
|
65 |
|
66 |
+
# Add configuration files
|
67 |
+
ADD --chown=user https://github.com/camenduru/webui-docker/raw/main/shared-config.json /content/
|
68 |
+
ADD --chown=user https://github.com/camenduru/webui-docker/raw/main/shared-ui-config.json /content/
|
69 |
|
70 |
EXPOSE 7860
|
71 |
+
CMD ["python", "webui.py", "--xformers", "--listen", "--disable-console-progressbars", "--enable-console-prompts", "--no-progressbar-hiding", "--ui-config-file", "/content/shared-ui-config.json", "--ui-settings-file", "/content/shared-config.json"]
|
|