Files
comfyui-nvidia/deployments/ai-stack/comfyui-init-models.sh
William Gill 0fa8040251 Eliminate first-inpaint timeout: preseed SAM/GroundingDINO + 600s default
Two changes to address the timeout-and-retry loop the user hit on the
first edit_image call:

  1. comfyui-init-models.sh now fetches the three weights inpaint
     needs into /models/sams and /models/grounding-dino:
       - sam_hq_vit_h.pth                (~2.5 GB)
       - groundingdino_swint_ogc.pth     (~700 MB)
       - GroundingDINO_SwinT_OGC.cfg.py  (~1 KB)
     Without preseeding these auto-download on first inpaint, which
     takes minutes and times out the tool call. The mkdir line gets
     the new subdirs added too.

  2. Tool TIMEOUT_SECONDS valve default bumped 240s → 600s as
     defense-in-depth — even with weights preseeded, BERT-base
     auto-downloads via transformers on first GroundingDINO load
     (~30s) and a slow KSampler on a contended GPU can push past
     4 minutes occasionally. Steady-state runs still finish in under
     a minute; the valve only matters for first-call latency.

After comfyui-model-init re-runs (`docker compose up -d
comfyui-model-init`), first inpaint should be near-instant.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 15:39:23 -05:00

85 lines
3.4 KiB
Bash

#!/bin/sh
# Preseed ComfyUI's models volume with checkpoints, VAEs, LoRAs, etc.
# Runs once via the comfyui-model-init service (see docker-compose.yml).
# Safe to re-run — already-present files are skipped.
#
# ComfyUI doesn't have a "pull" command of its own, so this is plain curl
# against direct download URLs. For HuggingFace, the direct URL is:
# https://huggingface.co/<repo>/resolve/main/<file>
# For gated HF repos (Flux-dev, SD3, etc.), set HF_TOKEN in .env — the
# script attaches it as a bearer token automatically.
set -e
apk add --no-cache curl >/dev/null
mkdir -p /models/checkpoints /models/vae /models/loras /models/controlnet \
/models/clip /models/clip_vision /models/upscale_models /models/embeddings \
/models/sams /models/grounding-dino
fetch() {
dest="$1"; name="$2"; url="$3"
target="/models/$dest/$name"
if [ -f "$target" ]; then
echo "$dest/$name already present"
return
fi
echo "→ Downloading $dest/$name"
mkdir -p "/models/$dest"
if [ -n "$HF_TOKEN" ] && echo "$url" | grep -q huggingface.co; then
curl -fL -C - --retry 3 -H "Authorization: Bearer $HF_TOKEN" \
-o "$target.partial" "$url"
else
curl -fL -C - --retry 3 -o "$target.partial" "$url"
fi
mv "$target.partial" "$target"
}
# ─── Edit the list below to choose what gets preseeded ──────────────────────
# Format: fetch <subdir under /models> <filename to save as> <direct URL>
#
# No checkpoints are downloaded by default — the deployment ships expecting
# you to point at your own model mirror or the public examples below.
# Whatever filename you pick should match the `ckpt_name` field in
# workflows/txt2img.json and workflows/img2img.json (the shipped default
# is CyberRealisticXLPlay_V8.0_FP16.safetensors); update either the
# script or the workflows so they line up.
# Examples — uncomment what you want.
# SDXL Base 1.0 (~6.9 GB)
# fetch 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
# SDXL VAE (fixes washed-out colours on some SDXL checkpoints)
# fetch vae sdxl_vae.safetensors \
# https://huggingface.co/stabilityai/sdxl-vae/resolve/main/sdxl_vae.safetensors
# Flux.1-dev (~23 GB, gated — needs HF_TOKEN with access to black-forest-labs)
# fetch checkpoints flux1-dev.safetensors \
# https://huggingface.co/black-forest-labs/FLUX.1-dev/resolve/main/flux1-dev.safetensors
# 4x-UltraSharp upscaler
# fetch upscale_models 4x-UltraSharp.pth \
# https://huggingface.co/lokCX/4x-Ultrasharp/resolve/main/4x-UltraSharp.pth
# ─── Inpainting models (SAM-HQ + GroundingDINO) ─────────────────────────────
# Required by the smart_image_gen Tool's edit_image with mask_text. ComfyUI
# would auto-download these on first use, but that takes minutes and tends
# to time out in-flight tool calls — preseeding here makes the first inpaint
# instant.
fetch sams sam_hq_vit_h.pth \
https://huggingface.co/lkeab/hq-sam/resolve/main/sam_hq_vit_h.pth
fetch grounding-dino groundingdino_swint_ogc.pth \
https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/groundingdino_swint_ogc.pth
fetch grounding-dino GroundingDINO_SwinT_OGC.cfg.py \
https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/GroundingDINO_SwinT_OGC.cfg.py
echo "Done."