How to Run Stable Diffusion in Docker

Oct 31, 2023 | Data Science

Ever wanted to generate stunning images using artificial intelligence? With Stable Diffusion, you can create breathtaking artworks right from your Docker container! This guide will walk you through the process step-by-step while also providing troubleshooting tips along the way.

Before You Start

To ensure a smooth experience, it’s crucial to meet the minimum requirements:

  • CUDA capable GPU with 8GB+ of VRAM for optimal performance.
  • In case you have a less powerful GPU, adjustments might be necessary.
  • If you do not have a suitable GPU, you can run it on the CPU using the options --device cpu and --onnx.

Huggingface Token

Since the pipeline uses the official model, you will need to create a user access token in your Hugging Face account. Save this token in a file named token.txt to be available when building the container, as its content will start with hf_….

Quickstart

The pipeline is managed using a single build.sh script. Follow this quickstart guide:

  • Pull the latest version of Stable Diffusion using:
  • sh .build.sh pull
  • You will need to specify a valid user access token when building the image.
  • To build the container, simply run:
  • sh .build.sh build
  • To execute the model, use the scripts as explained in the following sections.

Run Stable Diffusion

Let’s dive into how to run the model effectively.

Text-to-Image (txt2img)

For creating an image from a text prompt, use:

sh .build.sh run "Andromeda galaxy in a bottle"

Image-to-Image (img2img)

To generate an image from an existing one and a text prompt:

  • First, copy an image to the input folder.
  • Then run:
  • sh .build.sh run --image image.png "Andromeda galaxy in a bottle"

Depth-Guided Diffusion (depth2img)

Modify an existing image with its depth map:

  • Copy the image and depth map to the input folder and run:
  • sh .build.sh run --model stabilityai/stable-diffusion-2-depth --image image.png "A detailed description of the objects to change"

Options for Customization

You can customize outputs with various options. Here are a few notable ones:

  • --prompt [PROMPT]: Text prompt for image rendering.
  • --model [MODEL]: Specify which model to use.
  • --height [HEIGHT] and --width [WIDTH]: Set image dimensions (must be divisible by 64).
  • --iterations [ITERS]: Number of times to run the pipeline.

Examples

Combining options can lead to unique outputs. For instance, both commands below are identical:

sh .build.sh run "abstract art"
.build.sh run --prompt "abstract art"

Like a painter with their palette, you can select your colors (options) to mix a masterpiece!

Troubleshooting

While running Stable Diffusion might seem seamless, you might encounter some hiccups. Here are some troubleshooting ideas:

  • Not enough GPU resources? Try increasing CPU, memory, and swap in Docker settings.
  • Image too large? Use --height and --width to create smaller images.
  • For users with limited VRAM, remember to use --half and --attention-slicing to reduce memory use.
  • If running into any issues, consider skipping the safety checker with --skip.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox