ComfyUI Node

LLM Text Encoder

SDXL finally reads full sentences instead of tag soup

By NeuroSenko·Created about a year ago·Updated 10 months ago· 68
LLM Text Encoder
  • model
  • tokenizer
  • hidden_states
  • info
textmasterpiece, best quality, 1girl, anime style
system_promptYou are expert in understanding of user prompts for image generations. Create an image according to the prompt from user.
skip_first27

This is the node that makes the whole pack make sense. The ComfyUI LLM SDXL Adapter pack swaps SDXL's CLIP text encoders for a real language model - and LLMTextEncoder is where your words actually get read. Feed it the LLM_MODEL and LLM_TOKENIZER from a loader, type a prompt, and it hands back the hidden states the trained adapter will turn into SDXL conditioning.

Why bother? SDXL's CLIP-L + OpenCLIP-G combo is fine at booru tags and nothing else. A natural-language sentence mostly washes over it. The Gemma-based path this pack sets up handles tags and free-form language equally, up to hundreds of tokens, with no 77-token chunking and no weird splits. Community testing of the trained RouWei-Gemma adapter (thread 1m2k0lw) found it keeps multiple instructions from bleeding into each other - multi-character and nested scenes stay sharper than the stock encoders manage.

How it works

Under the hood it's the "prompt as a chat turn" pattern, the same thing the newer LLM-encoded models do natively. The node wraps your text in the model's chat template: your text becomes the user message, and system_prompt becomes the system message. The default system prompt ("You are expert in understanding of user prompts for image generations...") is a solid starting point - it's telling the model to behave like a prompt compressor rather than a chatbot.

Then it runs the model with torch.no_grad(), grabs the last layer's hidden states, and slices off the first skip_first tokens before handing you LLM_HIDDEN_STATES. That skip is deliberate: the front of a chat-templated sequence is padding, special tokens, and the system message - junk the adapter was never trained on. Leave it at 27 unless you have a reason not to; the info output tells you how many tokens survived after the cut.

The inputs and outputs that matter

  • model / tokenizer - wire these from LLMModelLoader or LLMGGUFModelLoader. Nothing else to set.
  • text - the actual prompt. This is where you feel the difference: write sentences, "a fox girl sitting in front of a monitor, her face lit by the screen, night lighting," not a 40-tag wall.
  • system_prompt - worth editing once you understand the model reads instructions. You can bias it toward tags, negative-ish instructions, whatever your workflow needs.
  • skip_first (default 27) - the one knob you might touch if your info shape looks wrong.
  • Outputs: hidden_states (LLM_HIDDEN_STATES) and info (STRING, a readout of the encoded shape).

Installing

In ComfyUI Manager, search "ComfyUI LLM SDXL Adapter" and install. Or:

cd ComfyUI/custom_nodes/
git clone https://github.com/NeuroSenko/ComfyUI_LLM_SDXL_Adapter.git

Restart ComfyUI. The pack needs transformers>=4.53.1, einops, safetensors, torch, and (only for the GGUF loader) gguf>=0.17.1. The catch is the model itself: the README is blunt that you need all files of gemma-3-1b-it in ComfyUI/models/llm/gemma-3-1b-it/ - not just the safetensors. Chat templates and tokenizers live in the small config files people skip, and this node can't do its thing without them.

Troubleshooting

  • "Text encoding failed" almost always means the model folder is incomplete or the tokenizer can't apply the chat template. Re-check you have tokenizer.json, tokenizer_config.json, special_tokens_map.json, and friends, not just weights.
  • Prompt weighting does nothing - (tag:1.4) and ((parentheses)) are CLIP-era syntax this path never implemented. That's a feature of the encoder, not a bug.
  • Long prompt drift: the 512-token ceiling is generous, but attention quality falls off well before it. A few strong concepts beat a novel.
  • If you want more insight, set the logger to INFO in __init__.py (the README shows exactly where) and the node logs shapes and tokens.
Categoryllm_sdxl

Inputs (5)

NameTypeDefaultDescription
modelLLM_MODEL
tokenizerLLM_TOKENIZER
textSTRINGmasterpiece, best quality, 1girl, anime style
system_promptoptSTRINGYou are expert in understanding of user prompts for image generations. Create an image according to the prompt from user.
skip_firstoptINT270–100

Outputs (2)

NameTypeDescription
hidden_statesLLM_HIDDEN_STATES
infoSTRING