fix(qwen): fix CFG failing when passing neg prompt embeds with none mask#13379
fix(qwen): fix CFG failing when passing neg prompt embeds with none mask#13379sayakpaul merged 12 commits intohuggingface:mainfrom
Conversation
|
@claude can you review this? |
|
I'll analyze this and get back to you. |
|
thanks! @sayakpaul should we add a test for this? |
|
Yes there should be a test for it sure. I think this PR could handle it too. |
cc4ea27 to
dbe4f95
Compare
9645089 to
dbe4f95
Compare
|
@sayakpaul Thanks for the feedback! I completely agree. I've pushed two commit that addresses the issues and adds the requested tests:
Everything passes locally now. Let me know if there's anything else needed! |
ee1e84b to
7fa33ee
Compare
|
Hi @sayakpaul, Thanks for the very helpful feedback! I have updated the PR to address your comments. Here is a summary of the changes I just pushed:
Let me know if anything else needs adjusting! |
|
@claude could you do a review? |
|
Claude finished @sayakpaul's task in 2m 44s —— View job Review of PR #13379
SummaryThe core fix is correct: relaxing Issues Found1. Bug:
|
|
@sayakpaul I've addressed all the points:
|
| logger.warning( | ||
| "If `prompt_embeds` are provided, `prompt_embeds_mask` also have to be passed. Make sure to generate `prompt_embeds_mask` from the same text encoder that was used to generate `prompt_embeds`." | ||
| ) |
There was a problem hiding this comment.
| logger.warning( | |
| "If `prompt_embeds` are provided, `prompt_embeds_mask` also have to be passed. Make sure to generate `prompt_embeds_mask` from the same text encoder that was used to generate `prompt_embeds`." | |
| ) | |
| logger.warning( | |
| "`prompt_embeds` is provided and `prompt_embeds_mask` is not provided, so the model will treat all" | |
| " prompt tokens as valid. If `prompt_embeds` contains padding, you should provide the padding mask as" | |
| " `prompt_embeds_mask`. Make sure to generate `prompt_embeds_mask` from the same text encoder that was" | |
| " used to generate `prompt_embeds`." | |
| ) |
Not sure about the exact wording, but I think the warning here should explain when not passing the corresponding mask is valid, and when passing it is necessary.
| logger.warning( | ||
| "If `negative_prompt_embeds` are provided, `negative_prompt_embeds_mask` also have to be passed. Make sure to generate `negative_prompt_embeds_mask` from the same text encoder that was used to generate `negative_prompt_embeds`." | ||
| ) |
There was a problem hiding this comment.
| logger.warning( | |
| "If `negative_prompt_embeds` are provided, `negative_prompt_embeds_mask` also have to be passed. Make sure to generate `negative_prompt_embeds_mask` from the same text encoder that was used to generate `negative_prompt_embeds`." | |
| ) | |
| logger.warning( | |
| "`negative_prompt_embeds` is provided and `negative_prompt_embeds_mask` is not provided, so the model" | |
| " will treat all negative prompt tokens as valid. If `negative_prompt_embeds` contains padding, you" | |
| " should provide the padding mask as `negative_prompt_embeds_mask`. Make sure to generate" | |
| " `negative_prompt_embeds_mask` from the same text encoder that was used to generate" | |
| " `negative_prompt_embeds`." | |
| ) |
Analogous suggestion to #13379 (comment) for negative_prompt_embeds/negative_prompt_embeds_mask.
dg845
left a comment
There was a problem hiding this comment.
Thanks for the PR! Left some small suggestions :).
|
Hi @dg845, I've updated the warning messages for both |

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