ComfyUI Node

Model Offload

Kick a model out of VRAM mid-run, without reloading

By lokinou·Created 11 months ago·Updated 8 months ago· 2
Model Offload
  • trigger_value
  • model
  • *
  • *
deviceauto
on_errorraise
enabletrue

You're running a workflow where two big things need the GPU but can't share it. Say you sampled with a Flux transformer and now the VAE decode spikes, or you want to chain a second model after the first. ComfyUI's automatic memory management will eventually shuffle things around - but it decides when, not you, and it likes to keep the big transformer resident because it's still referenced in the graph. Model Offload is the "right now" button: when it executes, it yanks the model wired into it off the GPU and onto CPU memory, frees the cache, and lets whatever comes next have the card to itself.

This is the companion to Model Recall in the same lokinou/comfyui-better-flow pack. Offload pushes a model out, Recall pulls it back. You usually use them as a pair around a VRAM-hungry middle section: offload after sampling, run your expensive step, recall before the next sampler.

How it works

The node isn't a fake passthrough - it does real work on the model object. It scans whatever you feed into model, finds the ModelPatcher (the wrapper ComfyUI uses for loaded weights), and moves its weights with model.to(offload_device), then runs gc.collect() and ComfyUI's cleanup_models_gc() + soft_empty_cache() to actually free the VRAM. It also checks that the move succeeded by comparing the model's device before and after.

The part the author clearly sweated over is GGUF models. Quantized models use GGUFModelPatcher, which normally pins weights via its load_on_device / patch_on_device behavior - so the node special-cases them: it ejects the model, unpatches it, moves the weights, and overrides that flag. The README's changelog shows this was the 0.1.2 fix, explicitly "fixed for GGUF flux model." The upshot: it works whether you loaded .safetensors or a Q4 .gguf, and regardless of whether you launched ComfyUI with --low-vram. The one thing it refuses is Nunchaku-managed models, which manage VRAM outside Python entirely.

Inputs and outputs that matter

  • trigger_value (required, any type) - sequencing hook. Whatever you connect here is what makes the node fire at the right moment; it's passed straight through.
  • model (optional, any type) - the model to offload. Wire this from your checkpoint/UNet/GGUF loader.
  • device (default auto, choices auto/cpu/your GPUs) - where to push it. auto picks ComfyUI's normal offload device (CPU); you can force a specific cuda:N.
  • enable (default on) - handy for A/B: turn it off and the node becomes pure passthrough.
  • on_error (raise/ignore) - what to do if the model turns out to be unsupported.

Outputs are two wildcard pass-throughs: the trigger value and the (now-offloaded) model, so you can keep wiring it downstream and Recall it later. The model doesn't disappear from the graph when it leaves VRAM.

When to actually bother

Honest take: if you're just trying to fit one model on a small card, this isn't your lever - GGUF quantization is (Q8 is basically fp16 at half the size). Manual offload pays off in multi-model choreography: a checkpoint swap mid-pipeline, a heavy upscaler or second pass, running a LoRA-trained model and a base model in the same run. The move to CPU costs time - VRAM→RAM shuffling is slow - so you're trading seconds of latency for not OOM-ing. That's usually a good trade when the alternative is a crash or dropping your whole resolution.

Install

Install once for the whole pack via ComfyUI Manager (search "comfyui-better-flow"), or:

cd ComfyUI/custom_nodes
git clone https://github.com/lokinou/comfyui-better-flow.git

Then restart ComfyUI fully - not just Reload, a real restart - so the new nodes register. No pip step: the pack has zero Python dependencies beyond what ComfyUI already ships. One warning from the README: if you have the old comfyui-offload-models pack installed, remove it - it only worked on .safetensor models and will just confuse you.

Gotchas

If you see "unsupported model" errors, check on_error and which node produced the model - Nunchaku-backed flux will always fail offload (by design). And remember the model only stays offloaded until ComfyUI's own manager decides to pull it back; if a later node requests it, it comes back on its own.

Categoryworkflow

Inputs (5)

NameTypeDefaultDescription
trigger_value*
modelopt*
deviceoptCOMBOautoSelect the device to offload the model to.
on_erroroptCOMBOraiseWhat to do on error: ignore or raise an exception.
enableoptBOOLEANtrueEnable offloading of the model to the offload device.

Outputs (2)

NameTypeDescription
**
**