Nodes/ComfyUI-JNodes/Empty Cuda Cache
ComfyUI Node

Empty Cuda Cache

Free VRAM mid-graph without splitting your workflow

By JaredTherriault·Created 3 years ago·Updated about a month ago· 91
Empty Cuda Cache
  • passthrough
  • *

If you've ever hit an out-of-memory error partway through a big workflow - the first model runs fine, then the upscale or the second stage tips you over - this node is the pressure valve. It empties PyTorch's CUDA memory cache at the exact point you drop it into the graph, handing that reserved VRAM back so the next heavy step has room to breathe. And because it's a passthrough, you can insert it in the middle of a wire without restructuring anything: whatever goes in comes out unchanged, the cache clear just happens as a side effect when execution reaches it.

That "passthrough in the middle" design is the clever part. Normally you'd have no clean way to force a cache flush between two stages of one graph. Here you splice this node onto any connection between the memory-hungry step and the next one, and it fires right there. On a tight card running Flux, Wan, or an SDXL-plus-upscale chain, that can be the difference between a run completing and a run dying halfway.

How it works

PyTorch holds onto GPU memory it has allocated even after it's done using it, keeping it cached to reuse quickly. That's usually good, but between two large models it can mean the cache is squatting on VRAM the next model needs. This node calls the equivalent of emptying that cache - releasing the unused reserved memory back to the GPU - at its position in the execution order. The passthrough in / passthrough out wiring exists purely so you can control when it fires by where you place it, without breaking the data flow.

The inputs and outputs that matter

  • passthrough - a wildcard input. Whatever you connect (a latent, an image, a model, anything) passes straight through. Its only job is to place the node in the execution order at the point you want the cache cleared.

The output is a matching wildcard * - the exact same thing you fed in, so the graph continues as if the node weren't there, minus the freed VRAM.

How to install it

ComfyUI Manager, search JNodes, install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/JaredTherriault/ComfyUI-JNodes
pip install -r ComfyUI-JNodes/requirements.txt

No model downloads.

Common issues & troubleshooting

It didn't stop my OOM. Emptying the cache reclaims unused reserved memory; it can't evict a model that's still loaded and in use. If two big models genuinely need to be resident at once, no cache flush fixes that - you need quantization (GGUF Q4–Q5 is the usual lever for fitting large models on small cards), a smaller resolution, or ComfyUI's own model-offloading flags. This node buys headroom, it doesn't create VRAM.

Placement matters. It only frees memory at its point in the run. Put it after the step that hogged VRAM and before the step that needs it. Dangling off to the side where nothing forces it to execute, it does nothing.

No visible speedup. It's not a speed node - clearing the cache can even cost a little as memory gets reallocated later. Use it to avoid OOM, not to go faster.

Remember RAM isn't VRAM. If you're leaning on system-RAM fallback to survive, note that shuffling between RAM and VRAM is brutally slow - this node won't help there. Reducing the actual footprint is the real fix.

Categorysd

Inputs (1)

NameTypeDefaultDescription
passthrough*

Outputs (1)

NameTypeDescription
**