Skip to content

Commit 10c16e1

Browse files
authored
Refactor invoke (#405)
Fixes a problem with cross attention class missing from diffusers models are now taken from the huggingFace cache. invoke-ai/InvokeAI@50eb02f
1 parent 555c26b commit 10c16e1

File tree

4 files changed

+30
-57
lines changed

4 files changed

+30
-57
lines changed

docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ services:
4343
<<: *base_service
4444
profiles: ["invoke"]
4545
build: ./services/invoke/
46-
image: sd-invoke:26
46+
image: sd-invoke:27
4747
environment:
4848
- PRELOAD=true
49-
- CLI_ARGS=
49+
- CLI_ARGS=--no-nsfw_checker --no-safety_checker --xformers
5050

5151

5252
sygil: &sygil

services/invoke/Dockerfile

+19-24
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,48 @@ ENV DEBIAN_FRONTEND=noninteractive PIP_EXISTS_ACTION=w PIP_PREFER_BINARY=1
1111

1212
RUN --mount=type=cache,target=/root/.cache/pip pip install torch==1.13.1+cu117 torchvision --extra-index-url https://download.pytorch.org/whl/cu117
1313

14-
RUN apt-get update && apt-get install git -y && apt-get clean
15-
16-
RUN git clone https://github.com/invoke-ai/InvokeAI.git /stable-diffusion
17-
18-
WORKDIR /stable-diffusion
19-
20-
RUN --mount=type=cache,target=/root/.cache/pip \
21-
git reset --hard f232068ab89bd80e4f5f3133dcdb62ea78f1d0f7 && \
22-
git config --global http.postBuffer 1048576000 && \
23-
egrep -v '^-e .' environments-and-requirements/requirements-lin-cuda.txt > req.txt && \
24-
pip install -r req.txt && \
25-
rm req.txt
26-
2714

2815
# patch match:
2916
# https://github.com/invoke-ai/InvokeAI/blob/main/docs/installation/INSTALL_PATCHMATCH.md
30-
RUN \
17+
RUN --mount=type=cache,target=/var/cache/apt \
3118
apt-get update && \
32-
# apt-get install build-essential python3-opencv libopencv-dev -y && \
33-
apt-get install make g++ libopencv-dev -y && \
19+
apt-get install make g++ git libopencv-dev -y && \
3420
apt-get clean && \
3521
cd /usr/lib/x86_64-linux-gnu/pkgconfig/ && \
3622
ln -sf opencv4.pc opencv.pc
3723

3824

39-
ARG BRANCH=main SHA=6e0c6d9cc9f6bdbdefc4b9e94bc1ccde1b04aa42
25+
26+
ENV ROOT=/InvokeAI
27+
RUN git clone https://github.com/invoke-ai/InvokeAI.git ${ROOT}
28+
WORKDIR ${ROOT}
29+
30+
RUN --mount=type=cache,target=/root/.cache/pip \
31+
git reset --hard 4463124bddd221c333d4c70e73aa2949ad35453d && \
32+
pip install .
33+
34+
35+
ARG BRANCH=main SHA=50eb02f68be912276a9c106d5e8038a5671a0386
4036
RUN --mount=type=cache,target=/root/.cache/pip \
4137
git fetch && \
4238
git reset --hard && \
4339
git checkout ${BRANCH} && \
4440
git reset --hard ${SHA} && \
45-
pip install .
46-
41+
pip install -U .
4742

4843
RUN --mount=type=cache,target=/root/.cache/pip \
49-
--mount=type=bind,from=xformers,source=/wheel.whl,target=/xformers-0.0.15-cp310-cp310-linux_x86_64.whl \
50-
pip install -U opencv-python-headless huggingface_hub triton /xformers-0.0.15-cp310-cp310-linux_x86_64.whl && \
44+
--mount=type=bind,from=xformers,source=/wheel.whl,target=/xformers-0.0.17-cp310-cp310-linux_x86_64.whl \
45+
pip install -U opencv-python-headless triton /xformers-0.0.17-cp310-cp310-linux_x86_64.whl && \
5146
python3 -c "from patchmatch import patch_match"
5247

5348

54-
RUN touch invokeai.init
5549
COPY . /docker/
5650

5751
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
5852
ENV NVIDIA_VISIBLE_DEVICES=all
59-
ENV PYTHONUNBUFFERED=1 ROOT=/stable-diffusion PYTHONPATH="${PYTHONPATH}:${ROOT}" PRELOAD=false CLI_ARGS="" HF_HOME=/root/.cache/huggingface
53+
ENV PYTHONUNBUFFERED=1 PRELOAD=false HF_HOME=/root/.cache/huggingface CONFIG_DIR=/data/config/invoke CLI_ARGS=""
6054
EXPOSE 7860
6155

6256
ENTRYPOINT ["/docker/entrypoint.sh"]
63-
CMD invokeai --web --host 0.0.0.0 --port 7860 --config /docker/models.yaml --root_dir ${ROOT} --outdir /output/invoke ${CLI_ARGS}
57+
CMD invokeai --web --host 0.0.0.0 --port 7860 --root_dir ${ROOT} --config ${CONFIG_DIR}/models.yaml --outdir /output/invoke ${CLI_ARGS}
58+
# TODO: make sure the config is persisted between sessions

services/invoke/entrypoint.sh

+9-8
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ set -Eeuo pipefail
44

55
declare -A MOUNTS
66

7+
mkdir -p ${CONFIG_DIR}
8+
79
# cache
810
MOUNTS["/root/.cache"]=/data/.cache/
911

12+
# this is really just a hack to avoid migrations
13+
rm -rf ${HF_HOME}/diffusers
14+
1015
# ui specific
1116
MOUNTS["${ROOT}/models/codeformer"]=/data/Codeformer/
12-
1317
MOUNTS["${ROOT}/models/gfpgan/GFPGANv1.4.pth"]=/data/GFPGAN/GFPGANv1.4.pth
14-
MOUNTS["${ROOT}/models/gfpgan/weights"]=/data/.cache/
15-
18+
MOUNTS["${ROOT}/models/gfpgan/weights"]=/data/GFPGAN/
1619
MOUNTS["${ROOT}/models/realesrgan"]=/data/RealESRGAN/
1720

18-
MOUNTS["${ROOT}/models/bert-base-uncased"]=/data/.cache/huggingface/transformers/
19-
MOUNTS["${ROOT}/models/openai/clip-vit-large-patch14"]=/data/.cache/huggingface/transformers/
20-
MOUNTS["${ROOT}/models/CompVis/stable-diffusion-safety-checker"]=/data/.cache/huggingface/transformers/
21+
MOUNTS["${ROOT}/models/ldm"]=/data/.cache/invoke/ldm/
2122

2223
MOUNTS["${ROOT}/embeddings"]=/data/embeddings/
2324

2425
# hacks
25-
MOUNTS["${ROOT}/models/clipseg"]=/data/.cache/invoke/clipseg/
2626

2727
for to_path in "${!MOUNTS[@]}"; do
2828
set -Eeuo pipefail
@@ -40,7 +40,8 @@ done
4040

4141
if "${PRELOAD}" == "true"; then
4242
set -Eeuo pipefail
43-
invokeai-configure --skip-sd-weights --root ${ROOT} --yes
43+
invokeai-configure --root ${ROOT} --yes
44+
cp ${ROOT}/configs/models.yaml ${CONFIG_DIR}/models.yaml
4445
fi
4546

4647
exec "$@"

services/invoke/models.yaml

-23
This file was deleted.

0 commit comments

Comments
 (0)