Nodes/Nukun_ComfyUI_Nodes/T5/Qwen Equal-Length Prompt Balancer (Nukun)
ComfyUI Node

T5/Qwen Equal-Length Prompt Balancer (Nukun)

Make your T5 positive and negative prompts the same length

By OnekoSL·Created 3 months ago·Updated 11 days ago· 1
T5/Qwen Equal-Length Prompt Balancer (Nukun)
  • tokenizer
  • positive
  • negative
  • positive_raw_tokens
  • negative_raw_tokens
  • effective_target
  • report
target1024
positive
negative

T5-based models (Pony v7, AuraFlow, anything running a T5/Qwen text stream) have an odd quirk: positive and negative prompts that end up wildly different token lengths can behave inconsistently, because the model treats the conditioning differently depending on how much padding it got. This node fixes that by encoding both prompts to the same effective token length. It's the "safer, better instrumented" replacement for the older T5Balancer, and it's a boring, dependable, easy-to-recommend node - which is exactly why it deserves a spot in your Pony v7 toolkit.

The math is simple and honest: it measures both prompts without padding, then targets max(target, positive_raw_tokens, negative_raw_tokens). Long prompts are preserved instead of truncated - the classic balancer mistake of chopping your good prompt down to the shorter one's size. If your negative is short and your positive is long, both get padded up to the positive's length, which is what you actually want.

How it works

Feed the node a CLIP (tokenizer input) - it auto-detects the active T5/Qwen stream from the supported keys (t5xxl, mt5xl, qwen3_4b/8b, qwen3vl, umt5xxl, etc.) - plus positive and negative strings. It tokenizes, computes the effective target, and encodes both prompts with padding to match. Default target is 1024.

The outputs tell you exactly what happened: positive and negative conditionings for your sampler, positive_raw_tokens and negative_raw_tokens for the unpadded counts, effective_target for the length actually used, and a report string for prompt tuning. If you're wondering why a prompt looks different after balancing, the report and the token counts answer it.

The one setting you'll actually change is target. On a low-memory machine, set it to 0 - that equalizes to the longer real prompt instead of adding artificial 1024-token padding. The 1024 default is a quality floor that can cost VRAM on T5 models, so if you're running tight, drop it.

Where it sits

In a Pony v7 workflow, this replaces the encoder chain: text → balancer → (optionally the sculpt variant below) → sampler. The README notes both equal-length nodes keep target = 1024 as their default and that on low-memory systems target = 0 is the move.

Installing it

Same pack install as everything else:

cd ComfyUI/custom_nodes
git clone https://github.com/OnekoSL/Nukun_ComfyUI_Nodes.git

Restart ComfyUI, or use Manager (search "Nukun"). No extra dependencies - it works with whatever CLIP you connect.

Common issues

If positive_raw_tokens and effective_target come out identical while target is higher, your prompt is just longer than 1024 - the balancer honors the long prompt, which is the intended behavior, not a bug. If you're seeing out-of-memory on T5 models, the 1024 default padding is the usual culprit; target = 0 is the sanctioned fix. And note this node does not touch the embeddings - if you want the optional embedding-level sculpting on top, that's the sibling T5 Sculpt Equal-Length Prompt Balancer. Start here, add sculpting only if you have a reason.

CategoryNukun/Conditioning

Inputs (4)

NameTypeDefaultDescription
tokenizerCLIPThe loaded T5/Qwen tokenizer to use.
targetINT10240–4096Minimum shared token length for positive and negative prompts.
positiveSTRING
negativeSTRING

Outputs (6)

NameTypeDescription
positiveCONDITIONING
negativeCONDITIONING
positive_raw_tokensINT
negative_raw_tokensINT
effective_targetINT
reportSTRING