From ab651fe0d73c2487ac06218da420edb33c78e395 Mon Sep 17 00:00:00 2001 From: AbdBarho Date: Sun, 11 Sep 2022 20:18:50 +0200 Subject: [PATCH] Major refactor (#49) * update folders * Update CI * Update CI * Unify base docker images * Remove dead config * Update permissions * Remove CPU Hack * Update hlky * Add Download Service * Adapt services * executable * remove buggy parameter * rename to SHA * Update README --- .github/workflows/docker.yml | 24 ++--- AUTOMATIC1111/docker-compose.yml | 21 ----- README.md | 89 +++++++------------ cache/.gitignore | 3 +- docker-compose.yml | 56 +++++++++--- lstein/docker-compose.yml | 20 ----- models/.gitignore | 7 -- scripts/chmod.sh | 5 ++ .../AUTOMATIC1111}/Dockerfile | 5 +- .../AUTOMATIC1111}/README.md | 0 .../AUTOMATIC1111}/config.json | 2 +- .../AUTOMATIC1111}/info.py | 0 .../AUTOMATIC1111}/mount.sh | 6 +- services/download/Dockerfile | 6 ++ services/download/checksums.sha256 | 6 ++ services/download/download.sh | 33 +++++++ {hlky => services/hlky}/Dockerfile | 24 ++--- {hlky => services/hlky}/info.py | 0 {hlky => services/hlky}/mount.sh | 17 ++-- {lstein => services/lstein}/Dockerfile | 4 +- {lstein => services/lstein}/README.md | 0 21 files changed, 164 insertions(+), 164 deletions(-) delete mode 100644 AUTOMATIC1111/docker-compose.yml delete mode 100644 lstein/docker-compose.yml delete mode 100644 models/.gitignore create mode 100755 scripts/chmod.sh rename {AUTOMATIC1111 => services/AUTOMATIC1111}/Dockerfile (96%) rename {AUTOMATIC1111 => services/AUTOMATIC1111}/README.md (100%) rename {AUTOMATIC1111 => services/AUTOMATIC1111}/config.json (90%) rename {AUTOMATIC1111 => services/AUTOMATIC1111}/info.py (100%) rename {AUTOMATIC1111 => services/AUTOMATIC1111}/mount.sh (86%) create mode 100644 services/download/Dockerfile create mode 100644 services/download/checksums.sha256 create mode 100755 services/download/download.sh rename {hlky => services/hlky}/Dockerfile (70%) rename {hlky => services/hlky}/info.py (100%) rename {hlky => services/hlky}/mount.sh (51%) rename {lstein => services/lstein}/Dockerfile (86%) rename {lstein => services/lstein}/README.md (100%) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 2820459..d976322 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,24 +1,14 @@ -name: Build Image +name: Build Images on: [push] -# TODO: how to cache intermediate images? jobs: - build_hlky: + build_all: runs-on: ubuntu-latest - name: hlky + name: All steps: - uses: actions/checkout@v3 - - run: docker compose build --progress plain - build_AUTOMATIC1111: - runs-on: ubuntu-latest - name: AUTOMATIC1111 - steps: - - uses: actions/checkout@v3 - - run: cd AUTOMATIC1111 && docker compose build --progress plain - build_lstein: - runs-on: ubuntu-latest - name: lstein - steps: - - uses: actions/checkout@v3 - - run: cd lstein && docker compose build --progress plain + # better caching? + - run: docker compose --profile auto build --progress plain + - run: docker compose --profile hlky build --progress plain + - run: docker compose --profile lstein build --progress plain diff --git a/AUTOMATIC1111/docker-compose.yml b/AUTOMATIC1111/docker-compose.yml deleted file mode 100644 index 223ca19..0000000 --- a/AUTOMATIC1111/docker-compose.yml +++ /dev/null @@ -1,21 +0,0 @@ -version: '3.9' - -services: - model: - build: . - ports: - - "7860:7860" - volumes: - - ../cache:/cache - - ../output:/output - - ../models:/models - - ./config.json:/docker/config.json - environment: - - CLI_ARGS=--medvram --opt-split-attention - deploy: - resources: - reservations: - devices: - - driver: nvidia - device_ids: ['0'] - capabilities: [gpu] diff --git a/README.md b/README.md index 6468a01..e6a167d 100644 --- a/README.md +++ b/README.md @@ -2,84 +2,58 @@ Run Stable Diffusion on your machine with a nice UI without any hassle! -This repository provides the [WebUI](https://github.com/hlky/stable-diffusion-webui) as a docker image for easy setup and deployment. - -Now with experimental support for 2 other forks: - -- [AUTOMATIC1111](./AUTOMATIC1111/) (Stable, very few bugs!) -- [lstein](./lstein/) - -NOTE: big update coming up! +This repository provides multiple UIs for you to play around with stable diffusion: ## Features -- Interactive UI with many features, and more on the way! -- Support for 6GB GPU cards. -- GFPGAN for face reconstruction, RealESRGAN for super-sampling. -- Experimental: - - Latent Diffusion Super Resolution - - GoBig - - GoLatent -- many more! +### AUTOMATIC1111 -## Setup +[AUTOMATIC1111's fork](https://github.com/AUTOMATIC1111/stable-diffusion-webui) is imho the most feature rich yet elegant UI: -Make sure you have an **up to date** version of docker installed. Download this repo and run: +- Text to image, with many samplers and even negative prompts! +- Image to image, with masking, cropping, in-painting, out-painting, variations. +- GFPGAN, RealESRGAN, LDSR, CodeFormer. +- Loopback, prompt weighting, prompt matrix, X/Y plot +- Live preview of the generated images. +- Highly optimized 4GB GPU support, or even CPU only! +- [Full feature list here](https://github.com/AUTOMATIC1111/stable-diffusion-webui-feature-showcase) -``` -docker compose build -``` +| Text to image | Image to image | Extras | +| ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | +| ![](https://user-images.githubusercontent.com/24505302/189541954-46afd772-d0c8-4005-874c-e2eca40c02f2.jpg) | ![](https://user-images.githubusercontent.com/24505302/189541956-5b528de7-1b5d-479f-a1db-d3f5a53afc59.jpg) | ![](https://user-images.githubusercontent.com/24505302/189541957-cf78b352-a071-486d-8889-f26952779a61.jpg) | -you can let it build in the background while you download the different models +### hlky -- [Stable Diffusion v1.4 (4GB)](https://www.googleapis.com/storage/v1/b/aai-blog-files/o/sd-v1-4.ckpt?alt=media), rename to `model.ckpt` -- (Optional) [GFPGANv1.3.pth (333MB)](https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth). -- (Optional) [RealESRGAN_x4plus.pth (64MB)](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth) and [RealESRGAN_x4plus_anime_6B.pth (18MB)](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth). -- (Optional) [LDSR (2GB)](https://heibox.uni-heidelberg.de/f/578df07c8fc04ffbadf3/?dl=1) and [its configuration](https://heibox.uni-heidelberg.de/f/31a76b13ea27482981b4/?dl=1), rename to `LDSR.ckpt` and `LDSR.yaml` respectively. - +[hlky's fork](https://github.com/hlky/stable-diffusion-webui) is one of the most popular UIs, with many features: -Put all of the downloaded files in the `models` folder, it should look something like this: +- Text to image, with many samplers +- Image to image, with masking, cropping, in-painting, variations. +- GFPGAN, RealESRGAN, LDSR, GoBig, GoLatent +- Loopback, prompt weighting +- 6GB or even 4GB GPU support! +- [Full feature list here](https://github.com/sd-webui/stable-diffusion-webui/blob/master/README.md) -``` -models/ -├── model.ckpt -├── GFPGANv1.3.pth -├── RealESRGAN_x4plus.pth -├── RealESRGAN_x4plus_anime_6B.pth -├── LDSR.ckpt -└── LDSR.yaml -``` +Screenshots: -## Run +| Text to image | Image to image | Image Lab | +| ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | +| ![](https://user-images.githubusercontent.com/24505302/189541298-f902b021-a1eb-4e4b-b2eb-b6a696a8ec80.jpg) | ![](https://user-images.githubusercontent.com/24505302/189541295-7d7f2162-2189-4e0a-abbd-703f4779e1cd.jpg) | ![](https://user-images.githubusercontent.com/24505302/189541294-aa7f7735-a973-4e17-ada0-1fe3acbb1772.jpg) | -After the build is done, you can run the app with: +### lstein -``` -docker compose up --build -``` +[lstein's fork](https://github.com/lstein/stable-diffusion) is very mature when it comes to the cli, but less so for the WebUI. -Will start the app on http://localhost:7860/ +## Setup & Usage -Note: the first start will take sometime as some other models will be downloaded, these will be cached in the `cache` folder, so next runs are faster. +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! -### FAQ - -You can find fixes to common issues [in the wiki page.](https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/FAQ) - -## Config - -in the `docker-compose.yml` you can change the `CLI_ARGS` variable, which contains the arguments that will be passed to the WebUI. By default: `--extra-models-cpu --optimized-turbo` are given, which allow you to use this model on a 6GB GPU. However, some features might not be available in the mode. [You can find the full list of arguments here.](https://github.com/hlky/stable-diffusion-webui/blob/2b1ac8daf7ea82c6c56eabab7e80ec1c33106a98/scripts/webui.py) - -You can set the `WEBUI_SHA` to [any SHA from the main repo](https://github.com/hlky/stable-diffusion/commits/main), this will build the container against that commit. Use at your own risk. - -# Disclaimer +## Disclaimer The authors of this project are not responsible for any content generated using this interface. This license of this software forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please read [the license](./LICENSE). -# Thanks +## Thanks Special thanks to everyone behind these awesome projects, without them, none of this would have been possible: @@ -89,3 +63,4 @@ Special thanks to everyone behind these awesome projects, without them, none of - [CompVis/stable-diffusion](https://github.com/CompVis/stable-diffusion) - [hlky/sd-enable-textual-inversion](https://github.com/hlky/sd-enable-textual-inversion) - [devilismyfriend/latent-diffusion](https://github.com/devilismyfriend/latent-diffusion) +- [Hafiidz/latent-diffusion](https://github.com/Hafiidz/latent-diffusion) diff --git a/cache/.gitignore b/cache/.gitignore index b4259b6..0988bd2 100644 --- a/cache/.gitignore +++ b/cache/.gitignore @@ -1,3 +1,4 @@ /torch /transformers -/weights \ No newline at end of file +/weights +/models diff --git a/docker-compose.yml b/docker-compose.yml index 32b9ec3..a2020e8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,11 @@ version: '3.9' -services: - model: - build: - context: ./hlky/ - args: - # You can choose any commit sha from https://github.com/hlky/stable-diffusion/commits/main - # USE AT YOUR OWN RISK! otherwise just leave it empty. - BRANCH: - WEBUI_SHA: +x-base_service: &base_service ports: - "7860:7860" volumes: - - ./cache:/cache - - ./output:/output - - ./models:/models - environment: - - CLI_ARGS=--extra-models-cpu --optimized-turbo + - &v1 ./cache:/cache + - &v2 ./output:/output deploy: resources: reservations: @@ -24,3 +13,42 @@ services: - driver: nvidia device_ids: ['0'] capabilities: [gpu] + +name: webui-docker + +services: + download: + build: ./services/download/ + profiles: ["download"] + volumes: + - *v1 + + hlky: + <<: *base_service + profiles: ["hlky"] + build: ./services/hlky/ + environment: + - CLI_ARGS=--optimized-turbo + + automatic1111: &automatic + <<: *base_service + profiles: ["auto"] + build: ./services/AUTOMATIC1111 + volumes: + - *v1 + - *v2 + - ./services/AUTOMATIC1111/config.json:/docker/config.json + environment: + - CLI_ARGS=--medvram --opt-split-attention + + automatic1111-cpu: + <<: *automatic + profiles: ["auto-cpu"] + deploy: {} + environment: + - CLI_ARGS=--no-half --precision full + + lstein: + <<: *base_service + profiles: ["lstein"] + build: ./services/lstein/ diff --git a/lstein/docker-compose.yml b/lstein/docker-compose.yml deleted file mode 100644 index 20adc83..0000000 --- a/lstein/docker-compose.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: '3.9' - -services: - model: - build: . - ports: - - "7860:7860" - volumes: - - ../cache:/cache - - ../output:/output - - ../models:/models - environment: - - CLI_ARGS= - deploy: - resources: - reservations: - devices: - - driver: nvidia - device_ids: ['0'] - capabilities: [gpu] diff --git a/models/.gitignore b/models/.gitignore deleted file mode 100644 index 8d8e32c..0000000 --- a/models/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -/model.ckpt -/GFPGANv1.3.pth -/RealESRGAN_x2plus.pth -/RealESRGAN_x4plus.pth -/RealESRGAN_x4plus_anime_6B.pth -/LDSR.ckpt -/LDSR.yaml diff --git a/scripts/chmod.sh b/scripts/chmod.sh new file mode 100755 index 0000000..d4af583 --- /dev/null +++ b/scripts/chmod.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -Eeuo pipefail + +find . -name "*.sh" -exec git update-index --chmod=+x {} \; diff --git a/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile similarity index 96% rename from AUTOMATIC1111/Dockerfile rename to services/AUTOMATIC1111/Dockerfile index 0b4c04a..5341ff5 100644 --- a/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -40,10 +40,10 @@ RUN pip install --prefer-binary --no-cache-dir -r ${ROOT}/repositories/CodeForme # Note: don't update the sha of previous versions because the install will take forever # instead, update the repo state in a later step -ARG SHA=06fadd2dc5c2753558a9f3971568c2673819f48c +ARG SHA=b5d1af11b7dc718d4d91d379c75e46f4bd2e2fe6 RUN </latent-diffusion/experiments/pretrained_models/project.yaml +if test -f "${MODELS_DIR}/LDSR.yaml"; then + sed 's/ldm\./ldm_latent\./g' "${MODELS_DIR}/LDSR.yaml" >/latent-diffusion/experiments/pretrained_models/project.yaml fi # force facexlib cache diff --git a/lstein/Dockerfile b/services/lstein/Dockerfile similarity index 86% rename from lstein/Dockerfile rename to services/lstein/Dockerfile index dd5d7a8..8733407 100644 --- a/lstein/Dockerfile +++ b/services/lstein/Dockerfile @@ -4,6 +4,8 @@ FROM continuumio/miniconda3:4.12.0 SHELL ["/bin/bash", "-ceuxo", "pipefail"] +ENV DEBIAN_FRONTEND=noninteractive + RUN conda install python=3.8.5 && conda clean -a -y RUN conda install pytorch==1.11.0 torchvision==0.12.0 cudatoolkit=11.3 -c pytorch && conda clean -a -y @@ -25,5 +27,5 @@ WORKDIR /stable-diffusion EXPOSE 7860 # run, -u to not buffer stdout / stderr CMD mkdir -p /stable-diffusion/models/ldm/stable-diffusion-v1/ && \ - ln -sf /models/model.ckpt /stable-diffusion/models/ldm/stable-diffusion-v1/model.ckpt && \ + ln -sf /cache/models/model.ckpt /stable-diffusion/models/ldm/stable-diffusion-v1/model.ckpt && \ python3 -u scripts/dream.py --outdir /output --web --host 0.0.0.0 --port 7860 ${CLI_ARGS} diff --git a/lstein/README.md b/services/lstein/README.md similarity index 100% rename from lstein/README.md rename to services/lstein/README.md