This repository has been archived on 2026-10-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
imagelab-runpod/startup.sh
T
donnyandClaude Opus 5.5 7ca831bfb7 WIP snapshot before nobara-pc migration (2026-10-15)
Uncommitted and untracked work from main on nobara-pc, saved so nothing is lost during the move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 13:02:00 -07:00

324 lines
13 KiB
Bash
Executable File

#!/bin/bash
set -e
# ============================================================================
# ImageLab RunPod startup
# ----------------------------------------------------------------------------
# All model-downloading is owned by imagelab_v3_extension (it reads
# IMAGELAB_AUTO_DOWNLOAD + CIVITAI_TOKEN at server start). This script just
# brings up ComfyUI + the custom nodes the web app's graph references, then
# launches the server with sensible flags for the detected GPU.
# ============================================================================
COMFYUI_DIR="/workspace/ComfyUI"
CUSTOM_NODES_DIR="$COMFYUI_DIR/custom_nodes"
# Colors
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
log_step() { echo -e "${BLUE}[STEP]${NC} $1"; }
# ----------------------------------------------------------------------------
# Custom nodes
# ----------------------------------------------------------------------------
# Everything the web app's graph references plus a small set of QoL nodes.
# Keep this list tight — every entry slows boot.
#
# * imagelab_v3_extension → /imagelab/* API: hashing, downloads, CivitAI
# * ComfyUI-Inpaint-CropAndStitch → InpaintCropImproved / InpaintStitchImproved
# * ComfyUI-BRIA_AI-RMBG → BRIA_RMBG_ModelLoader_Zho + BRIA_RMBG_Zho
# * ComfyUI-WD14-Tagger → kept available (old AutoTag path; harmless if unused)
# * ComfyUI_UltimateSDUpscale → UltimateSDUpscale node (the Ultimate SD Upscale pass)
# * comfyui_controlnet_aux → AIO_Preprocessor (the ControlNet pass; in the list below)
# * ComfyUI-Manager → in-UI node manager (very useful on a fresh pod)
# * rgthree-comfy / custom-scripts → QoL UI nodes the user is likely to want
# ----------------------------------------------------------------------------
CUSTOM_NODES=(
# — required by the web app's graph —
"https://gitea.dev.blueoceanswim.com/donny/imagelab_v3_extension.git"
"https://github.com/lquesada/ComfyUI-Inpaint-CropAndStitch.git"
"https://github.com/ZHO-ZHO-ZHO/ComfyUI-BRIA_AI-RMBG.git"
"https://github.com/pythongosssss/ComfyUI-WD14-Tagger.git"
"https://github.com/ssitu/ComfyUI_UltimateSDUpscale.git"
# — QoL / general-purpose carried over from the old image —
"https://github.com/ltdrdata/ComfyUI-Manager.git"
"https://github.com/pythongosssss/ComfyUI-Custom-Scripts.git"
"https://github.com/chrisgoringe/cg-use-everywhere.git"
"https://github.com/rgthree/rgthree-comfy.git"
"https://github.com/cubiq/ComfyUI_essentials.git"
"https://github.com/cubiq/ComfyUI_IPAdapter_plus.git"
"https://github.com/Fannovel16/comfyui_controlnet_aux.git"
"https://github.com/ltdrdata/ComfyUI-Impact-Pack.git"
"https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite.git"
"https://github.com/WASasquatch/was-node-suite-comfyui.git"
"https://github.com/comfyanonymous/ComfyUI_experiments.git"
"https://github.com/JPS-GER/ComfyUI_JPS-Nodes.git"
"https://github.com/jamesWalker55/comfyui-various.git"
"https://github.com/Acly/comfyui-tooling-nodes.git"
)
# ----------------------------------------------------------------------------
# ComfyUI
# ----------------------------------------------------------------------------
setup_comfyui() {
log_step "Setting up ComfyUI"
if [ -d "$COMFYUI_DIR/.git" ]; then
log_info "ComfyUI exists — pulling latest"
git -C "$COMFYUI_DIR" pull --ff-only || log_warn "Failed to pull ComfyUI updates"
else
log_info "Cloning ComfyUI"
git clone --depth 1 https://github.com/comfyanonymous/ComfyUI.git "$COMFYUI_DIR"
fi
log_info "Installing ComfyUI requirements (skipping pre-installed torch)"
cd "$COMFYUI_DIR"
grep -v -E "^torch==|^torch\[|^torch$|^torchvision|^torchaudio" requirements.txt > /tmp/comfy_req.txt
pip install -r /tmp/comfy_req.txt 2>&1 | tail -10
rm -f /tmp/comfy_req.txt
}
# ----------------------------------------------------------------------------
# Custom nodes
# ----------------------------------------------------------------------------
install_custom_nodes() {
log_step "Installing custom nodes"
mkdir -p "$CUSTOM_NODES_DIR"
for repo in "${CUSTOM_NODES[@]}"; do
name=$(basename "$repo" .git)
path="$CUSTOM_NODES_DIR/$name"
if [ -d "$path/.git" ]; then
log_info "Updating $name"
git -C "$path" pull --ff-only 2>/dev/null || log_warn "Failed to update $name"
else
log_info "Cloning $name"
git -C "$CUSTOM_NODES_DIR" clone --depth 1 "$repo" 2>/dev/null || log_warn "Failed to clone $name"
fi
done
log_step "Installing node requirements"
for path in "$CUSTOM_NODES_DIR"/*/; do
name=$(basename "$path")
if [ -f "$path/requirements.txt" ]; then
log_info " $name"
pip install -q -r "$path/requirements.txt" 2>&1 | grep -v "already satisfied" || true
fi
done
# Some nodes have an install.py — run it if present.
for path in "$CUSTOM_NODES_DIR"/*/; do
if [ -f "$path/install.py" ]; then
log_info " install.py for $(basename "$path")"
( cd "$path" && python install.py 2>&1 | tail -3 ) || true
fi
done
}
# ----------------------------------------------------------------------------
# BRIA RMBG model (the BRIA_RMBG_* nodes look for it under their own dir)
# ----------------------------------------------------------------------------
download_bria_model() {
BRIA_DIR="$CUSTOM_NODES_DIR/ComfyUI-BRIA_AI-RMBG/RMBG-1.4"
if [ -f "$BRIA_DIR/model.pth" ]; then
log_info "BRIA RMBG-1.4 already present"
return
fi
log_step "Downloading BRIA RMBG-1.4"
python3 - <<PY || log_warn "BRIA RMBG download failed"
import os
from huggingface_hub import snapshot_download
snapshot_download(
repo_id="briaai/RMBG-1.4",
local_dir="$BRIA_DIR",
token=os.environ.get("HF_TOKEN") or None,
)
print("BRIA RMBG-1.4 downloaded")
PY
}
# ----------------------------------------------------------------------------
# TAESD preview decoder + SDXL VAE — pulled from HuggingFace (the CivitAI
# auto-download path can't reach them). TAESD is what `--preview-method taesd`
# needs to stream live preview frames as the sampler runs; the SDXL VAE is
# the common override most users want available without a manual download.
# ----------------------------------------------------------------------------
download_hf_models() {
local vae_approx="$COMFYUI_DIR/models/vae_approx"
local vae_dir="$COMFYUI_DIR/models/vae"
mkdir -p "$vae_approx" "$vae_dir"
if [ -f "$vae_approx/taesdxl_decoder.safetensors" ] && [ -f "$vae_dir/sdxl_vae.safetensors" ]; then
log_info "TAESD-XL + SDXL VAE already present"
return
fi
log_step "Downloading TAESD-XL + SDXL VAE from HuggingFace"
python3 - <<PY || log_warn "TAESD / SDXL VAE download failed"
import os
from huggingface_hub import hf_hub_download
token = os.environ.get("HF_TOKEN") or None
# TAESD-XL decoder → models/vae_approx/taesdxl_decoder.safetensors
# (ComfyUI's preview system looks for this exact filename in vae_approx/.)
hf_hub_download(
repo_id="madebyollin/taesdxl",
filename="taesdxl_decoder.safetensors",
local_dir="$vae_approx",
token=token,
)
print("TAESD-XL ready")
# SDXL VAE → models/vae/sdxl_vae.safetensors
hf_hub_download(
repo_id="stabilityai/sdxl-vae",
filename="sdxl_vae.safetensors",
local_dir="$vae_dir",
token=token,
)
print("SDXL VAE ready")
PY
}
# ----------------------------------------------------------------------------
# Feature models from HuggingFace (the CivitAI auto-download path can't reach
# these). The xinsir ControlNet-Union (Promax) drives the web app's ControlNet
# pass — including the Tile type for hi-res-fix-style upscaling — and a default
# ESRGAN model lets the Ultimate SD Upscale pass run out of the box. Both are
# existence-checked, so they download once onto the models volume.
# ----------------------------------------------------------------------------
download_feature_models() {
local cn_dir="$COMFYUI_DIR/models/controlnet"
local up_dir="$COMFYUI_DIR/models/upscale_models"
mkdir -p "$cn_dir" "$up_dir"
local cn_target="$cn_dir/xinsir-controlnet-union-sdxl-promax.safetensors"
if [ -f "$cn_target" ]; then
log_info "ControlNet-Union (Promax) already present"
else
log_step "Downloading xinsir ControlNet-Union-SDXL (Promax)"
python3 - <<PY || log_warn "ControlNet-Union download failed"
import os
from huggingface_hub import hf_hub_download
p = hf_hub_download(
repo_id="xinsir/controlnet-union-sdxl-1.0",
filename="diffusion_pytorch_model_promax.safetensors",
local_dir="$cn_dir",
token=os.environ.get("HF_TOKEN") or None,
)
# Rename to a self-describing filename — the web app keys ControlNet-Union
# handling off "union"/"promax" appearing in the file name.
os.replace(p, "$cn_target")
print("ControlNet-Union Promax ready")
PY
fi
if [ -f "$up_dir/RealESRGAN_x4.pth" ]; then
log_info "Default upscale model already present"
else
log_step "Downloading RealESRGAN_x4 upscale model"
python3 - <<PY || log_warn "Upscale model download failed"
import os
from huggingface_hub import hf_hub_download
hf_hub_download(
repo_id="ai-forever/Real-ESRGAN",
filename="RealESRGAN_x4.pth",
local_dir="$up_dir",
token=os.environ.get("HF_TOKEN") or None,
)
print("RealESRGAN_x4 ready")
PY
fi
}
# ----------------------------------------------------------------------------
# SageAttention (background) — ~3x sampler speedup on supported GPUs.
# ----------------------------------------------------------------------------
install_sage_attention() {
local setting="${SAGE_ATTENTION:-true}"
if [ "$setting" = "false" ]; then
log_info "SageAttention disabled (SAGE_ATTENTION=false)"
return
fi
log_step "Installing SageAttention in the background"
(
pip install -q sageattention 2>&1 | tail -3 \
&& touch /tmp/.sageattention_installed \
&& log_info "SageAttention installed" \
|| log_warn "SageAttention install failed"
) &
}
# ----------------------------------------------------------------------------
# ComfyUI launch — GPU-aware default args
# ----------------------------------------------------------------------------
start_comfyui() {
log_step "Starting ComfyUI"
cd "$COMFYUI_DIR"
if [ -z "$COMFYUI_ARGS" ]; then
VRAM_MB=$(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits 2>/dev/null | head -1)
VRAM_GB=$(( ${VRAM_MB:-0} / 1024 ))
GPU_NAME=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -1)
log_info "GPU: ${GPU_NAME:-unknown} (${VRAM_GB} GB)"
# Common args: bind all ifaces, TAESD live previews (what the web app
# reads as binary WS frames), CORS open so the browser can talk to us.
BASE_ARGS="--listen 0.0.0.0 --port 8188 --preview-method taesd --preview-size 768 --enable-cors-header"
if [ "$VRAM_GB" -ge 180 ]; then
log_info "Blackwell-class GPU — bf16"
COMFYUI_ARGS="$BASE_ARGS --bf16-vae --bf16-unet"
elif [ "$VRAM_GB" -ge 80 ]; then
log_info "Hopper-class GPU — bf16"
COMFYUI_ARGS="$BASE_ARGS --bf16-vae --bf16-unet"
elif [ "$VRAM_GB" -ge 40 ]; then
log_info "Ampere-class GPU — fp16"
COMFYUI_ARGS="$BASE_ARGS --fp16-vae --fp16-unet"
elif [ "$VRAM_GB" -ge 20 ]; then
log_info "Consumer GPU — fp16"
COMFYUI_ARGS="$BASE_ARGS --fp16-vae --fp16-unet"
else
log_info "Low-VRAM GPU — --lowvram"
COMFYUI_ARGS="$BASE_ARGS --lowvram"
fi
if [ -f /tmp/.sageattention_installed ] && [ "${SAGE_ATTENTION:-true}" != "false" ]; then
log_info "Enabling --use-sage-attention"
COMFYUI_ARGS="$COMFYUI_ARGS --use-sage-attention"
fi
fi
log_info "Args: $COMFYUI_ARGS"
log_info "ComfyUI on http://0.0.0.0:8188"
exec python main.py $COMFYUI_ARGS
}
# ----------------------------------------------------------------------------
# main
# ----------------------------------------------------------------------------
log_info "=========================================="
log_info "ImageLab RunPod"
log_info "=========================================="
log_info "CIVITAI_TOKEN=$( [ -n "$CIVITAI_TOKEN" ] && echo set || echo unset )"
log_info "IMAGELAB_AUTO_DOWNLOAD=$( [ -n "$IMAGELAB_AUTO_DOWNLOAD" ] && echo set || echo unset )"
log_info "SAGE_ATTENTION=${SAGE_ATTENTION:-true}"
log_info "=========================================="
setup_comfyui
install_custom_nodes
install_sage_attention # background
download_bria_model &
BRIA_PID=$!
download_hf_models &
HF_PID=$!
download_feature_models &
FEAT_PID=$!
wait $BRIA_PID $HF_PID $FEAT_PID || true
start_comfyui