77FROM pytorch/pytorch:1.12.1-cuda11.3-cudnn8-runtime as base
88# Below: our ideal image, but Optimization fails with it.
99# FROM continuumio/miniconda3:4.12.0 as base
10+
11+ # Note, docker uses HTTP_PROXY and HTTPS_PROXY (uppercase)
12+ # We purposefully want those managed independently, as we want docker
13+ # to manage its own cache. This is just for pip, models, etc.
14+ ARG http_proxy
15+ ENV http_proxy=${http_proxy}
16+ ARG https_proxy
17+ ENV https_proxy=${https_proxy}
18+ RUN if [ -n "$http_proxy" ] ; then \
19+ echo quit \
20+ | openssl s_client -proxy $(echo ${https_proxy} | cut -b 8-) -servername google.com -connect google.com:443 -showcerts \
21+ | sed 'H;1h;$!d;x; s/^.*\( -----BEGIN CERTIFICATE-----.*-----END CERTIFICATE-----\)\n ---\n Server certificate.*$/\1 /' \
22+ > /usr/local/share/ca-certificates/squid-self-signed.crt ; \
23+ update-ca-certificates ; \
24+ fi
25+ ENV REQUESTS_CA_BUNDLE=${http_proxy:+/usr/local/share/ca-certificates/squid-self-signed.crt}
26+
1027ENV DEBIAN_FRONTEND=noninteractive
1128# RUN apt-get install gnupg2
1229# RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC
@@ -31,31 +48,35 @@ FROM base as output
3148RUN mkdir /api
3249WORKDIR /api
3350
51+ # # XXXX playing around a lot.
52+ # pip installs pytorch 1.13 and uninstalls 1.12 (needed by xformers)
53+ # recomment conda update; didn't help. need to solve above issue.
54+
55+ RUN conda update -n base -c defaults conda
3456# We need python 3.9 or 3.10 for xformers
3557# Yes, we install pytorch twice... will switch base image in future
36- # RUN conda update -n base -c defaults conda
3758RUN conda create -n xformers python=3.10
3859SHELL ["/opt/conda/bin/conda" , "run" , "--no-capture-output" , "-n" , "xformers" , "/bin/bash" , "-c" ]
3960RUN python --version
4061RUN conda install -c pytorch -c conda-forge cudatoolkit=11.6 pytorch=1.12.1
4162RUN conda install xformers -c xformers/label/dev
4263
4364# Install python packages
44- RUN mkdir -p /root/.cache/pip
45- COPY root-cache/pip /root/.cache/pip
46- RUN pip3 install --upgrade pip
65+ # RUN pip3 install --upgrade pip
66+ RUN https_proxy="" REQUESTS_CA_BUNDLE="" conda install pip
4767ADD requirements.txt requirements.txt
48- RUN pip3 install -r requirements.txt
68+ RUN pip install -r requirements.txt
4969
50- # Required to build flash attention
70+ # Not needed anymore, but, may be needed again in the future :D
5171# Turing: 7.5 (RTX 20s, Quadro), Ampere: 8.0 (A100), 8.6 (RTX 30s)
5272# https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/
53- # ENV FLASH_ATTENTION=0
5473# ENV TORCH_CUDA_ARCH_LIST="7.5 8.0 8.6"
55- # this is built it into memory efficient attention now ! ^_^
5674
57- ADD install.sh .
58- RUN bash install.sh
75+ RUN git clone https://github.com/huggingface/diffusers
76+ WORKDIR /api/diffusers
77+ RUN git checkout v0.9.0
78+ WORKDIR /api
79+ RUN pip install -e diffusers
5980
6081# We add the banana boilerplate here
6182ADD server.py .
@@ -76,20 +97,44 @@ ENV HF_AUTH_TOKEN=${HF_AUTH_TOKEN}
7697ARG MODEL_ID="runwayml/stable-diffusion-v1-5"
7798ENV MODEL_ID=${MODEL_ID}
7899
100+ # "" = model default.
101+ ARG PRECISION="fp16"
102+ ENV PRECISION=${PRECISION}
103+ ADD precision.py .
104+
79105# ARG PIPELINE="StableDiffusionInpaintPipeline"
80106ARG PIPELINE="ALL"
81107ENV PIPELINE=${PIPELINE}
82108
83- COPY root-cache/huggingface /root/.cache/huggingface
84- COPY root-cache/checkpoints /root/.cache/checkpoints
85- RUN du -sh /root/.cache/*
109+ ARG USE_DREAMBOOTH=0
110+ ENV USE_DREAMBOOTH=${USE_DREAMBOOTH}
86111
112+ ARG AWS_ACCESS_KEY_ID
113+ ARG AWS_SECRET_ACCESS_KEY
114+ ARG AWS_DEFAULT_REGION
115+ ARG AWS_S3_ENDPOINT_URL
116+ ENV AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
117+ ENV AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
118+ ENV AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
119+ ENV AWS_S3_ENDPOINT_URL=${AWS_S3_ENDPOINT_URL}
120+
121+ COPY utils utils
122+
123+ # Download diffusers model from somewhere else (see Storage docs)
124+ # Don't use this for checkpoints (.ckpt)! Use CHECKPOINT_URL for that.
125+ ARG MODEL_URL=""
126+ ENV MODEL_URL=${MODEL_URL}
87127# If set, it will be downloaded and converted to diffusers format, and
88128# saved in a directory with same MODEL_ID name to be loaded by diffusers.
89129ARG CHECKPOINT_URL=""
90130ENV CHECKPOINT_URL=${CHECKPOINT_URL}
131+ ARG CHECKPOINT_CONFIG_URL=""
132+ ENV CHECKPOINT_CONFIG_URL=${CHECKPOINT_CONFIG_URL}
133+
91134ADD download-checkpoint.py .
92135RUN python3 download-checkpoint.py
136+ ARG _CONVERT_SPECIAL
137+ ENV _CONVERT_SPECIAL=${_CONVERT_SPECIAL}
93138ADD convert-to-diffusers.py .
94139RUN python3 convert-to-diffusers.py
95140# RUN rm -rf checkpoints
@@ -106,7 +151,15 @@ ARG USE_PATCHMATCH=0
106151RUN if [ "$USE_PATCHMATCH" = "1" ] ; then apt-get install -yqq python3-opencv ; fi
107152COPY --from=patchmatch /tmp/PyPatchMatch PyPatchMatch
108153
154+ RUN if [ "$USE_DREAMBOOTH" = "1" ] ; then \
155+ # By specifying the same torch version as conda, it won't download again.
156+ # Without this, it will upgrade torch, break xformers, make bigger image.
157+ pip install -r diffusers/examples/dreambooth/requirements.txt bitsandbytes torch==1.12.1 ; \
158+ fi
159+ RUN if [ "$USE_DREAMBOOTH" = "1" ] ; then apt-get install git-lfs ; fi
160+
109161# Add your custom app code, init() and inference()
162+ ADD train_dreambooth.py .
110163ADD send.py .
111164ADD app.py .
112165
0 commit comments