Skip to content

v2.4.9 - Unify Model Patch Memory Cleaner into General Purge VRAM V2

Choose a tag to compare

@ussoewwin ussoewwin released this 07 Oct 15:52
· 6 commits to main since this release
EN 中文

Overview

In v2.4.9, the standalone Model Patch Memory Cleaner custom node has been deprecated and officially unregistered from ComfyUI's node catalog (NODE_CLASS_MAPPINGS and NODE_DISPLAY_NAME_MAPPINGS). Its complete functionality has been fully consolidated into General Purge VRAM V2 (DisTorchPurgeVRAMV2) under the clear_model_patches toggle, accompanied by immediate physical CUDA memory recovery.


Technical Details & Architecture

1. Problem & Architectural Rationale

Previously, users running specialized patch workflows—such as ModelPatchLoader (Z-Image ControlNet, QwenImage BlockWise ControlNet, SigLIP MultiFeat Proj, etc.)—required placing an extra standalone Model Patch Memory Cleaner node prior to upscaling stages to prevent out-of-memory (OOM) exceptions.

While DisTorchPurgeVRAMV2 already featured a clear_model_patches toggle, an architectural discrepancy existed:

  • In the standalone node, unloading model patches was immediately followed by:
    if clean_gpu and torch.cuda.is_available():
        torch.cuda.empty_cache()
        torch.cuda.synchronize()
    if force_gc:
        gc.collect()
  • In DisTorchPurgeVRAMV2, purge_cache (which executes torch.cuda.empty_cache()) ran at the very top of the node execution flow—before model patches were unloaded. Consequently, if a user configured purge_models = False (intending to retain the base Diffusion/UNet checkpoint while discarding patch weights), the patch models were unhooked from ComfyUI's tracking, but their GPU cache memory was not immediately reclaimed by the caching allocator, delaying physical VRAM release.

2. Complete Functional Consolidation into DisTorchPurgeVRAMV2

In this release, DisTorchPurgeVRAMV2 (in both nodes/purge_vram.py and root purge_vram.py) now provides full functional parity with the standalone cleaner:

  1. ModelPatcher Inspection: Scans current_loaded_models in reverse order for ModelPatcher instances with active additional_models or attachments.
  2. Safe Unload & De-registration: Marks models as unused (currently_used = False), executes model_unload(), and pops them from current_loaded_models.
  3. ComfyUI GC: Calls comfy.model_management.cleanup_models_gc().
  4. Instant Physical VRAM Release: Directly executes:
    if torch.cuda.is_available():
        torch.cuda.empty_cache()
        torch.cuda.synchronize()
        print("GPU memory cleared")
    
    gc.collect()
    print("Garbage collection completed")
    
    print("Model patch memory cleanup completed")

This guarantees immediate, deterministic physical VRAM recovery even when purge_models=False.

3. Node Unregistration & Catalog Cleanup

The standalone ModelPatchMemoryCleaner has been removed from NODE_CLASS_MAPPINGS and NODE_DISPLAY_NAME_MAPPINGS in __init__.py.

  • ComfyUI's node search palette now exposes only the three primary nodes:
    • General Purge VRAM V2 (DisTorchPurgeVRAMV2)
    • Memory Manager (Advanced) (MemoryManager)
    • Patch Sage Attention DM (PatchSageAttentionDM)
  • Workflows that previously utilized Model Patch Memory Cleaner should seamlessly transition to General Purge VRAM V2 with clear_model_patches: True.

Migration Guide for Workflows

  • Previous Workflow:
    [ModelPatchLoader] → [ControlNet Node] → [Model Patch Memory Cleaner] → [Upscaler]
    
  • Recommended Workflow (v2.4.9+):
    [ModelPatchLoader] → [ControlNet Node] → [General Purge VRAM V2 (clear_model_patches=True)] → [Upscaler]
    
    (To keep your base diffusion model loaded while discarding patch weights, set clear_model_patches=True and purge_models=False).