ComfyUI Node

Gemma Sampler

Let the LLM rewrite your prompt before you render

By kijai·Created 2 years ago·Updated 2 years ago· 196
Gemma Sampler
  • gemma_model
  • string
prompt
max_length128
temperature0.70
do_sampletrue
early_stoppingfalse
top_k50
top_p0.95
repetition_penalty1.00
length_penalty1.00
keep_model_loadedfalse

Gemma is already in your graph doing text encoding, so why not put it to work writing better prompts while it's there? That's the whole idea of GemmaSampler: instead of grabbing Gemma's hidden states as embeddings, it runs the model as an actual generative LLM - model.generate() and all - and hands you back a freshly rewritten prompt as a plain string.

It's the optional node of the pack, and that's fine. A basic Lumina workflow doesn't touch it. You add it when you want prompt expansion: type a stub like "a lighthouse in a storm," let Gemma spin it into a few sentences of scene description, and feed the result into LuminaGemmaTextEncode for a richer render. Think of it as a local, free prompt-expansion service that runs on your own GPU - no API key, no cloud call.

How it works

The node tokenizes your prompt, runs model.generate() with the sampling parameters you set, decodes the tokens back to text, and prints it to the console so you can see what it came up with. The output is a STRING, and it's a rewrite of the full prompt - including your original text - not just a continuation, so wire it into the prompt input of the text encoder, not somewhere that expects raw user text.

The inputs that actually matter

  • max_length - cap on generated tokens, default 128. Keep it modest; Lumina's encoder truncates at 256 anyway, and longer generations just take longer.
  • temperature (0.7 default) - creativity knob. Bump toward 1 for looser prose, drop toward 0 for more literal expansions.
  • do_sample - on by default. Turn it off for greedy decoding if you want the same expansion every time.
  • top_p (0.95) / top_k (50) - nucleus/top-k sampling. You can mostly leave these alone.
  • repetition_penalty and length_penalty - both default 1.0. If Gemma starts looping, nudge repetition_penalty up toward 1.1-1.2 rather than fighting it.
  • early_stopping - off by default, only relevant for greedy decoding.

Optional keep_model_loaded - like the encode nodes, it defaults to false and offloads Gemma after running. If you're chaining this into an encode in the same workflow, leave it false; the encode node will reload.

Output: one STRING, meant for LuminaGemmaTextEncode's prompt field.

Installing and running

Same pack install as everything else here:

cd ComfyUI/custom_nodes
git clone https://github.com/kijai/ComfyUI-LuminaWrapper
pip install -r requirements.txt

then restart ComfyUI. You need the Gemma model loaded first (the gated-download dance applies - accept the terms on HF or it won't download). Speed note: this is a real autoregressive LLM pass, not an embedding lookup, so it's the slowest node in the graph relative to how little it does. If it feels like the whole queue is stalling, that's it - lower max_length.

Honestly, you can skip this node entirely and still get great Lumina results. It's a nice-to-have for prompt writers and a trap only if you assume it's required. If your goal is prompt expansion specifically, try it once, keep a short stub, and let Gemma do the heavy lifting on prose.

CategoryLuminaWrapper

Inputs (11)

NameTypeDefaultDescription
gemma_modelGEMMAODEL
promptSTRING
max_lengthINT1281–512
temperatureFLOAT0.700–1
do_sampleBOOLEANtrue
early_stoppingBOOLEANfalse
top_kINT500–100
top_pFLOAT0.950–1
repetition_penaltyFLOAT1.000–10
length_penaltyFLOAT1.000–10
keep_model_loadedoptBOOLEANfalse

Outputs (1)

NameTypeDescription
stringSTRING