From 242ff772a53fc9c345347adb99d51fbaede0daff Mon Sep 17 00:00:00 2001 From: Meisoftcoltd <38667978+Meisoftcoltd@users.noreply.github.com> Date: Sun, 12 Apr 2026 12:46:33 +0000 Subject: [PATCH] fix: optimize VRAM purge order and remove conflicting environment variable - Removed `PYTORCH_CUDA_ALLOC_CONF` from `__init__.py` to allow elastic VRAM expansion via `expandable_segments:True`. - Swapped `torch.cuda.empty_cache()` and `torch.cuda.synchronize()` order in `vram_node.py` to ensure pending operations finish before purging cache. - Added critical warnings in `README.md` and `README_EN.md` discouraging the use of `--highvram` flag when starting ComfyUI to prevent VRAM Defragmenter sabotage. --- README.md | 5 +++++ README_EN.md | 5 +++++ __init__.py | 4 ---- vram_node.py | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8d0a841..2e71c1e 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,11 @@ Para que el nodo `VideoAnalyzerWithAudio` pueda desempaquetar contenedores `.mp4 * **🪟 Windows:** Descarga los binarios precompilados de FFmpeg y añade la carpeta `bin` a tus variables de entorno (PATH). +### 🚨 Advertencia Crítica sobre el Uso de la VRAM +Se **desrecomienda encarecidamente** el uso del argumento `--highvram` al arrancar ComfyUI. + +El argumento `--highvram` le da la orden estricta a ComfyUI de mantener los modelos bloqueados en la memoria de video. Esto sabotea directamente el funcionamiento de nuestro `VRAM Defragmenter`, ya que bloquea el comando `mm.unload_all_models()` impidiendo que la gráfica se vacíe entre ciclos. Para que esta suite funcione correctamente con modelos masivos como WanVideo y evite errores de OOM (Out Of Memory), los usuarios deben usar el arranque estándar (o `--normalvram`), permitiendo que el sistema libere dinámicamente la memoria hasta llegar a 0 GB entre lotes. + --- ## 🧠 La Arquitectura Híbrida (Desglose de Nodos) diff --git a/README_EN.md b/README_EN.md index 68026ea..a6c1c4a 100644 --- a/README_EN.md +++ b/README_EN.md @@ -35,6 +35,11 @@ For the `VideoAnalyzerWithAudio` node to unpack `.mp4` containers and extract au * **🪟 Windows:** Download the precompiled FFmpeg binaries and add the `bin` folder to your environment variables (PATH). +### 🚨 Critical Warning Regarding VRAM Usage +The use of the `--highvram` argument when starting ComfyUI is **strongly discouraged**. + +The `--highvram` argument gives ComfyUI the strict command to keep models locked in video memory. This directly sabotages the operation of our `VRAM Defragmenter`, as it blocks the `mm.unload_all_models()` command, preventing the graphics card from emptying between cycles. For this suite to work correctly with massive models like WanVideo and avoid OOM (Out Of Memory) errors, users must use the standard startup (or `--normalvram`), allowing the system to dynamically release memory down to 0 GB between batches. + --- ## 🧠 The Hybrid Architecture (Node Breakdown) diff --git a/__init__.py b/__init__.py index 8c5ac04..003d492 100644 --- a/__init__.py +++ b/__init__.py @@ -1,9 +1,5 @@ import os -# Inyección algorítmica para evitar micro-fragmentación de VRAM en WanVideo -if "PYTORCH_CUDA_ALLOC_CONF" not in os.environ: - os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:128" - __version__ = "1.6.0" NODE_CLASS_MAPPINGS = {} diff --git a/vram_node.py b/vram_node.py index ce9d8bc..b92a13e 100644 --- a/vram_node.py +++ b/vram_node.py @@ -73,8 +73,8 @@ class MeisoftVRAMDefragmenter: if torch.cuda.is_available(): print(" -> 🧱 Desfragmentando Caching Allocator de CUDA...") torch.cuda.ipc_collect() - torch.cuda.empty_cache() - torch.cuda.synchronize() # Barrera contra race conditions + torch.cuda.synchronize() # 🚀 OPTIMIZACIÓN: Esperar a que terminen los kernels pendientes PRIMERO + torch.cuda.empty_cache() # 🚀 Luego vaciamos la caché de forma segura # --- FASE 7: LIBERACIÓN DE MEMORIA DEL SISTEMA (Multi-Plataforma) --- import platform