Nodes/arkennemasis Nodes/arkennemasis Purge VRAM (between stages)
ComfyUI Node

arkennemasis Purge VRAM (between stages)

The node that actually gets your VRAM back between stages

By Hishamahmer·Created 2 months ago·Updated 8 days ago· 9
arkennemasis Purge VRAM (between stages)
  • images
  • anything
  • images
  • anything
  • report
unload_modelstrue
empty_cachetrue
collect_garbagetrue

ComfyUI is a hoarder. It keeps models loaded so the next queue doesn't pay the load cost again, and most of the time that's the right trade. But when stage one loads a big model and stage two needs a different big model, the second one just doesn't fit. ArkPurgeVRAM is the explicit "leave the stage" button: unload every model, empty the CUDA cache, then pass your input straight through to the next stage.

The neat trick is in how you place it. The images input is a pass-through - you wire the image generator into it and take images back out into the next stage. That link is what makes ComfyUI run the purge at exactly that point in the graph, between the two models, instead of at some random moment you don't control. Same deal for the anything wildcard input, which passes any non-image value through.

How it works

The purge is more thorough than a plain "free VRAM" call, and the order matters:

  1. gc.collect() - releases tensors stuck waiting on a reference cycle.
  2. unload_all_models() - evicts every loaded model. This is the one that actually frees the gigabytes.
  3. A sweep of cleanup_models_gc, cleanup_models, reset_cast_buffers - the calls that release the pinned host buffers dynamic loading stages weights into. The source is blunt about why: on a 1280×736 MiniMax H3 scene that's roughly 94 GB of system RAM that never comes back, and scene 2 or 3 dies with a misleading CUDA OOM while the GPU sits nearly empty.
  4. soft_empty_cache(force=True) plus torch.cuda.empty_cache() - returns PyTorch's cached blocks to the driver. Without this the memory stays reserved and the next model still can't see it.

IS_CHANGED returns NaN, so the purge is never served from ComfyUI's cache - a purge that didn't run would be worse than no purge.

The inputs that matter

  • unload_models (true) - evict everything from VRAM.
  • empty_cache (true) - give the driver the memory back.
  • collect_garbage (true) - run the Python collector first.
  • images, anything - the pass-throughs that position the purge in the graph.
  • report - a "VRAM 12.3 → 18.1 GB (+5.8) | RAM …" line, which is genuinely useful for knowing whether the purge did anything.

Install and gotchas

One of the 61 nodes in the arkennemasis pack:

cd ComfyUI/custom_nodes
git clone https://github.com/Hishamahmer/comfyui-arkennemasis
pip install -r ComfyUI/custom_nodes/comfyui-arkennemasis/requirements.txt

Restart, or install via ComfyUI Manager by repo URL.

Two honest caveats. First, this is a blunt instrument - it unloads everything, so if your two stages actually share a model, you're paying a reload cost for nothing. Second, remember the NaN cache-busting: the purge forces everything behind it to re-run, which is exactly what you want for the purge itself but means it shouldn't sit in the hot path of a graph you re-queue a lot. Use it where the README says - between stages that use different big models - and it'll save you a class of OOMs that no amount of "it'll fit" reasoning can fix.

Categoryarkennemasis/Utility

Inputs (5)

NameTypeDefaultDescription
unload_modelsBOOLEANtrueEvict every loaded model from VRAM. This is the one that actually frees the gigabytes.
empty_cacheBOOLEANtrueReturn PyTorch's cached blocks to the driver. Without this the memory stays reserved and the next model still cannot see it.
collect_garbageBOOLEANtrueRun Python's collector first, so tensors waiting on a reference cycle are actually released.
imagesoptIMAGEWire the image generator in here and take `images` back out into the next stage. That link is what makes ComfyUI run the purge at this point in the graph.
anythingopt*Same idea for anything that is not an image — any type in, the same value out.

Outputs (3)

NameTypeDescription
imagesIMAGE
anything*
reportSTRING