ComfyUI Node

PurgeVRAM

A panic button for your VRAM — and when it's actually worth hitting

By T8mars·Created 2 years ago·Updated 11 months ago· 90
PurgeVRAM
  • anything
    purge_cachetrue
    purge_modelstrue

    PurgeVRAM does exactly one thing: you drop it into a workflow, wire one wire to it, and it empties your GPU's memory when it runs. That's the whole pack - a single node forked out of the big ComfyUI_LayerStyle suite by chflame163. The README is refreshingly honest about it: "the code was all done by him, all the credit goes to him, except for separating the purge vram node." It exists so you can grab this one feature without installing the entire LayerStyle tree to get it.

    What it actually does

    When the node fires it does four things in order: runs Python's garbage collector, calls torch.cuda.empty_cache() and torch.cuda.ipc_collect() to return cached CUDA memory, then - if purge_models is on (it is, by default) - calls ComfyUI's model_management.unload_all_models() and soft_empty_cache(). The first two hand back VRAM ComfyUI is holding but not using: cached weights, intermediate tensors the allocator hasn't released. The last two are the hammer - they evict every checkpoint, LoRA, and text encoder loaded on the GPU, so the next generation starts clean and reloads whatever it needs from disk.

    The shape of the node tells you how to use it. The anything input uses the AnyType wildcard trick (credit to pythongosssss), so it accepts literally any wire - model, latent, image, number, you name it. That's not a bug; it's how ordering is enforced. ComfyUI executes in dependency order, so connecting anything upstream guarantees the purge only runs after that node finishes. And since it's an output node with nothing after it, it's a dead end in the graph by design - that's the point.

    The inputs (all three of them)

    • anything - feed it any connection to pin the purge to that point in the graph. This is the one that actually matters.
    • purge_models (default on) - whether to evict loaded models, or just clear cached tensors. Turn it off if you want the cheap version that doesn't force a reload later.
    • purge_cache (default on) - ...doesn't actually do anything. Honest note: it's declared in the schema but never read in the code; the cache clear always runs. Flip it off and nothing changes. Mildly annoying, but it means there's no wrong way to set it.

    Install

    ComfyUI Manager → Install Custom Nodes → search "purgevram". Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/T8mars/comfyui-purgevram
    

    Restart ComfyUI, done. There's no requirements.txt, no model downloads, no Python dependencies beyond what ComfyUI already ships - it's pure torch plus ComfyUI's own model_management. It's also registered on the Comfy Registry (publisher t8star), which is how Manager finds it.

    When to actually reach for it

    Straight talk: modern ComfyUI manages VRAM automatically, and the troubleshooting consensus is that most manual memory meddling makes things slower, not smoother. PurgeVRAM earns its place in three situations: a workflow that runs fine once but OOMs on the second run because the first left memory fragmented; you want to hand VRAM back to another app (Blender, a game, a second ComfyUI instance) without restarting; or you're switching between workflows that load different models and want the old ones gone.

    Where people get burned: it is not a fix for a model that genuinely doesn't fit. The community threads are full of people stacking purge nodes after every ksampler to fight Wan/Flux OOMs and still hitting walls - the actual fix there is quantization or block-swap, not purging. And don't forget the reload tax: after unload_all_models() the next generation re-reads every checkpoint from disk, so a purge right before a generation costs you real seconds of warmup. Put it at the end of a branch, after the save node, not in the middle of a tight loop. It's a panic button, and panic buttons are for the end of the run.

    Categoryutils

    Inputs (3)

    NameTypeDefaultDescription
    anything*
    purge_cacheBOOLEANtrue
    purge_modelsBOOLEANtrue

    Outputs (0)

    No outputs