Nodes/ComfyUI-QI-QwenEditSafe/Qwen Image Edit — Text Encoder (Safe) — by wallen0322
ComfyUI Node

Qwen Image Edit — Text Encoder (Safe) — by wallen0322

The Safe encoder that locks the grid

By wallen0322·Created 12 months ago·Updated 10 months ago· 56
Qwen Image Edit — Text Encoder (Safe) — by wallen0322
  • clip
  • image
  • vae
  • conditioning
  • image
  • latent
prompt
no_resize_padtrue
pad_modereflect
grid_multiple64
inject_modeboth
encode_fp32true
vl_max_pixels16777216
system_templateYou are a Prompt optimizer for image generation. Evaluate the user's input: if it requires expansion (e.g., due to vagueness, multiple characters without clear distinction, or missing details), enhance it by adding precise feature descriptions, using unique labels per character, ensuring visual distinctions, and including quality tags like "Ultra HD, 4K, cinematic lighting". If the input is already detailed and clear, output it verbatim. Keep enhanced prompts under 300 words.

Qwen-Image-Edit is the open editor everyone reached for in 2026, and it has one infamous flaw: it re-emits the whole frame instead of patching your image, so pixels nobody asked about move. The community named the symptom early - "the generated images often experience offset, which distorts the proportion of characters" - and the fix is basically always the same: control the input resolution. That's the entire reason this node exists. QI_TextEncodeQwenImageEdit_Safe is the general text-edit encoder from wallen0322's QI pack, and "Safe" means it letterboxes and grid-pads your input without resampling, so the geometry you feed in is the geometry you get back.

What it does and when you'd use it

It replaces the stock TextEncodeQwenImageEdit node in a Qwen-Edit workflow. Feed it your clip, prompt, image, and vae, and it hands you the conditioning, image, and latent triple that wires straight into a KSampler. In the context of the pack, this is the "explore and adjust parameters freely" encoder - the one you reach for when you want a text-guided edit (change the dress, remove the watermark, re-light the scene) and want to dial in exactly how hard the model sticks to your reference.

How it actually works

The mechanism is worth knowing because it's why the pack behaves differently from the stock node. It builds the Qwen chat template with Picture 1: vision placeholders, tokenizes it through the Qwen2.5-VL branch, then VAE-encodes the padded image and attaches two kinds of anchors to the conditioning:

  • reference_latents - the VAE-encoded padded image, injected early in the schedule to hold overall layout.
  • reference_pixels - low-pass, mid, and high-frequency versions of the image, injected at different timestep ranges. The high-frequency pass runs late and stops before the final steps, so it sharpens edges and hair without blocking the edit.

The pixel references come from the VAE reconstruction, not the raw image - same domain as what the sampler sees, which is what makes the colors stable. A prompt-optimizer system template gets injected into the Qwen2.5-VL tokenizer's system role, which is why a terse instruction like "make the red dress blue" still comes out well-detailed.

The inputs that matter

  • no_resize_pad (default on) - letterbox only, no resample. This is the "Safe" in the name. Leave it on; turning it off reintroduces the offset problem.
  • grid_multiple (default 64) - pads dimensions up to a multiple of this so the VAE gets clean shapes. 64 is right for Qwen; drop toward 8 if you're at a weird size.
  • inject_mode (both / latents / pixels) - both is the point of the pack. latents alone is lighter on VRAM but lets geometry drift more.
  • encode_fp32 (default on) - VAE in fp32. Costs a bit of VRAM, buys stability.
  • vl_max_pixels - cap on the image the CLIP-vision branch actually sees (default 16.7MP, auto-throttled). The VL branch doesn't need full res; it needs the subject, and the wrapper node in this pack is where you tune that.
  • system_template - the prompt-optimizer text. Clear it to disable.

Outputs: conditioning, image, latent. The latent carries a qi_pad dict with the crop metadata - pair this encoder with the pack's QI_VAEDecodeLockSize (not a stock VAEDecode) so the final image is cropped back to your original size.

Installing it

Through ComfyUI Manager: search ComfyUI-QI-QwenEditSafe and install. Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/wallen0322/ComfyUI-QI-QwenEditSafe

Restart ComfyUI. That's genuinely it - the pack's requirements.txt is empty and its install.py prints "nothing to install". No API, no keys, no extra Python deps; it's all torch plus ComfyUI's own nodes. What you do need is a Qwen-Image-Edit model. The 20B weights won't fit a consumer card at bf16, so grab a community GGUF quant (or use the Nunchaku INT4 loader the example workflow wires up) and a LoraLoaderModelOnly for your edit LoRA.

Gotchas

  • The README is a step behind the code: it mentions a prompt_emphasis knob and a QI_VAEDecodeHQ node, but the shipped encoder folded emphasis into an automatic schedule and the decoder is QI_VAEDecodeLockSize. Trust the node's actual inputs, not the doc.
  • For character work, the author suggests appending this to your prompt: 保持人物一致性不变,保持画风光影不变 ("keep the character consistent, keep the art style and lighting unchanged"). It genuinely helps.
  • If faces drift anyway, that's the model, not you - Qwen-Edit is weakest on real faces. Mask-and-crop or inpaint the face back rather than fighting the encoder.
CategoryQI by wallen0322

Inputs (11)

NameTypeDefaultDescription
clipCLIP
promptSTRING
imageIMAGE
vaeVAE
no_resize_padoptBOOLEANtrue
pad_modeoptCOMBOreflect2 options: reflect, replicate
grid_multipleoptINT648–128
inject_modeoptCOMBOboth3 options: both, latents, pixels
encode_fp32optBOOLEANtrue
vl_max_pixelsoptINT167772160–16777216
system_templateoptSTRINGYou are a Prompt optimizer for image generation. Evaluate the user's input: if it requires expansion (e.g., due to vagueness, multiple characters without clear distinction, or missing details), enhance it by adding precise feature descriptions, using unique labels per character, ensuring visual distinctions, and including quality tags like "Ultra HD, 4K, cinematic lighting". If the input is already detailed and clear, output it verbatim. Keep enhanced prompts under 300 words.

Outputs (3)

NameTypeDescription
conditioningCONDITIONING
imageIMAGE
latentLATENT