InvokeAI/docs/installation/INSTALL_DOCKER.md
Lincoln Stein 79e79b78aa mkdocs fixes, PR #1032
Squashed commit of the following:

commit 2c1e0168bb03a2cd625f2d4aca40eee0fdf7e4af
Merge: 2325c6c 31f2733
Author: Lincoln Stein <lincoln.stein@gmail.com>
Date:   Tue Oct 11 08:33:18 2022 -0400

    Merge branch 'mkdocs-fixes' of https://github.com/mauwii/stable-diffusion into mauwii-mkdocs-fixes

commit 31f2733e89
Merge: d9d6d3a a61a690
Author: Lincoln Stein <lincoln.stein@gmail.com>
Date:   Tue Oct 11 08:05:52 2022 -0400

    Merge branch 'main' into mkdocs-fixes

commit d9d6d3af3f
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 08:13:04 2022 +0200

    some more minor, overseen fixes to IMG2IMG

commit 4ab5a2aeba
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 07:49:11 2022 +0200

    add 4gotten alt-text to images

commit f778bd9c0f
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 07:18:11 2022 +0200

    update OTHER.md
    - fix codeblocks, add admonitions, embed graphic

commit a19f148a8e
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 06:51:29 2022 +0200

    update IMG2IMG.md

commit c1f1dfa714
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 06:10:25 2022 +0200

    update EMBIGGEN.md
    - fix codeblocks
    - fix toc
    - use admonitions

commit 791e6c63ef
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 05:58:53 2022 +0200

    better admonitions for CLI.md

commit e078025f00
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 05:50:32 2022 +0200

    huge update to CLI.md
    way too many updates to list them all, including:
    - render keys for keyboard-shortcuts
    - quote commands and "unhide" parameter-values (like `<int>`, `<string>`
    - fix codeblocks
    - quote commands
    - quote filenames
    - use admonitions
    - ....

commit bd98dd2307
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 04:49:57 2022 +0200

    fix INPAINTING.md
    - fix numbered List
    - replace text key combos with actual rendered keyboard keys

commit 5392000335
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 04:30:11 2022 +0200

    fix nubered list and codeblocks in INSTALL_WINDOWS

commit ffe9276f1e
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 04:12:56 2022 +0200

    fix numbered list in INSTALL_LINUX.md
    also fix blank lines, codeblocks and admonition

commit 2c6a6a567f
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 03:51:03 2022 +0200

    upgrade INSTALL_MAC.md:
    - use annotations and content-tabs

    yes, this looks ugly in repo afterwards, but plz also look at mkdocs:
    https://mauwii.github.io/stable-diffusion/installation/INSTALL_MAC/

commit 8f6c544480
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 01:43:11 2022 +0200

    comment out PR part in mkdocs-flow.yml

commit b52c14a67f
Merge: 97ebe58 a1b0b91
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 01:17:28 2022 +0200

    Merge branch 'mkdocs-fixes' of github.com:mauwii/stable-diffusion into mkdocs-fixes

commit a1b0b91bb3
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:59:44 2022 +0200

    fix conda env in codeblock

commit 5f9f9a266e
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:43:46 2022 +0200

    fix 4gotten title in TEXTUAL_INVERSION

commit 8f025b034e
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:41:52 2022 +0200

    quote repo_url and repo_name
    otherwise the version/stars/forks did not appear

commit 3a52b7deb3
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:39:54 2022 +0200

    fix TEXTUAL_INVERSION headline to fit the others

commit 389b21f966
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:35:48 2022 +0200

    fix SAMPLER_CONVERGENCE and add emoji

commit f26fc79a18
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:32:04 2022 +0200

    fix INSTALL_DOCKER.md:
    - fix title (Docker instead of "Before you begin")
    - add headline with Emoji
    - fix headlines to render toc correct

commit cbc3520489
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:24:58 2022 +0200

    add headline with emoji to INSTALL_MAC.md

commit 25f0614d66
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:21:01 2022 +0200

    add log emoji to docs/CHANGELOG.md

commit 42005688fa
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:20:47 2022 +0200

    use better fitting Icon for new Name

commit 0c65bad7f5
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:09:07 2022 +0200

    add Headline with Emoji to WEB and POSTPROCESS

commit 1c1cf2692e
Author: mauwii <Mauwii@outlook.de>
Date:   Mon Oct 10 23:56:16 2022 +0200

    update index.md:
    - remove unused template reference
    - make headline rendered bold and underlined, add (kind of) subtitle
    - update discord badge and link
    - update Quick links to look like in GH-Readme
      - also remove self reference to docs
    - add screenshot as in GH-Readme
    - add note pointing to issues tab
    - update path in command line to reflect new Repo Name

commit 0e29b0737e
Author: mauwii <Mauwii@outlook.de>
Date:   Mon Oct 10 23:23:10 2022 +0200

    chng site_name to `Stable Diffusion Toolkit Docs`

commit ad8a60d992
Author: mauwii <Mauwii@outlook.de>
Date:   Mon Oct 10 23:00:02 2022 +0200

    fix repo_url in mkdocs.yml

commit 234569d6b6
Author: mauwii <Mauwii@outlook.de>
Date:   Mon Oct 10 22:54:39 2022 +0200

    fix link to upscaling in WEB.md and TOC
    - TOC fixed by adding `#` to every headline after `## Parting remarks`
    - add missing blank lines

commit 97c84ad824
Author: mauwii <Mauwii@outlook.de>
Date:   Mon Oct 10 22:25:32 2022 +0200

    fix broken links in docs/CHANGELOG.md

commit bce62b3a32
Author: mauwii <Mauwii@outlook.de>
Date:   Mon Oct 10 22:15:37 2022 +0200

    add title to CHANGELOG.md to render TOC wo. `**`
    alternatively remove `**` around headline

commit 97ebe58b5b
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:59:44 2022 +0200

    fix conda env in codeblock

commit 87ac217e43
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:43:46 2022 +0200

    fix 4gotten title in TEXTUAL_INVERSION

commit 91439e8a52
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:41:52 2022 +0200

    quote repo_url and repo_name
    otherwise the version/stars/forks did not appear

commit 8a632a9e8f
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:39:54 2022 +0200

    fix TEXTUAL_INVERSION headline to fit the others

commit 7c8ffe2feb
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:35:48 2022 +0200

    fix SAMPLER_CONVERGENCE and add emoji

commit e2e86d2d11
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:32:04 2022 +0200

    fix INSTALL_DOCKER.md:
    - fix title (Docker instead of "Before you begin")
    - add headline with Emoji
    - fix headlines to render toc correct

commit 8b54c083fe
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:24:58 2022 +0200

    add headline with emoji to INSTALL_MAC.md

commit 8d8a032434
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:21:01 2022 +0200

    add log emoji to docs/CHANGELOG.md

commit 76519f6fa4
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:20:47 2022 +0200

    use better fitting Icon for new Name

commit aff0725533
Author: mauwii <Mauwii@outlook.de>
Date:   Tue Oct 11 00:09:07 2022 +0200

    add Headline with Emoji to WEB and POSTPROCESS

commit 0f7898cbdd
Author: mauwii <Mauwii@outlook.de>
Date:   Mon Oct 10 23:56:16 2022 +0200

    update index.md:
    - remove unused template reference
    - make headline rendered bold and underlined, add (kind of) subtitle
    - update discord badge and link
    - update Quick links to look like in GH-Readme
      - also remove self reference to docs
    - add screenshot as in GH-Readme
    - add note pointing to issues tab
    - update path in command line to reflect new Repo Name

commit f4c04eadf8
Author: mauwii <Mauwii@outlook.de>
Date:   Mon Oct 10 23:23:10 2022 +0200

    chng site_name to `Stable Diffusion Toolkit Docs`

commit 6e624827c0
Author: mauwii <Mauwii@outlook.de>
Date:   Mon Oct 10 23:00:02 2022 +0200

    fix repo_url in mkdocs.yml

commit 158848dd7e
Author: mauwii <Mauwii@outlook.de>
Date:   Mon Oct 10 22:54:39 2022 +0200

    fix link to upscaling in WEB.md and TOC
    - TOC fixed by adding `#` to every headline after `## Parting remarks`
    - add missing blank lines

commit 533736e135
Author: mauwii <Mauwii@outlook.de>
Date:   Mon Oct 10 22:29:46 2022 +0200

    fix link to truncation_comparison.jpg in OTHER.md

commit dd335142df
Author: mauwii <Mauwii@outlook.de>
Date:   Mon Oct 10 22:25:32 2022 +0200

    fix broken links in docs/CHANGELOG.md

commit 374dd54f30
Author: mauwii <Mauwii@outlook.de>
Date:   Mon Oct 10 22:15:37 2022 +0200

    add title to CHANGELOG.md to render TOC wo. `**`
    alternatively remove `**` around headline
2022-10-11 08:36:00 -04:00

9.4 KiB

title
Docker

:fontawesome-brands-docker: Docker

Before you begin

  • For end users: Install Stable Diffusion locally using the instructions for your OS.
  • For developers: For container-related development tasks or for enabling easy deployment to other environments (on-premises or cloud), follow these instructions. For general use, install locally to leverage your machine's GPU.

Why containers?

They provide a flexible, reliable way to build and deploy Stable Diffusion. You'll also use a Docker volume to store the largest model files and image outputs as a first step in decoupling storage and compute. Future enhancements can do this for other assets. See Processes under the Twelve-Factor App methodology for details on why running applications in such a stateless fashion is important.

You can specify the target platform when building the image and running the container. You'll also need to specify the Stable Diffusion requirements file that matches the container's OS and the architecture it will run on.

Developers on Apple silicon (M1/M2): You can't access your GPU cores from Docker containers and performance is reduced compared with running it directly on macOS but for development purposes it's fine. Once you're done with development tasks on your laptop you can build for the target platform and architecture and deploy to another environment with NVIDIA GPUs on-premises or in the cloud.

Installation on a Linux container

Prerequisites

Get the data files

Go to Hugging Face, and click "Access repository" to Download the model file sd-v1-4.ckpt (~4 GB) to ~/Downloads. You'll need to create an account but it's quick and free.

Also download the face restoration model.

cd ~/Downloads
wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth

Install Docker

On the Docker Desktop app, go to Preferences, Resources, Advanced. Increase the CPUs and Memory to avoid this Issue. You may need to increase Swap and Disk image size too.

Setup

Set the fork you want to use and other variables.

TAG_STABLE_DIFFUSION="santisbon/stable-diffusion"
PLATFORM="linux/arm64"
GITHUB_STABLE_DIFFUSION="-b orig-gfpgan https://github.com/santisbon/stable-diffusion.git"
REQS_STABLE_DIFFUSION="requirements-linux-arm64.txt"
CONDA_SUBDIR="osx-arm64"

echo $TAG_STABLE_DIFFUSION
echo $PLATFORM
echo $GITHUB_STABLE_DIFFUSION
echo $REQS_STABLE_DIFFUSION
echo $CONDA_SUBDIR

Create a Docker volume for the downloaded model files.

docker volume create my-vol

Copy the data files to the Docker volume using a lightweight Linux container. We'll need the models at run time. You just need to create the container with the mountpoint; no need to run this dummy container.

cd ~/Downloads # or wherever you saved the files

docker create --platform $PLATFORM --name dummy --mount source=my-vol,target=/data alpine

docker cp sd-v1-4.ckpt dummy:/data
docker cp GFPGANv1.4.pth dummy:/data

Get the repo and download the Miniconda installer (we'll need it at build time). Replace the URL with the version matching your container OS and the architecture it will run on.

cd ~
git clone $GITHUB_STABLE_DIFFUSION

cd stable-diffusion/docker-build
chmod +x entrypoint.sh
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh -O anaconda.sh && chmod +x anaconda.sh

Build the Docker image. Give it any tag -t that you want.
Choose the Linux container's host platform: x86-64/Intel is amd64. Apple silicon is arm64. If deploying the container to the cloud to leverage powerful GPU instances you'll be on amd64 hardware but if you're just trying this out locally on Apple silicon choose arm64.
The application uses libraries that need to match the host environment so use the appropriate requirements file.
Tip: Check that your shell session has the env variables set above.

docker build -t $TAG_STABLE_DIFFUSION \
--platform $PLATFORM \
--build-arg gsd=$GITHUB_STABLE_DIFFUSION \
--build-arg rsd=$REQS_STABLE_DIFFUSION \
--build-arg cs=$CONDA_SUBDIR \
.

Run a container using your built image.
Tip: Make sure you've created and populated the Docker volume (above).

docker run -it \
--rm \
--platform $PLATFORM \
--name stable-diffusion \
--hostname stable-diffusion \
--mount source=my-vol,target=/data \
$TAG_STABLE_DIFFUSION

Usage (time to have fun)

Startup

If you're on a Linux container the invoke script is automatically started and the output dir set to the Docker volume you created earlier.

If you're directly on macOS follow these startup instructions.
With the Conda environment activated (conda activate ldm), run the interactive interface that combines the functionality of the original scripts txt2img and img2img:
Use the more accurate but VRAM-intensive full precision math because half-precision requires autocast and won't work.
By default the images are saved in outputs/img-samples/.

python3 scripts/invoke.py --full_precision

You'll get the script's prompt. You can see available options or quit.

invoke> -h
invoke> q

Text to Image

For quick (but bad) image results test with 5 steps (default 50) and 1 sample image. This will let you know that everything is set up correctly.
Then increase steps to 100 or more for good (but slower) results.
The prompt can be in quotes or not.

invoke> The hulk fighting with sheldon cooper -s5 -n1
invoke> "woman closeup highly detailed"  -s 150
# Reuse previous seed and apply face restoration
invoke> "woman closeup highly detailed"  --steps 150 --seed -1 -G 0.75

You'll need to experiment to see if face restoration is making it better or worse for your specific prompt.

If you're on a container the output is set to the Docker volume. You can copy it wherever you want.
You can download it from the Docker Desktop app, Volumes, my-vol, data.
Or you can copy it from your Mac terminal. Keep in mind docker cp can't expand *.png so you'll need to specify the image file name.

On your host Mac (you can use the name of any container that mounted the volume):

docker cp dummy:/data/000001.928403745.png /Users/<your-user>/Pictures

Image to Image

You can also do text-guided image-to-image translation. For example, turning a sketch into a detailed drawing.

strength is a value between 0.0 and 1.0 that controls the amount of noise that is added to the input image. Values that approach 1.0 allow for lots of variations but will also produce images that are not semantically consistent with the input. 0.0 preserves image exactly, 1.0 replaces it completely.

Make sure your input image size dimensions are multiples of 64 e.g. 512x512. Otherwise you'll get Error: product of dimension sizes > 2**31'. If you still get the error try a different size like 512x256.

If you're on a Docker container, copy your input image into the Docker volume

docker cp /Users/<your-user>/Pictures/sketch-mountains-input.jpg dummy:/data/

Try it out generating an image (or more). The invoke script needs absolute paths to find the image so don't use ~.

If you're on your Mac

invoke> "A fantasy landscape, trending on artstation" -I /Users/<your-user>/Pictures/sketch-mountains-input.jpg --strength 0.75  --steps 100 -n4

If you're on a Linux container on your Mac

invoke> "A fantasy landscape, trending on artstation" -I /data/sketch-mountains-input.jpg --strength 0.75  --steps 50 -n1

Web Interface

You can use the invoke script with a graphical web interface. Start the web server with:

python3 scripts/invoke.py --full_precision --web

If it's running on your Mac point your Mac web browser to http://127.0.0.1:9090

Press Control-C at the command line to stop the web server.

Notes

Some text you can add at the end of the prompt to make it very pretty:

cinematic photo, highly detailed, cinematic lighting, ultra-detailed, ultrarealistic, photorealism, Octane Rendering, cyberpunk lights, Hyper Detail, 8K, HD, Unreal Engine, V-Ray, full hd, cyberpunk, abstract, 3d octane render + 4k UHD + immense detail + dramatic lighting + well lit + black, purple, blue, pink, cerulean, teal, metallic colours, + fine details, ultra photoreal, photographic, concept art, cinematic composition, rule of thirds, mysterious, eerie, photorealism, breathtaking detailed, painting art deco pattern, by hsiao, ron cheng, john james audubon, bizarre compositions, exquisite detail, extremely moody lighting, painted by greg rutkowski makoto shinkai takashi takeuchi studio ghibli, akihiko yoshida

The original scripts should work as well.

python3 scripts/orig_scripts/txt2img.py --help
python3 scripts/orig_scripts/txt2img.py --ddim_steps 100 --n_iter 1 --n_samples 1  --plms --prompt "new born baby kitten. Hyper Detail, Octane Rendering, Unreal Engine, V-Ray"
python3 scripts/orig_scripts/txt2img.py --ddim_steps 5   --n_iter 1 --n_samples 1  --plms --prompt "ocean" # or --klms