Source: examples/stable_diffusion
Stable Diffusion Web UI on SkyPilot#
Run the InvokeAI Stable Diffusion web UI on a cloud GPU with SkyPilot, using the official ghcr.io/invoke-ai/invokeai:v6.14.2-cuda image (pinned; newer tags are listed in the InvokeAI releases).
Steps#
Install SkyPilot by following the instructions.
Run
git clone https://github.com/skypilot-org/skypilot.git && cd skypilot/examples/stable_diffusionRun
sky launch -c stable-diffusion stable_diffusion_docker.yamlRun
ssh -L 9090:localhost:9090 stable-diffusionOpen
http://localhost:9090in your browser.On first launch, open Model Manager in the UI and install a starter model (for example, a Stable Diffusion 1.5 or SDXL checkpoint). Models and generated images are stored under
~/invokeaion the cluster, so they survive container restarts.Type in a prompt and click Invoke to generate images.
Once you are done, run
sky stop stable-diffusionto stop the VM, orsky down stable-diffusionto delete it.
If a model you want to install is gated on Hugging Face, pass a token with sky launch --env HUGGING_FACE_HUB_TOKEN=<token> ....
Tips#
Prompts like
A photo of an astronaut riding a horse, cinematic lighting, highly detailedwork well; use the negative prompt field to exclude things you don’t want.The Canvas tab supports inpainting and outpainting; Workflows exposes the node editor for more advanced pipelines.
Running locally#
docker-compose.yml starts the same container on a local machine with an NVIDIA GPU: docker compose up.
Included files#
docker-compose.yml
version: '3.8'
services:
invokeai:
image: ghcr.io/invoke-ai/invokeai:v6.14.2-cuda
container_name: invokeai
restart: on-failure
ports:
- "9090:9090"
volumes:
- ~/invokeai:/invokeai
environment:
- HUGGING_FACE_HUB_TOKEN=${HUGGING_FACE_HUB_TOKEN:-}
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
stable_diffusion_docker.yaml
# Runs the InvokeAI Stable Diffusion web UI (https://github.com/invoke-ai/InvokeAI)
# on a single GPU using the official ghcr.io/invoke-ai/invokeai:v6.14.2-cuda image.
#
# Usage:
# sky launch -c stable-diffusion examples/stable_diffusion/stable_diffusion_docker.yaml
# ssh -L 9090:localhost:9090 stable-diffusion
# # then open http://localhost:9090
envs:
HUGGING_FACE_HUB_TOKEN: "" # optional, for gated Hugging Face models
resources:
accelerators: L4:1
ports: 9090
setup: |
set -e
docker pull ghcr.io/invoke-ai/invokeai:v6.14.2-cuda
run: |
set -e
# Models and generated images are kept under ~/invokeai on the host.
mkdir -p ~/invokeai
docker rm -f invokeai 2>/dev/null || true
docker run -d --name invokeai --restart on-failure \
--gpus all \
-p 9090:9090 \
-v ~/invokeai:/invokeai \
-e HUGGING_FACE_HUB_TOKEN=${HUGGING_FACE_HUB_TOKEN:-} \
ghcr.io/invoke-ai/invokeai:v6.14.2-cuda
docker logs -f invokeai