Nodes/ComfyUI-EmbeddingGemma2/EmbeddingGemma 2 Unload
ComfyUI Node

EmbeddingGemma 2 Unload

Get the 2.5 GB back before you sample

By hiroki-abe-58·Created about 23 hours ago·Updated about 16 hours ago· 0
EmbeddingGemma 2 Unload
  • after
  • report

The smallest node in the pack and the one most likely to save your run. EmbeddingGemma 2 in bfloat16 with all encoders resident is about 2.5 GiB of VRAM, and of course it wants that VRAM at exactly the wrong moment - mid-sampling, when your diffusion model is already at the edge.

This node frees it. That's it. No model input, no configuration, one output.

Why it isn't automatic

The loader has a keep_loaded toggle, which sounds like the answer and mostly isn't. Turn it off and the model is released after every encode node - so a workflow that encodes text, then images, then ranks, reloads the whole 740M-parameter model between each step. Loading takes about 3 seconds and a full cache flush. Do that three times and you've paid nine seconds to save memory you were going to use again thirty milliseconds later.

keep_loaded on plus an Unload node at the end of the embedding section is the right shape: pay for the load once, do all your encoding, then hand the memory back before the heavy part of the graph runs. Which is why the node exists as a separate thing.

How to wire it

One input, optional and slightly unusual: after, of type EG2_EMBEDDINGS. It plays no part in the unload - it's a sequencing hook. Connect an embeddings output and ComfyUI's graph forces the Unload downstream of that node, instead of wherever the scheduler feels like. An output node with no inputs is a loose end, and ordering isn't worth leaving to chance.

So: wire your last encode node's embeddings output into after, and skip the report output if you don't care. Everything downstream - samplers, upscalers, whatever - then runs with the embedding model gone.

The output is report, a JSON string that says {"unloaded": true} or false. False means there was nothing resident when it fired (already released, or never loaded) - not an error, just information. It also displays in the node's UI, since the pack pushes it to the text widget too.

It's a terminal node, on purpose

The node is registered as an output node and marked non-idempotent. Two consequences worth knowing:

  • It can be executed as an endpoint, like Save Image - it doesn't need anything downstream to justify running.
  • It re-runs every queue rather than being cached and skipped, because freeing memory is not something the cache should be allowed to think is "already done".

That also means one Unload per queue is the intent. If you're running a loop or a batch that repeatedly encodes then samples, put the Unload where it does the most good rather than sprinkling several around.

What it does and doesn't touch

It drops the pack's own resident model reference and calls torch.cuda.empty_cache(). It does not touch your checkpoint, your VAE, your CLIP, or anything else ComfyUI has loaded - ComfyUI's own model management is a separate system with its own unloading behaviour. If you're still out of memory after this fires, the problem is your diffusion model's footprint, not this pack.

When you'd skip it entirely

If you have headroom, don't bother. Modern cards run a 2.5 GiB tenant without noticing, and the whole pack's speed story - 0.06 s for an image, 0.13 s for a 5-second video on an RTX 5090 - depends on the model staying put. The Unload node is for tight cards, for workflows where an embedding step precedes a much heavier video or upscale stage, and for people who've already seen the OOM.

Keep in mind the reload cost: if you unload and then a later part of the same workflow needs another embedding, you're paying ~3 s and the peak allocation again. Order your graph so all encoding happens in one block.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/hiroki-abe-58/ComfyUI-EmbeddingGemma2
python -m pip install -r ComfyUI-EmbeddingGemma2/requirements.txt
python ComfyUI-EmbeddingGemma2/tools/download_model.py --models-dir ../models/embeddinggemma

ComfyUI Manager alternative: search EmbeddingGemma 2 for ComfyUI, restart when it's done. You need the model on disk regardless - the Unload node itself is trivial, but the pack's loader that feeds it wants a complete sentence-transformers folder inside models/embeddinggemma/, which is what the download script produces.

Two install friction points that apply to the whole pack. It's written against ComfyUI's V3 backend node API, so on a build older than roughly v0.38 nothing registers and it looks like a failed install. And sentence-transformers 6.1.0 requires huggingface-hub<2.0, so the requirements install downgrades hub from 2.2.0 to 1.33.0 - fine in the author's testing, but if some other custom node of yours starts throwing import errors afterwards, that's your suspect.

One honest limit: that 2.5 GiB figure is the author's, measured on Windows 11 with an RTX 5090. Linux GPU, macOS and AMD weren't verified with the real model, so your peak may differ.

Categoryloaders/embeddinggemma

Inputs (1)

NameTypeDefaultDescription
afteroptEG2_EMBEDDINGSOptional: connect embeddings so this runs after them

Outputs (1)

NameTypeDescription
reportSTRING—