Skip to content

fix(qwen): fix CFG failing when passing neg prompt embeds with none mask#13379

Open
Sunhill666 wants to merge 2 commits intohuggingface:mainfrom
Sunhill666:fix/qwen-image-cfg-mask
Open

fix(qwen): fix CFG failing when passing neg prompt embeds with none mask#13379
Sunhill666 wants to merge 2 commits intohuggingface:mainfrom
Sunhill666:fix/qwen-image-cfg-mask

Conversation

@Sunhill666
Copy link
Copy Markdown

What does this PR do?

Fixes #13377

This PR fixes a bug in QwenImagePipeline and QwenImageEditPipeline where Classifier-Free Guidance (CFG) is incorrectly disabled when users manually pass negative_prompt_embeds alongside a None mask.

Root cause:
The encode_prompt method naturally optimizes an all-ones prompt_embeds_mask by converting and returning it as None. However, the has_neg_prompt condition in the __call__ method strictly required negative_prompt_embeds_mask is not None to activate CFG. This logical mismatch caused do_true_cfg to evaluate to False even when valid negative embeddings were provided.

Changes:

  • Relaxed the has_neg_prompt condition.
  • It now correctly evaluates has_neg_prompt to True as long as negative_prompt_embeds is not None, since a None mask simply implies that no padding/masking is required.

Before submitting

Who can review?

@asomoza @yiyixuxu

@asomoza
Copy link
Copy Markdown
Member

asomoza commented Apr 2, 2026

@claude can you review this?

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Claude Code is working…

I'll analyze this and get back to you.

View job run

@asomoza
Copy link
Copy Markdown
Member

asomoza commented Apr 2, 2026

thanks! @sayakpaul should we add a test for this?

@sayakpaul
Copy link
Copy Markdown
Member

Yes there should be a test for it sure. I think this PR could handle it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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)

3 participants