fix(vram): stop coexisting pipelines from rebuilding every run
BuildPipeline.build() called comfy's unload_all_models() to free ComfyUI-native torch weights, but that blanket free_memory(1e30) went through our own free_memory hook and was read as "destroy all QuantFunc pipelines" — so running a second pipeline destroyed the first (and vice-versa), forcing a full rebuild on every repeat run even with activate_unload on. - BuildPipeline self-cleanup now routes through free_comfy_native_models(), which calls the captured ORIGINAL (un-hooked) free_memory: clears comfy-native torch only, never touches QuantFunc pipelines. - The free_memory hook is now a measured graded ladder: VRAM pressure -> offload GPU->CPU only (offload frees the GPU; destroying an already- offloaded pipeline frees zero VRAM, so VRAM-triggered destroy was pure friendly-fire). RAM-low -> disk-page backups (madvise). Destroy is reserved for genuine host-RAM exhaustion only, clamped so the reversible disk-page rung always precedes the destructive rung. - LRU bookkeeping + resident-pipeline cap (QUANTFUNC_MAX_RESIDENT_PIPELINES, default 3) to bound growth now that blanket no longer destroys. Verified live (device 1, RTX 3060): Z-Image + Qwen-Edit coexisting, repeat runs reuse both pipelines (~22s) instead of rebuilding (64s+), with no friendly-fire destroy. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Y
yejianhui committed
7423ea72989fbb27bed2bba4bf4c813818d84167
Parent: abb8020