Skip to content

Commit dde69d6

Browse files
authored
feat: support sd3 (#46)
BREAKING CHANGE: we have 3 different images now instead of just one: base, sdxl and sd3 * ci: use branch name for creating dev releases * ci: replace "/" with "-" to have a valid tag name * ci: correctly handle the tag name * ci: build an image that contains sd3 using docker bake * ci: use "set" instead of "args" * ci: use "env" instead of "set" * ci: use variables instead of args * ci: set variables directly for the targets * ci: write the secrets into the GITHUB_ENV * ci: handle env variables correctly * ci: use env variables from GitHub Variables * ci: added back to env * ci: print out env * ci: adding the vars directly into the workflow * ci: example workflow for sd3 * ci: renamed DOCKERHUB_REPO to DOCKERHUB_REPOSITORY * ci: removed quotes for DOCKERHUB_REPOSITORY * ci: only use DOCKERHUB_REPO in bake * ci: added vars into sd3 target * ci: added direct target * ci: back to basics * ci: multi-stage build to not expose the HUGGINGFACE_ACCESS_TOKEN * ci: write everything into GITHUB_ENV again * ci: use correct name for final stage * ci: use correct runner * fix: make sure to use the latest versions of all packages * ci: simplified variables for all targets * docs: added 3 images, updated build your own image * docs: updated TOC * ci: updated name * ci: use docker bake to publish 3 images instead of just 1
1 parent 46474ac commit dde69d6

File tree

6 files changed

+240
-45
lines changed

6 files changed

+240
-45
lines changed

.github/workflows/dev.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: Development
33
on:
44
workflow_dispatch:
55
push:
6-
branches:
7-
- "dev"
6+
branches-ignore:
7+
- main
88

99
jobs:
1010
dev:
@@ -40,9 +40,19 @@ jobs:
4040
username: ${{ secrets.DOCKERHUB_USERNAME }}
4141
password: ${{ secrets.DOCKERHUB_TOKEN }}
4242

43-
- name: Build and push
44-
uses: docker/build-push-action@v5
43+
- name: Set environment variables
44+
run: |
45+
echo "DOCKERHUB_REPO=${{ vars.DOCKERHUB_REPO }}" >> $GITHUB_ENV
46+
echo "DOCKERHUB_IMG=${{ vars.DOCKERHUB_IMG }}" >> $GITHUB_ENV
47+
echo "HUGGINGFACE_ACCESS_TOKEN=${{ secrets.HUGGINGFACE_ACCESS_TOKEN }}" >> $GITHUB_ENV
48+
echo "RELEASE_VERSION=${GITHUB_REF##refs/heads/}" | sed 's/\//-/g' >> $GITHUB_ENV
49+
50+
- name: Build and push the images to Docker Hub
51+
uses: docker/bake-action@v2
4552
with:
4653
push: true
47-
tags: |
48-
${{ secrets.DOCKERHUB_REPO }}/${{ secrets.DOCKERHUB_IMG }}:dev
54+
set: |
55+
*.args.DOCKERHUB_REPO=${{ env.DOCKERHUB_REPO }}
56+
*.args.DOCKERHUB_IMG=${{ env.DOCKERHUB_IMG }}
57+
*.args.RELEASE_VERSION=${{ env.RELEASE_VERSION }}
58+
sd3.args.HUGGINGFACE_ACCESS_TOKEN=${{ env.HUGGINGFACE_ACCESS_TOKEN }}

.github/workflows/release.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,27 @@ jobs:
6060
env:
6161
GITHUB_TOKEN: ${{ secrets.BLIBLA_SEMANTIC_RELEASE }}
6262

63-
- name: Build image and push it to Docker Hub
64-
if: steps.semanticrelease.outputs.new-release-published == 'true'
65-
uses: docker/build-push-action@v5
63+
- name: Set environment variables
64+
run: |
65+
echo "DOCKERHUB_REPO=${{ vars.DOCKERHUB_REPO }}" >> $GITHUB_ENV
66+
echo "DOCKERHUB_IMG=${{ vars.DOCKERHUB_IMG }}" >> $GITHUB_ENV
67+
echo "HUGGINGFACE_ACCESS_TOKEN=${{ secrets.HUGGINGFACE_ACCESS_TOKEN }}" >> $GITHUB_ENV
68+
echo "RELEASE_VERSION=${{ steps.semanticrelease.outputs.release-version }}" >> $GITHUB_ENV
69+
70+
- name: Build and push the images to Docker Hub
71+
uses: docker/bake-action@v2
6672
with:
6773
push: true
68-
tags: |
69-
${{ secrets.DOCKERHUB_REPO }}/${{ secrets.DOCKERHUB_IMG }}:${{ steps.semanticrelease.outputs.release-version }}
70-
${{ secrets.DOCKERHUB_REPO }}/${{ secrets.DOCKERHUB_IMG }}:latest
74+
set: |
75+
*.args.DOCKERHUB_REPO=${{ env.DOCKERHUB_REPO }}
76+
*.args.DOCKERHUB_IMG=${{ env.DOCKERHUB_IMG }}
77+
*.args.RELEASE_VERSION=${{ env.RELEASE_VERSION }}
78+
sd3.args.HUGGINGFACE_ACCESS_TOKEN=${{ env.HUGGINGFACE_ACCESS_TOKEN }}
7179
7280
- name: Update description on Docker Hub
7381
if: steps.semanticrelease.outputs.new-release-published == 'true'
7482
uses: peter-evans/dockerhub-description@v3
7583
with:
7684
username: ${{ secrets.DOCKERHUB_USERNAME }}
7785
password: ${{ secrets.DOCKERHUB_TOKEN }}
78-
repository: ${{ secrets.DOCKERHUB_REPO }}/${{ secrets.DOCKERHUB_IMG }}
86+
repository: ${{ env.DOCKERHUB_REPO }}/${{ env.DOCKERHUB_IMG }}

Dockerfile

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Use Nvidia CUDA base image
1+
# Stage 1: Base image with common dependencies
22
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04 as base
33

44
# Prevents prompts from packages asking for user input during installation
@@ -24,16 +24,9 @@ RUN git clone https://github.com/comfyanonymous/ComfyUI.git /comfyui
2424
# Change working directory to ComfyUI
2525
WORKDIR /comfyui
2626

27-
ARG SKIP_DEFAULT_MODELS
28-
# Download checkpoints/vae/LoRA to include in image.
29-
RUN if [ -z "$SKIP_DEFAULT_MODELS" ]; then wget -O models/checkpoints/sd_xl_base_1.0.safetensors https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors; fi
30-
RUN if [ -z "$SKIP_DEFAULT_MODELS" ]; then wget -O models/vae/sdxl_vae.safetensors https://huggingface.co/stabilityai/sdxl-vae/resolve/main/sdxl_vae.safetensors; fi
31-
RUN if [ -z "$SKIP_DEFAULT_MODELS" ]; then wget -O models/vae/sdxl-vae-fp16-fix.safetensors https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl_vae.safetensors; fi
32-
3327
# Install ComfyUI dependencies
34-
RUN pip3 install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 \
35-
&& pip3 install --no-cache-dir xformers==0.0.21 \
36-
&& pip3 install -r requirements.txt
28+
RUN pip3 install --upgrade --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 \
29+
&& pip3 install --upgrade -r requirements.txt
3730

3831
# Install runpod
3932
RUN pip3 install runpod requests
@@ -48,5 +41,29 @@ WORKDIR /
4841
ADD src/start.sh src/rp_handler.py test_input.json ./
4942
RUN chmod +x /start.sh
5043

44+
# Stage 2: Download models
45+
FROM base as downloader
46+
47+
ARG HUGGINGFACE_ACCESS_TOKEN
48+
ARG MODEL_TYPE
49+
50+
# Change working directory to ComfyUI
51+
WORKDIR /comfyui
52+
53+
# Download checkpoints/vae/LoRA to include in image based on model type
54+
RUN if [ "$MODEL_TYPE" = "sdxl" ]; then \
55+
wget -O models/checkpoints/sd_xl_base_1.0.safetensors https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors && \
56+
wget -O models/vae/sdxl_vae.safetensors https://huggingface.co/stabilityai/sdxl-vae/resolve/main/sdxl_vae.safetensors && \
57+
wget -O models/vae/sdxl-vae-fp16-fix.safetensors https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl_vae.safetensors; \
58+
elif [ "$MODEL_TYPE" = "sd3" ]; then \
59+
wget --header="Authorization: Bearer ${HUGGINGFACE_ACCESS_TOKEN}" -O models/checkpoints/sd3_medium_incl_clips_t5xxlfp8.safetensors https://huggingface.co/stabilityai/stable-diffusion-3-medium/resolve/main/sd3_medium_incl_clips_t5xxlfp8.safetensors; \
60+
fi
61+
62+
# Stage 3: Final image
63+
FROM base as final
64+
65+
# Copy models from stage 2 to the final image
66+
COPY --from=downloader /comfyui/models /comfyui/models
67+
5168
# Start the container
52-
CMD /start.sh
69+
CMD /start.sh

README.md

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ Read our article here: https://blib.la/blog/comfyui-on-runpod
4949

5050
## Quickstart
5151

52-
- 🐳 Use the latest release of the image for your worker: [timpietruskyblibla/runpod-worker-comfy:2.1.3](https://hub.docker.com/r/timpietruskyblibla/runpod-worker-comfy)
52+
- 🐳 Choose one of the three available images for your serverless endpoint:
53+
- `timpietruskyblibla/runpod-worker-comfy:3.0.0-base`: doesn't contain any checkpoints, just a clean ComfyUI image
54+
- `timpietruskyblibla/runpod-worker-comfy:3.0.0-sdxl`: contains the checkpoints and VAE for Stable Diffusion XL
55+
- `timpietruskyblibla/runpod-worker-comfy:3.0.0-sd3`: contains the medium checkpoint for Stable Diffusion 3
5356
- ⚙️ [Set the environment variables](#config)
5457
- ℹ️ [Use the Docker image on RunPod](#use-the-docker-image-on-runpod)
5558

@@ -60,11 +63,14 @@ Read our article here: https://blib.la/blog/comfyui-on-runpod
6063
- The generated image is either:
6164
- Returned as base64-encoded string (default)
6265
- Uploaded to AWS S3 ([if AWS S3 is configured](#upload-image-to-aws-s3))
63-
- Build-in checkpoint:
64-
- [sd_xl_base_1.0.safetensors](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0)
65-
- Build-in VAE:
66-
- [sdxl_vae.safetensors](https://huggingface.co/stabilityai/sdxl-vae/)
67-
- [sdxl-vae-fp16-fix](https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/)
66+
- There are three different Docker images to choose from:
67+
- `<version>-base`: doesn't contain any checkpoints, just a clean ComfyUI image
68+
- `<version>-sdxl`: contains the checkpoints and VAE for Stable Diffusion XL
69+
- Checkpoint: [sd_xl_base_1.0.safetensors](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0)
70+
- VAEs:
71+
- [sdxl_vae.safetensors](https://huggingface.co/stabilityai/sdxl-vae/)
72+
- [sdxl-vae-fp16-fix](https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/)
73+
- `<version>-sd3`: contains the checkpoint [sd3_medium_incl_clips_t5xxlfp8.safetensors](https://huggingface.co/stabilityai/stable-diffusion-3-medium) for Stable Diffusion 3
6874
- [Bring your own models](#bring-your-own-models)
6975
- Based on [Ubuntu + NVIDIA CUDA](https://hub.docker.com/r/nvidia/cuda)
7076

@@ -98,10 +104,10 @@ This is only needed if you want to upload the generated picture to AWS S3. If yo
98104
- In the dialog, configure:
99105
- Template Name: `runpod-worker-comfy` (it can be anything you want)
100106
- Template Type: serverless (change template type to "serverless")
101-
- Container Image: `<dockerhub_username>/<repository_name>:tag`, in this case: `timpietruskyblibla/runpod-worker-comfy:2.1.3` (or `dev` if you want to have the development release)
107+
- Container Image: `<dockerhub_username>/<repository_name>:tag`, in this case: `timpietruskyblibla/runpod-worker-comfy:3.0.0-sd3` (or `-base` for a clean image or `-sdxl` for Stable Diffusion XL)
102108
- Container Registry Credentials: You can leave everything as it is, as this repo is public
103109
- Container Disk: `20 GB`
104-
- Enviroment Variables: [Configure S3](#upload-image-to-aws-s3)
110+
- (optional) Environment Variables: [Configure S3](#upload-image-to-aws-s3)
105111
- Note: You can also not configure it, the images will then stay in the worker. In order to have them stored permanently, [we have to add the network volume](https://github.com/blib-la/runpod-worker-comfy/issues/1)
106112
- Click on `Save Template`
107113
- Navigate to [`Serverless > Endpoints`](https://www.runpod.io/console/serverless/user/endpoints) and click on `New Endpoint`
@@ -112,7 +118,7 @@ This is only needed if you want to upload the generated picture to AWS S3. If yo
112118
- Max Workers: `3` (whatever makes sense for you)
113119
- Idle Timeout: `5` (you can leave the default)
114120
- Flash Boot: `enabled` (doesn't cost more, but provides faster boot of our worker, which is good)
115-
- Advanced: If you are using a Network Volume, select it under `Select Network Volume`. Otherwise leave the defaults.
121+
- (optional) Advanced: If you are using a Network Volume, select it under `Select Network Volume`. Otherwise leave the defaults.
116122
- Select a GPU that has some availability
117123
- GPUs/Worker: `1`
118124
- Click `deploy`
@@ -283,15 +289,21 @@ If you prefer to include your models directly in the Docker image, follow these
283289
```
284290

285291
3. **Build Your Docker Image**:
286-
- Build the image locally:
292+
- Build the **base** image locally:
287293
```bash
288-
docker build -t <your_dockerhub_username>/runpod-worker-comfy:dev --platform linux/amd64 .
294+
docker build -t <your_dockerhub_username>/runpod-worker-comfy:dev-base --target base --platform linux/amd64 .
289295
```
290-
- Optionally, skip downloading the default models to reduce the image size:
296+
- Build the **sdxl** image locally:
291297
```bash
292-
docker build --build-arg SKIP_DEFAULT_MODELS=1 -t <your_dockerhub_username>/runpod-worker-comfy:dev --platform linux/amd64 .
298+
docker build --build-arg MODEL_TYPE=sdxl -t <your_dockerhub_username>/runpod-worker-comfy:dev-sdxl --platform linux/amd64 .
293299
```
294-
- Ensure to specify `--platform linux/amd64` to avoid errors on RunPod, see [issue #13](https://github.com/blib-la/runpod-worker-comfy/issues/13).
300+
- Build the **sd3** image locally:
301+
```bash
302+
docker build --build-arg MODEL_TYPE=sd3 --build-arg HUGGINGFACE_ACCESS_TOKEN=<your-huggingface-token> -t <your_dockerhub_username>/runpod-worker-comfy:dev-sd3 --platform linux/amd64 .
303+
```
304+
305+
> [!NOTE]
306+
> Ensure to specify `--platform linux/amd64` to avoid errors on RunPod, see [issue #13](https://github.com/blib-la/runpod-worker-comfy/issues/13).
295307

296308
## Local testing
297309

@@ -385,14 +397,19 @@ The repo contains two workflows that publish the image to Docker hub using GitHu
385397
- [dev.yml](.github/workflows/dev.yml): Creates the image and pushes it to Docker hub with the `dev` tag on every push to the `main` branch
386398
- [release.yml](.github/workflows/release.yml): Creates the image and pushes it to Docker hub with the `latest` and the release tag. It will only be triggered when you create a release on GitHub
387399
388-
If you want to use this, you should add these secrets to your repository:
400+
If you want to use this, you should add these **secrets** to your repository:
401+
402+
| Configuration Variable | Description | Example Value |
403+
| ---------------------- | ----------------------------------------- | --------------- |
404+
| `DOCKERHUB_USERNAME` | Your Docker Hub username. | `your-username` |
405+
| `DOCKERHUB_TOKEN` | Your Docker Hub token for authentication. | `your-token` |
406+
407+
And also make sure to add these **variables** to your repository:
389408
390-
| Configuration Variable | Description | Example Value |
391-
| ---------------------- | ------------------------------------------------------------ | --------------------- |
392-
| `DOCKERHUB_USERNAME` | Your Docker Hub username. | `your-username` |
393-
| `DOCKERHUB_TOKEN` | Your Docker Hub token for authentication. | `your-token` |
394-
| `DOCKERHUB_REPO` | The repository on Docker Hub where the image will be pushed. | `timpietruskyblibla` |
395-
| `DOCKERHUB_IMG` | The name of the image to be pushed to Docker Hub. | `runpod-worker-comfy` |
409+
| Variable Name | Description | Example Value |
410+
| ---------------- | ------------------------------------------------------------ | --------------------- |
411+
| `DOCKERHUB_REPO` | The repository on Docker Hub where the image will be pushed. | `timpietruskyblibla` |
412+
| `DOCKERHUB_IMG` | The name of the image to be pushed to Docker Hub. | `runpod-worker-comfy` |
396413
397414
## Acknowledgments
398415

docker-bake.hcl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
variable "DOCKERHUB_REPO" {
2+
default = ""
3+
}
4+
5+
variable "DOCKERHUB_IMG" {
6+
default = ""
7+
}
8+
9+
variable "RELEASE_VERSION" {
10+
default = ""
11+
}
12+
13+
variable "HUGGINGFACE_ACCESS_TOKEN" {
14+
default = ""
15+
}
16+
17+
group "default" {
18+
targets = ["base", "sdxl", "sd3"]
19+
}
20+
21+
target "base" {
22+
context = "."
23+
dockerfile = "Dockerfile"
24+
target = "base"
25+
tags = ["${DOCKERHUB_REPO}/${DOCKERHUB_IMG}:${RELEASE_VERSION}-base"]
26+
}
27+
28+
target "sdxl" {
29+
context = "."
30+
dockerfile = "Dockerfile"
31+
target = "final"
32+
args = {
33+
MODEL_TYPE = "sdxl"
34+
}
35+
tags = ["${DOCKERHUB_REPO}/${DOCKERHUB_IMG}:${RELEASE_VERSION}-sdxl"]
36+
inherits = ["base"]
37+
}
38+
39+
target "sd3" {
40+
context = "."
41+
dockerfile = "Dockerfile"
42+
target = "final"
43+
args = {
44+
MODEL_TYPE = "sd3"
45+
HUGGINGFACE_ACCESS_TOKEN = "${HUGGINGFACE_ACCESS_TOKEN}"
46+
}
47+
tags = ["${DOCKERHUB_REPO}/${DOCKERHUB_IMG}:${RELEASE_VERSION}-sd3"]
48+
inherits = ["base"]
49+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"input": {
3+
"workflow": {
4+
"6": {
5+
"inputs": {
6+
"text": "comic illustration of a white unicorn with a golden horn and pink mane and tail standing amidst a colorful and magical fantasy landscape. The background is filled with pastel-colored mountains and fluffy clouds and colorful balloons and stars. There are vibrant rainbows arching across the sky. The ground is adorned with oversized, candy-like plants, trees shaped like lollipops, and swirling ice cream cones. The scene is bathed in soft, dreamy light, giving it an enchanting and otherworldly feel. 4k, high resolution",
7+
"clip": ["252", 1]
8+
},
9+
"class_type": "CLIPTextEncode",
10+
"_meta": {
11+
"title": "CLIP Text Encode (Prompt)"
12+
}
13+
},
14+
"13": {
15+
"inputs": {
16+
"shift": 3,
17+
"model": ["252", 0]
18+
},
19+
"class_type": "ModelSamplingSD3",
20+
"_meta": {
21+
"title": "ModelSamplingSD3"
22+
}
23+
},
24+
"71": {
25+
"inputs": {
26+
"text": "worst quality, lowres, blurry, deformed, overexposure, bright, hands, oversaturated, burned, oversharpened, artifacts, hand, human, handwriting, nsfw, breast, breasts",
27+
"clip": ["252", 1]
28+
},
29+
"class_type": "CLIPTextEncode",
30+
"_meta": {
31+
"title": "CLIP Text Encode (Negative Prompt)"
32+
}
33+
},
34+
"135": {
35+
"inputs": {
36+
"width": 1152,
37+
"height": 768,
38+
"batch_size": 1
39+
},
40+
"class_type": "EmptySD3LatentImage",
41+
"_meta": {
42+
"title": "EmptySD3LatentImage"
43+
}
44+
},
45+
"231": {
46+
"inputs": {
47+
"samples": ["271", 0],
48+
"vae": ["252", 2]
49+
},
50+
"class_type": "VAEDecode",
51+
"_meta": {
52+
"title": "VAE Decode"
53+
}
54+
},
55+
"252": {
56+
"inputs": {
57+
"ckpt_name": "sd3_medium_incl_clips_t5xxlfp8.safetensors"
58+
},
59+
"class_type": "CheckpointLoaderSimple",
60+
"_meta": {
61+
"title": "Load Checkpoint"
62+
}
63+
},
64+
"271": {
65+
"inputs": {
66+
"seed": 291740611171897,
67+
"steps": 28,
68+
"cfg": 4.5,
69+
"sampler_name": "dpmpp_2m",
70+
"scheduler": "sgm_uniform",
71+
"denoise": 1,
72+
"model": ["13", 0],
73+
"positive": ["6", 0],
74+
"negative": ["71", 0],
75+
"latent_image": ["135", 0]
76+
},
77+
"class_type": "KSampler",
78+
"_meta": {
79+
"title": "KSampler"
80+
}
81+
},
82+
"273": {
83+
"inputs": {
84+
"filename_prefix": "sd3/sd3",
85+
"images": ["231", 0]
86+
},
87+
"class_type": "SaveImage",
88+
"_meta": {
89+
"title": "Save Image"
90+
}
91+
}
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)