YG Clean VRAM
Stuck VRAM after a run? YG Clean VRAM is the button you can wire
- passthrough
- passthrough
If you've ever queued a big video or a Flux run, then queued a small one, and watched it hit an out-of-memory error - you already know why a "clean VRAM" node exists. ComfyUI mostly manages memory on its own, but models hang around in the cache by design (it's what makes the next run fast), and when you switch tasks the leftover footprint can bite. YG Clean VRAM is a node that sits in your workflow and does what the dashboard's "Clean VRAM" button does, on schedule, right before you need the memory.
How it works
It's not magic and it's not an API call to some cloud service - it calls the same internal functions ComfyUI itself uses. The node unloads all loaded models (unload_all_models), forces the cache empty (soft_empty_cache(force=True)), then runs torch.cuda.empty_cache() plus, if you leave aggressive on, ipc_collect() and a synchronize to actually settle the GPU. It also sets the queue's free_memory/unload_models flags, which is the same thing ComfyUI's /free endpoint does, so any other queued prompt on this server gets a clean slate too.
The bit that's actually smart: it re-runs the cleanup in passes and measures GPU memory from nvidia-smi between them, stopping early once freeing stops helping. max_passes controls how many tries, and target_free_mb lets you say "keep going until used memory drops below this."
The inputs that matter
Most of these you can leave alone. The two worth touching:
unload_models- on by default. Turn it off if you want the model cache kept (faster next run, more VRAM used). Only useful if your problem is fragmentation rather than a loaded model.clean_all_servers- off by default. If you run multiple ComfyUI instances on one GPU, each only frees its own memory, and nvidia-smi still shows the others holding theirs. Flip this on to hit every local instance.
The dashboard_url/dashboard_token fields are for an optional server-status dashboard integration (defaults to 127.0.0.1:8194). The README is explicit: if you don't run a dashboard, leave them alone - when clean_all_servers is on and the dashboard is unreachable, the node falls back to POSTing /free directly to each known ComfyUI port (8188, 8189, 8190...). You can override that list with the YG_CLEAN_PORTS env var, or set YG_DASHBOARD_URL/YG_DASHBOARD_TOKEN.
Placement is the whole trick
The node has one output, passthrough, which forwards whatever you feed into its passthrough input. That's not decorative: wire any value in and route it onward, and the cleanup is guaranteed to run before your next node because the graph has to resolve it first. It's also marked as an output node, so it always executes even dangling. Typical use: put it at the start of a heavy workflow and feed it a constant, or drop it between two different-generation stages.
Installing it and honest caveats
Part of the comfyui_yg_nodes pack (MIT, no extra dependencies - the pyproject declares none). ComfyUI Manager: search comfyui_yg_nodes. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/mallikarjunaraokoliparthi/comfyui_yg_nodes.git
Restart and it lives in the YG_Nodes menu.
The honest caveat is the same one every VRAM node runs into: it only frees memory this process holds. If nvidia-smi shows several gigabytes still used after a clean and the node's own torch reading is near zero, that's other processes - enable clean_all_servers or shut them down. It won't fix an undersized GPU, either. What it's genuinely good for is clearing the accumulated gunk between jobs in a long session, without clicking around in a dashboard. For that, it's a real time-saver.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| unload_models | BOOLEAN | true | Unload all loaded models from VRAM. Disable to keep the model cache (faster next run, more VRAM used). |
| aggressive | BOOLEAN | true | Adds cuda.ipc_collect + synchronize after empty_cache. |
| max_passes | INT | 31–10 | Number of clean-then-measure passes. Stops early once VRAM stops dropping. |
| target_free_mb | INT | 00–200000 | Optional: keep cleaning until GPU 'used' drops to this many MB or below. 0 disables. |
| trigger_every_run | BOOLEAN | true | Re-execute on every workflow run (no caching). |
| clean_all_servers | BOOLEAN | false | Also clean VRAM on ALL ComfyUI servers via the dashboard (or by POSTing /free to each port). Use this if other ComfyUI instances on the same GPU are holding memory. |
| dashboard_url | STRING | http://127.0.0.1:8194 | Server Status Dashboard base URL (e.g. http://127.0.0.1:8194). |
| dashboard_token | STRING | Dashboard SECRET_TOKEN. | |
| passthroughopt | * | Optional value forwarded to the output. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| passthrough | * | — |