Unload All Models
Free your VRAM mid-workflow — and don't worry, the weird input is on purpose
- passthrough
- model_to_unpatch
- clip_to_unpatch
- passthrough
Unload All Models (class MarUnloadAllModels) from the comfyui-mdsnodes pack is a reset button for your GPU. When it runs, it strips LoRA patches, kicks every model out of VRAM, and flushes PyTorch's CUDA cache. It's the kind of node you don't reach for every day, but when you need it - you need it badly.
It was built for the pack's model-tester workflow: fire a prompt through checkpoint A, then checkpoint B, then C, and watch VRAM climb each time until a run dies with an out-of-memory error. This node sits between tests and hands the GPU back a clean slate. If you've ever watched a ComfyUI workflow with three checkpoint loaders slowly eat itself, you already know why it exists.
How it works - and why it's a passthrough
The thing that looks weird at first is the required passthrough input. This node doesn't need your data for anything - it just needs a wire. There's a reason: ComfyUI only executes nodes whose outputs eventually feed an output node, working backward from the save/preview nodes. A node with only side effects (unload, clear cache) and no output chain would get pruned from the graph entirely, so the author gives it a wildcard * passthrough that carries whatever you connect straight through untouched. Wire it in the middle of a data stream - say, between your image save and the next stage - and it gets a guaranteed seat in every run.
When it fires, it does four things in order:
- If you connected model_to_unpatch and/or clip_to_unpatch, it calls
unpatch_model(unpatch_weights=True)anddetach()on each - a forceful un-LoRA-ing for models and CLIPs that picked up patches upstream. - It calls
comfy.model_management.unload_all_models()andsoft_empty_cache()- ComfyUI's own "drop everything" plus a gentle cache clear. - If force_gc is on (it is, by default), it runs
gc.collect(), thentorch.cuda.empty_cache()andtorch.cuda.ipc_collect()- the hard flush.
The inputs that matter
- passthrough - required, any type. Connect the data stream you want to carry; it comes out the other side byte-for-byte untouched.
- model_to_unpatch / clip_to_unpatch - optional. Only needed when a LoRA-applied MODEL or CLIP is part of the graph and you want the patches forcibly stripped.
- force_gc - boolean, defaults to
True. The hard garbage-collection + cache-empty pass. Flip it off if you want the lighterunload_all_models+soft_empty_cachepath.
The output is a single passthrough socket that echoes your input. That's it.
Installing it
No dependencies, no model files, stock ComfyUI only:
# ComfyUI Manager: search "ComfyUI-MDSNodes" and click Install
# or:
cd ComfyUI/custom_nodes
git clone https://github.com/MarwanDSAI/comfyui-mdsnodes
Restart, and it shows up under MDSNodes/utils.
Where people get burned
The honest caveat is that this is a hammer, and hammers have a cost. unload_all_models() doesn't just clear the cache - it evicts everything from ComfyUI's model cache, which means the next generation in that workflow reloads its checkpoint from disk. In a normal single-model workflow, drop one of these in the middle and you've made every run slower for no benefit. Reserve it for the workflows that genuinely juggle multiple models - the tester setups it was written for - or a spot where you've hit OOM and need a clean break between stages.
Second, it's a reset, not a shrinker. It frees VRAM between runs; it does nothing about a single generation that blows past your card's limit. If one sampler pass itself OOMs, no mid-graph unload node fixes that - that's a model-size/quantization problem (see the GGUF route in the KB's troubleshooting notes).
And a quiet gotcha from the source: the unpatching is wrapped in try/except with a warning print, so if a connected MODEL doesn't expose unpatch_model, the node just logs and moves on. Your LoRA might not actually be stripped. If the whole point of wiring model_to_unpatch was to kill a lingering patch, check the console output for [MarNodes] Warning lines - silent success is not guaranteed here.
Used where it's meant to be used - a tester or a multi-checkpoint pipeline - Unload All Models is the difference between babysitting VRAM and letting a long run finish itself.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| passthrough | * | Connect the data stream you want to pass through. | |
| model_to_unpatchopt | MODEL | Optional: Connect your MODEL stream to forcefully detach/unpatch all applied LoRAs. | |
| clip_to_unpatchopt | CLIP | Optional: Connect your CLIP stream to forcefully detach/unpatch all applied LoRAs. | |
| force_gcopt | BOOLEAN | true | Force Python garbage collection and CUDA cache empty. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| passthrough | * | The untouched input data passed forward. |