Add apply_patches.sh: fix ComfyUI #14573 aimdo/DynamicVRAM sampler hang (ratio 0.0->0.4)
Browse files- apply_patches.sh +42 -0
apply_patches.sh
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# apply_patches.sh — apply local fixes to the pinned ComfyUI core that upstream
|
| 3 |
+
# hasn't merged yet. Idempotent; safe to run on every boot / every start.
|
| 4 |
+
#
|
| 5 |
+
# Patch 1 — ComfyUI #14573: sampler hangs at "Model Initializing" (and slow
|
| 6 |
+
# loads) with comfy-aimdo / DynamicVRAM on NVIDIA. Root cause:
|
| 7 |
+
# model_management.py forces MIN_WEIGHT_MEMORY_RATIO = 0.0 on NVIDIA, and
|
| 8 |
+
# aimdo's custom-allocator VRAM is untracked by get_free_memory(), so the
|
| 9 |
+
# weight-memory formula allocates ~0 MB to the model → deadlock on the first
|
| 10 |
+
# forward pass. Fix: use 0.4 (the non-NVIDIA default) so DynamicVRAM gets real
|
| 11 |
+
# VRAM → no hang AND fast staged loads. Remove once upstream fixes #14573:
|
| 12 |
+
# https://github.com/Comfy-Org/ComfyUI/issues/14573
|
| 13 |
+
|
| 14 |
+
set -uo pipefail
|
| 15 |
+
COMFYUI_DIR="${COMFYUI_DIR:-/workspace/ComfyUI}"
|
| 16 |
+
MM="$COMFYUI_DIR/comfy/model_management.py"
|
| 17 |
+
|
| 18 |
+
log(){ printf '[apply_patches] %s\n' "$*"; }
|
| 19 |
+
|
| 20 |
+
patch_min_weight_ratio(){
|
| 21 |
+
[ -f "$MM" ] || { log "model_management.py not found ($MM) — skipping"; return 0; }
|
| 22 |
+
if ! grep -qE '^[[:space:]]*MIN_WEIGHT_MEMORY_RATIO = 0\.0[[:space:]]*$' "$MM"; then
|
| 23 |
+
if grep -q '#14573' "$MM"; then
|
| 24 |
+
log "patch 1 already applied — ok"
|
| 25 |
+
else
|
| 26 |
+
log "patch 1: '= 0.0' line not present (ComfyUI changed?) — skipping, verify upstream"
|
| 27 |
+
fi
|
| 28 |
+
return 0
|
| 29 |
+
fi
|
| 30 |
+
cp "$MM" "$MM.orig.$(date +%s)" 2>/dev/null || true
|
| 31 |
+
sed -i -E \
|
| 32 |
+
's/^([[:space:]]*)MIN_WEIGHT_MEMORY_RATIO = 0\.0[[:space:]]*$/\1MIN_WEIGHT_MEMORY_RATIO = 0.4 # patched: ComfyUI #14573 (aimdo\/DynamicVRAM hang)/' \
|
| 33 |
+
"$MM"
|
| 34 |
+
if grep -q '#14573' "$MM" && ! grep -qE '^[[:space:]]*MIN_WEIGHT_MEMORY_RATIO = 0\.0[[:space:]]*$' "$MM"; then
|
| 35 |
+
log "patch 1 applied: MIN_WEIGHT_MEMORY_RATIO 0.0 → 0.4"
|
| 36 |
+
else
|
| 37 |
+
log "WARNING: patch 1 did not apply cleanly — inspect $MM"
|
| 38 |
+
fi
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
patch_min_weight_ratio
|
| 42 |
+
log "done"
|