ComfyUI Node

Purge VRAM (UTK)

Out of memory mid-workflow? This node tells the GPU to get its act together

By whmc76·Created about a year ago·Updated 2 months ago· 72
Purge VRAM (UTK)
  • anything
  • anything
purge_cachetrue
purge_modelstrue

You know the drill: switch checkpoints mid-session, run a video gen, and the next job dies with a CUDA out-of-memory error even though you "cleared" things. ComfyUI does its own caching, but between the model you just used and the one you're about to, VRAM fills with stuff nobody asked to keep. Purge VRAM (UTK) is the "shake the GPU" button you can drop into a workflow so it happens automatically, at the right moment.

What it actually does

It's a small node with an anything input that passes through untouched - which is the clever bit, because it means you can chain it into a workflow wherever it's convenient and not break any wires. On run it does three things:

  1. torch.cuda.empty_cache() to release cached blocks,
  2. gc.collect() to sweep orphaned Python objects,
  3. if you leave purge_models on (it's on by default), it calls ComfyUI's own unload_all_models() and soft_empty_cache() - the same cleanup ComfyUI runs when you hit the "Free" button in the UI.

So the two toggles - purge_cache and purge_models - are "clear the scratch space" and "also kick the models out of RAM." Turn purge_models off if you only need the cache cleared and want the current checkpoint to stay loaded.

Where to put it (and where not to)

This is the part people get wrong. Because it can unload every model, it should go after the expensive work is done - right after your save/preview node at the tail of a stage - not in the middle of a pipeline that still needs the checkpoint. Drop it between stages in a multi-pass workflow and you'll watch the next sampler eat a re-load penalty every time.

Where it shines: long batch sessions, img2video chains where each clip loads a fresh model, and anything that switches between big checkpoints. Put it after the output node of the first stage and before the second stage loads, and the OOMs mostly stop happening.

Installing it

It's part of the ComfyUI-UniversalToolkit pack:

  • ComfyUI Manager → search ComfyUI-UniversalToolkit → Install → restart, or
  • cd ComfyUI/custom_nodes && git clone https://github.com/whmc76/ComfyUI-UniversalToolkit then pip install -r requirements.txt and restart.

No extra dependencies - it's plain torch, which you already have.

Common gotchas

  • It's marked as an output node - so it only runs when the workflow actually reaches it, and ComfyUI treats it as a terminal node. That's intentional; don't expect it to fire if the branch feeding it never executes.
  • Nothing visibly happens - correct. Its job is silent cleanup. If you want confirmation, watch your terminal for the "VRAM purged successfully" log line.
  • The anything passthrough doesn't fix your OOM - it's just a carrier so the node can sit in the graph. The cleanup is the whole show.

Honestly, if you run short sessions you may never need this node - ComfyUI frees VRAM reasonably well on its own. It earns its keep the moment you're chaining multiple models and starting to fight the memory ceiling. When that day comes, you'll be glad it's a two-minute fix instead of a restart ritual.

CategoryUniversalToolkit/Tools

Inputs (3)

NameTypeDefaultDescription
anything*
purge_cacheBOOLEANtrue
purge_modelsBOOLEANtrue

Outputs (1)

NameTypeDescription
anything*