fix(qwen): fix CFG failing when passing neg prompt embeds with none mask#13379
Open
Sunhill666 wants to merge 2 commits intohuggingface:mainfrom
Open
fix(qwen): fix CFG failing when passing neg prompt embeds with none mask#13379Sunhill666 wants to merge 2 commits intohuggingface:mainfrom
Sunhill666 wants to merge 2 commits intohuggingface:mainfrom
Conversation
Member
|
@claude can you review this? |
Contributor
|
I'll analyze this and get back to you. |
Member
|
thanks! @sayakpaul should we add a test for this? |
asomoza
approved these changes
Apr 2, 2026
Member
|
Yes there should be a test for it sure. I think this PR could handle it too. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What does this PR do?
Fixes #13377
This PR fixes a bug in
QwenImagePipelineandQwenImageEditPipelinewhere Classifier-Free Guidance (CFG) is incorrectly disabled when users manually passnegative_prompt_embedsalongside aNonemask.Root cause:
The
encode_promptmethod naturally optimizes an all-onesprompt_embeds_maskby converting and returning it asNone. However, thehas_neg_promptcondition in the__call__method strictly requirednegative_prompt_embeds_mask is not Noneto activate CFG. This logical mismatch causeddo_true_cfgto evaluate toFalseeven when valid negative embeddings were provided.Changes:
has_neg_promptcondition.has_neg_prompttoTrueas long asnegative_prompt_embeds is not None, since aNonemask simply implies that no padding/masking is required.Before submitting
QwenImagePipelinesilently disables CFG when passingnegative_prompt_embedsif mask isNone(whichencode_promptreturns by default) #13377.documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@asomoza @yiyixuxu