/stable-diffusion-docker

Stable Diffusion Docker Project with WebUI

Primary LanguageShell

Docker for Stable Diffusion

Setup for Windows

  • For Windows using WSL2, write a .wslconfig File in your user path with following content:
[wsl2]
memory=12GB # Limits VM memory in WSL 2 to X GB
processors=3 # Makes the WSL 2 VM use X virtual processors
localhostForwarding=true
  • You can play with the values if your PC can't handle it.

  • Install Docker Desktop for Windows

  • Make sure you are running the newest NVIDIA Drivers and newest Docker Desktop Version.

Installation

With Docker

  • Build image yourself with:

    docker build -t stable-diffusion-guitard .

  • Run prebuild image with:

    docker run -d --gpus all -p 7860:8080 -v ./.cache/app:/root/.cache -v ./.cache/facexlib/:/app/src/facexlib/facexlib/weights/ -v ./.cache/gfpgan/:/app/gfpgan/weights/ -v ./models/:/models/ -v ./outputs/:/outputs/ -e RUN_MODE=false sharrnah/stable-diffusion-guitard

    (replace "sharrnah/stable-diffusion-guitard" image name with "stable-diffusion-guitard" to run self-build image)

    change "RUN_MODE" depending on your machine. (see Options for more info)

With Docker Compose (recommended)

  • Download / Clone this repo.

    (Or just get the docker-compose.yaml file if you want to use the prebuild image and ignore "build image yourself" step.)

  • Start docker-compose project.

    • building image yourself:

    docker compose -f docker-compose.build.yaml up -d --build

    • start prebuild image with:

    docker compose up -d

  • See current logs with:

    docker compose logs stablediffusion -f

  • You can exec into the container with:

    docker compose exec stablediffusion bash

Options

  • You can set the environment variable "RUN_MODE" to one of these setting:
    • "OPTIMIZED" For reduced Memory mode (sacrificing speed)
    • "OPTIMIZED-TURBO" For lesser reduced Memory mode (sacrificing less speed)
    • "GTX16" When generated images are green (known problem on GTX 16xx GPUs)
    • "GTX16-TURBO" When generated images are green (known problem on GTX 16xx GPUs) [using OPTIMIZED-TURBO]
    • "FULL-PRECISION" use full precision
  • Set the environment variable "WEBUI_RELAUNCH" to
    • "true" (default) For automatic restarting of the WebUI
    • "false" Disables automatic restarting of the WebUI
  • Set the environment variable "ENABLE_TEXTUAL_INVERSION" to
    • "true" To clone and install Textual Inversion (Breaks Latent Diffusion SR!!!)
    • "false" (default) does not clone Textual Inversion on startup

For that you can create a .env file and set the content to

RUN_MODE=OPTIMIZED

or

RUN_MODE=GTX16

(See example.env file including all possible values)

Usage

  • after the webgui started successfully you should see a log output telling

    Running on local URL:  http://127.0.0.1:7860/
    
  • See current log with:

    docker compose logs stablediffusion -f

  • Open http://127.0.0.1:7860/ in your Browser to use it.

  • All generated images are saved into the ./outputs/ directory.

  • Find some nice example prompts here:

Model Sources

Models should be downloaded automatically on first run now!

Model Function Version Size Local Location (Case-Sensitive!) Download Source
Stable Diffusion Image Generation v1.4 ~4 GB models/SDv1.4.ckpt Web:
https://drive.yerf.org/wl/?id=EBfTrmcCCUAGaQBXVIj5lJmEhjoP1tgl
https://www.googleapis.com/storage/v1/b/aai-blog-files/o/sd-v1-4.ckpt?alt=media
Torrent Magnet:
magnet:?xt=urn:btih:3a4a612d75ed088ea542acac52f9f45987488d1c&dn=sd-v1-4.ckpt&tr=udp%3a%2f%2ftracker.openbittorrent.com%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337
Hugging Face:
https://huggingface.co/CompVis/stable-diffusion-v1-4
GFPGAN Face Correction v1.3.0 332 MB models/GFPGANv1.3.pth Web:
https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth
RealESRGAN Upscaling v0.1.0 ~64 MB models/RealESRGAN_x4plus.pth Web:
https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth
RealESRGAN anime Upscaling Anime v0.2.2.4 ~17 MB models/RealESRGAN_x4plus_anime_6B.pth Web:
https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth
Latent Diffusion Upscaling, Inpainting July 2022 ~2 GB models/LDSR.ckpt Web:
https://heibox.uni-heidelberg.de/f/578df07c8fc04ffbadf3/?dl=1

Sources: