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
@Ricardo-M-L
Copy link
Copy Markdown
Author

Gentle bump — this is a small (+9/-9 across 9 QwenImage pipeline variants) correctness fix. encode_prompt() converts all-ones masks to None as an optimization, but has_neg_prompt still required mask to be non-None, so CFG silently turns off when callers pass pre-computed negative_prompt_embeds. Happy to rebase or split further if useful. Thanks for any review cycles.

@asomoza
Copy link
Copy Markdown
Member

asomoza commented Apr 17, 2026

thanks @Ricardo-M-L but this was already fixed with an earlier PR and the issue was closed with the merge.

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)

2 participants