Nodes/ComfyUI LLM SDXL Adapter/T5Gemma Text Encoder
ComfyUI Node

T5Gemma Text Encoder

The T5Gemma branch's text front end

By NeuroSenko·Created about a year ago·Updated 10 months ago· 68
T5Gemma Text Encoder
  • llm_model
  • llm_tokenizer
  • hidden_states
  • attention_mask
  • info
textmasterpiece, best quality, 1girl, anime style
max_length512
devicecuda
dtypebfloat16

T5GEMMATextEncoder is the T5Gemma branch's version of LLMTextEncoder - the node that turns your prompt into the hidden states the adapter chain consumes. Same spirit, different mechanics. Where the Gemma encoder wraps your text in a chat template and relies on a system prompt, this one takes the plain T5-style approach: tokenize, pad to a fixed length, run through the encoder, hand back the token-level states and the attention mask.

It's the middle link in a chain that looks like T5GEMMALoader → T5GEMMATextEncoder → t5gemmaApplyLLMToSDXLAdapter. Because the apply node on this branch needs an attention mask (more on that there), this encoder is the only one in the pack that outputs one - hidden_states alone won't get you through the T5Gemma apply node.

What it does

The encode path is simple and legible: it appends <eos> to your text, tokenizes with padding="max_length" and truncation to max_length, runs the model, and returns the last_hidden_state cast to float32. No chat template, no token skipping - it's a straight encoder pass.

The inputs that matter:

  • llm_model / llm_tokenizer - from T5GEMMALoader.
  • text - your prompt, same natural-language-friendly behavior as the Gemma branch.
  • max_length (default 512, up to 4096) - the fixed sequence length everything pads to. This has to line up with what the adapter expects; leave it at 512 unless you know better.
  • device (cpu or cuda, default cuda) and dtype (float32 or bfloat16, default bfloat16) - your precision/VRAM trade-off, right on the node.

Outputs: hidden_states (LLM_HIDDEN_STATES), attention_mask (LLM_ATTENTION_MASK), and info (STRING with the shape).

Honest notes

This is the least "finished-feeling" corner of the pack - the README documents the Gemma adapter, not a T5Gemma one, so you're on your own for weights that match the 2304-dim t5gemma preset. If that's what you're doing, this node is the reference implementation of how to feed the encoder. If you just want sentences working in SDXL, the Gemma branch (LLMModelLoaderLLMTextEncoder) is the smoother path.

Install

Ships with the ComfyUI LLM SDXL Adapter pack - ComfyUI Manager, search "ComfyUI LLM SDXL Adapter", or clone https://github.com/NeuroSenko/ComfyUI_LLM_SDXL_Adapter.git into ComfyUI/custom_nodes/ and restart. Dependencies: transformers>=4.53.1, einops, safetensors, torch.

Troubleshooting

  • Attention mask goes in, error comes out - you tried to use this with the wrong apply node. The Gemma ApplyLLMToSDXLAdapter has no mask input; use t5gemmaApplyLLMToSDXLAdapter.
  • Wrong shapes vs. the adapter - check max_length against your adapter's target_seq_len expectation; a mismatch shows up as a linear-layer error on the other side.
  • Slow encoding on float32/cpu - expected. The dtype/device inputs exist precisely so you can drop to bf16 on GPU.
Categoryllm_sdxl

Inputs (6)

NameTypeDefaultDescription
llm_modelLLM_MODEL
llm_tokenizerLLM_TOKENIZER
textSTRINGmasterpiece, best quality, 1girl, anime style
max_lengthINT5128–4096
deviceCOMBOcuda2 options: cpu, cuda
dtypeCOMBObfloat162 options: float32, bfloat16

Outputs (3)

NameTypeDescription
hidden_statesLLM_HIDDEN_STATES
attention_maskLLM_ATTENTION_MASK
infoSTRING