Skip to content

fix: QwenImage pipelines silently disable CFG with pre-computed negative_prompt_embeds#13449

Open
Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Ricardo-M-L:fix/qwenimage-cfg-negative-prompt-embeds
Open

fix: QwenImage pipelines silently disable CFG with pre-computed negative_prompt_embeds#13449
Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Ricardo-M-L:fix/qwenimage-cfg-negative-prompt-embeds

Conversation

@Ricardo-M-L
Copy link
Copy Markdown

Summary

  • Fix all 9 QwenImage pipeline variants where CFG is silently disabled when passing negative_prompt_embeds with None mask
  • encode_prompt() converts all-ones masks to None as an optimization (line 266-267), but has_neg_prompt required mask to be non-None — creating an inconsistency
  • Remove the and negative_prompt_embeds_mask is not None check so None mask means "all tokens valid"

Affected pipelines

  • pipeline_qwenimage.py
  • pipeline_qwenimage_img2img.py
  • pipeline_qwenimage_inpaint.py
  • pipeline_qwenimage_layered.py
  • pipeline_qwenimage_controlnet.py
  • pipeline_qwenimage_controlnet_inpaint.py
  • pipeline_qwenimage_edit.py
  • pipeline_qwenimage_edit_inpaint.py
  • pipeline_qwenimage_edit_plus.py

Test plan

  • Verified encode_prompt() converts all-ones mask to None (line 266-267)
  • Confirmed all 9 files updated consistently
  • No remaining instances of the old pattern in codebase

Fixes #13377

🤖 Generated with Claude Code

…beds mask is None

`encode_prompt()` optimizes all-ones masks to `None`, but `has_neg_prompt`
required both `negative_prompt_embeds` and `negative_prompt_embeds_mask` to
be non-None. This caused CFG to be silently skipped when users passed
pre-computed `negative_prompt_embeds` with an optimized `None` mask.

Remove the `negative_prompt_embeds_mask is not None` check from all 9
QwenImage pipeline variants so that a `None` mask correctly means
"all tokens valid" rather than "no negative prompt".

Fixes huggingface#13377

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added pipelines size/S PR with diff < 50 LOC labels Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pipelines size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] QwenImagePipeline silently disables CFG when passing negative_prompt_embeds if mask is None (which encode_prompt returns by default)

1 participant