Nodes/ComfyUI-gen2/Gen2 QwenImage Text Encode (outdated)
ComfyUI Node

Gen2 QwenImage Text Encode (outdated)

VideoX's exact prompt encoding, not ComfyUI's

By petmycat·Created 7 months ago·Updated 12 days ago· 23
Gen2 QwenImage Text Encode (outdated)
  • clip
  • conditioning
text
max_sequence_length512
embeds_dtypeauto

In the (outdated) QwenImage section of this pack, you don't use ComfyUI's CLIPTextEncode. This node exists because VideoX-Fun's QwenImage pipeline encodes text in a specific way that differs from ComfyUI's default in three concrete ways, and if you want bit-compatible output with VideoX's diffusers results, you need those exact differences. The README says it plainly: this is "VideoX-style text encoding (use instead of CLIPTextEncode)".

What's different from CLIPTextEncode

  1. Its own tokenizer. It loads a HuggingFace Qwen2 tokenizer from ComfyUI/models/gen2/qwen_2512_tokenizer/ rather than ComfyUI's wrapped version. There's a fallback to Qwen/Qwen2-VL-7B-Instruct from HuggingFace if the local folder is missing, but you're meant to place the Qwen-Image-2512 tokenizer where the code expects it.
  2. VideoX's exact prompt template. Your text is wrapped in the system/user/assistant template that QwenImage was trained with, and the fixed drop_idx = 34 template tokens are stripped from the embeddings afterward. This is fixed, not dynamically calculated like ComfyUI does.
  3. No fixed padding. The output embeddings use the actual token length of the batch - padded only to the max in-batch length - rather than a padded sequence. That matters downstream because the sampler keys its attention masks off these lengths.

Inputs

  • clip - a CLIP model (from a normal Load CLIP or checkpoint loader). It drives the underlying text encoder.
  • text - your prompt (multiline).
  • max_sequence_length - truncation cap, default 512 (64–4096, step 64). The tooltip notes VideoX's default is 1024; if you're reproducing VideoX results, set this to match what your reference run used.
  • embeds_dtype - auto (default), fp16, or bf16. auto infers from the text encoder's dtype.

Output: conditioning of type GEN2_CONDITIONING - a dict with the embeds, attention mask, and per-sequence token lengths. It feeds the Gen2 QwenImage Control Sampler's positive/negative inputs, and it won't wire into stock samplers (the types are deliberately pack-specific).

Installation

The full QwenImage stack: VideoX-Fun as a custom node, diffusers + transformers in your environment, and the Qwen-Image-2512 tokenizer placed in ComfyUI/models/gen2/qwen_2512_tokenizer/. Pack install via ComfyUI Manager (search "ComfyUI-gen2"), or:

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

Common issues

  • "Failed to load tokenizer" error. The local models/gen2/qwen_2512_tokenizer folder isn't there and the HuggingFace fallback failed (no network, or the repo name changed). Download the Qwen-Image-2512 tokenizer into that path and restart.
  • clip is None / "clip input is invalid". You need a real CLIP - the node reads the underlying text encoder from it. In the intended workflow it's a QwenImage CLIP.
  • Output won't connect to anything. GEN2_CONDITIONING is pack-specific. Wire it to this pack's sampler, not a stock KSampler.

Reality check: this node only matters if you're running the outdated VideoX-compatible pipeline. For modern QwenImage editing, ComfyUI's native text encoding handles the model fine - the "exact VideoX process" here is about reproducibility with a specific reference implementation, not about being strictly better.

CategoryGen2/QwenImage

Inputs (4)

NameTypeDefaultDescription
clipCLIP
textSTRINGThe text prompt to encode
max_sequence_lengthINT51264–4096Maximum sequence length (truncate if longer, VideoX default: 1024)
embeds_dtypeCOMBOauto3 options: auto, fp16, bf16

Outputs (1)

NameTypeDescription
conditioningGEN2_CONDITIONING