Nodes/ComfyUI_OllamaUnload/Ollama Unload (free VRAM)
ComfyUI Node

Ollama Unload (free VRAM)

Ollama is squatting on your VRAM — this node evicts it before the sampler runs

By bradsec·Created 2 months ago·Updated 2 months ago· 0
Ollama Unload (free VRAM)
  • passthrough
  • passthrough
  • status
urlhttp://127.0.0.1:11434
model
waittrue
timeout60
free_comfy_vramtrue

If you run Ollama and your diffusion model on the same GPU, you've met this wall. You use Ollama for prompt writing, vision captioning, or negative-prompt generation, then the KSampler fires - and dies with torch.OutOfMemoryError, because the LLM is still parked in VRAM. A 26B model eats something like 17 GB. Add Flux2 on a 24 GB card and there is simply no room for both. This node is a tiny utility that kicks the LLM out of memory right before the image step, so the whole card belongs to the sampler.

The name is accurate

This is a single node, Ollama Unload (free VRAM), found under Add Node > Ollama. It does one thing and does it cleanly: it talks to Ollama directly over its HTTP API - no key, no extra pack, no Python dependencies beyond the standard library. It's designed to sit alongside something like stavsap/comfyui-ollama, which is the pack people usually use to run Ollama inside ComfyUI in the first place.

How it works (the keep_alive tradeoff)

Here's the trap the README walks you through, and it's a good one. Set keep_alive to 0 on your Ollama Connectivity node and you dodge the OOM - but Ollama reloads the whole model between every LLM stage, which is slow and, on a big model, costs you 10–20 seconds each time. Set it to 5+ minutes and a multi-stage chain (vision analysis → prompt write → edit → negative prompt) stays fast, because the model stays resident across all stages. The catch: it's still resident when sampling starts. This node splits the difference - you keep the long keep_alive, then drop this node after the last LLM stage.

Under the hood it uses Ollama's documented graceful unload: POST /api/generate with keep_alive: 0. That matters, because the obvious hack - killing ollama serve - doesn't work; the server just respawns and reloads the model. The node also polls /api/ps to confirm the model has actually left memory before it lets the workflow continue.

The inputs that matter

You'll touch maybe three of these, and one of them is the whole point:

  • passthrough - the one that forces the node to run before the sampler. ComfyUI only guarantees execution order through data flow, so you wire your final prompt (or conditioning) into passthrough, and feed passthrough out into your CLIP Text Encode → KSampler path. Now the sampler depends on this node, so unload has to finish first.
  • model - exact name to unload (e.g. gemma4:26b). Leave it empty and it unloads everything loaded. A named model that isn't resident is skipped - it's never loaded just to be unloaded, which would be a pointless VRAM spike.
  • free_comfy_vram - default true; also unloads ComfyUI's own models and empties the CUDA cache, so you free the whole card in one go.

The rest are sensible defaults: wait (block until it's really gone), timeout (max 600s to wait and poll), url (default http://127.0.0.1:11434, only change it if Ollama isn't local). Outputs are passthrough (your value, unchanged) and a human-readable status string like unload requested: gemma4:26b; comfy vram freed.

Installing it

Install via Manager > Custom Nodes Manager - search for ComfyUI_OllamaUnload - or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/bradsec/ComfyUI_OllamaUnload

Then restart ComfyUI. That's it: no requirements.txt, no model downloads, no pip. Rarer than a custom node with zero deps.

Where people get burned

  • Forgetting the passthrough wiring. Drop this node into your graph without routing a value through it and ComfyUI may run it whenever it pleases - which can be after sampling. The passthrough trick isn't a suggestion, it's the mechanism.
  • Unreachable Ollama. The node fails loudly (RuntimeError) rather than silently letting you OOM later - annoying, but the failure is at least honest.
  • The still-resident warning. If wait times out with a model still in /api/ps, you get a warning in status. Usually means Ollama is busy or the model won't drop; the node tells you instead of guessing.

One companion tip: launch ComfyUI with a low --reserve-vram (like 1) so image gen gets the whole card once the LLM is gone. Real-world threads about this problem - people on 8–12 GB cards where Ollama blocks checkpoint loading - usually resolve to "set OLLAMA_KEEP_ALIVE=0," which trades speed for relief. This node is the version of that fix that doesn't make you pay for it on every stage. It's a niche tool, but if you're in the niche, it's exactly right.

CategoryOllama

Inputs (6)

NameTypeDefaultDescription
urlSTRINGhttp://127.0.0.1:11434Ollama server base URL, e.g. http://127.0.0.1:11434.
modelSTRINGExact model name to unload (e.g. gemma4:26b). Empty = unload every loaded model.
waitBOOLEANtrueBlock until the model leaves Ollama memory (VRAM actually freed) before continuing.
timeoutINT601–600Max seconds to wait for the unload and the resident-memory poll.
free_comfy_vramBOOLEANtrueAlso unload ComfyUI's own models and empty the CUDA cache.
passthroughopt*Wire your final prompt/conditioning through here so this node runs BEFORE the sampler.

Outputs (2)

NameTypeDescription
passthrough*
statusSTRING