DiffusionGemma Encode (KV Cache)
Mint or advance a KV cache — DGemmaEncode conditions DiffusionGemma on context
- model
- kv_cache
- kv_cache
Most of the time you don't need this node. If you just want DiffusionGemma to answer a prompt, wire DGemmaLoader straight into DGemmaSampler and be done. DGemmaEncode exists for the harder case: conditioning a run on context - background text that shapes the generation without being the prompt itself - and for the provenance-sensitive experiments this pack is built around. It's the mint/advance half of the KV-cache seam; DGemmaDenoise is the other half.
The trick is that one node does two jobs, and the difference is a single connection. Leave the optional kv_cache input unwired and the node mints a fresh cache from your text. Wire an existing cache in and the same node advances it with newly committed text. There's no mode widget - the presence of the wire is the mode.
How it works
The text input gets tokenized directly - no chat role markers, no generation-prompt suffix, no thinking mechanism - and run through the model's encoder to produce key/value tensors. That's the important semantic difference from the prompt you'd type on a sampler: this text conditions as background. It shapes what gets generated, but it cannot restrict output the way a real prompt does. The current turn's text belongs on DGemmaDenoise's prompt widget; this node's text is the independent context that context-free run would otherwise be missing.
Output is a single kv_cache (DGEMMA_KV_CACHE) socket. Feed it into DGemmaDenoise's kv_cache input to condition a run.
The one input you'll actually touch
text- the raw context, multiline. On a fresh mint this is the full context. When you're advancing a wired cache, it's the newly committed continuation.model- fromDGemmaLoader(required, obvious).kv_cache- optional; the mint/advance switch described above.
Where people get burned
The pack's own docs flag this one loudly, and it's subtle. When DGemmaDenoise composes a prompt onto this node's output cache, the cache object is grown in place. ComfyUI caches node results, so a later run can silently hand you the already-grown cache - you'll see the wrong or stale turn echoed back. If that happens, don't reuse the cached output: invalidate the node (change an input, or force re-execution). The README's guidance is blunt - re-run DGemmaEncode to mint fresh.
Also note where this fits in the bigger picture: the KV-cache path is the pack's answer to separating provenance from mere commit dynamics (issue #78). Content can freeze early from a memorized answer-shape with zero in-canvas work; a known-provenance injected cache is how you distinguish "diffusion computed this" from "the model recalled this." If that distinction doesn't matter to your workflow, you can skip this node entirely.
Install
It's part of the ComfyUI-DiffusionGemma pack - Manager install (search the pack title) or clone into custom_nodes, restart, and make sure transformers==5.13.0 + diffusers>=0.39.0 landed. One honest caveat: the KV-cache seam is labeled Phase 3/4 in the pack's own ADRs, and the decoder-drive body only fully landed recently (PR #242, ac3c832). It's live, but it's the most experimental surface of the pack - expect to read the README's known-limitations section before you trust a composed run.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| model | DGEMMA_MODEL | Loaded DiffusionGemma model (from DGemmaLoader). | |
| text | STRING | Raw-encoded CONTEXT — NOT a prompt slot. Tokenized directly (no chat role markers, no generation-prompt suffix, no thinking mechanism) and conditions as background; it cannot restrict output the way a prompt does. The current-turn text belongs on DGemmaDenoise's prompt widget, not here. On a fresh mint this is the full context; when advancing a wired cache, this is the newly-committed continuation. | |
| kv_cacheopt | DGEMMA_KV_CACHE | UNWIRED = mint a fresh cache from text. WIRED = advance the incoming cache with text. This one connection is what switches mint vs. advance — there is no separate mode widget. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| kv_cache | DGEMMA_KV_CACHE | — |