Fix clip_skip being ignored for negative prompt embeddings in SDXL pipelines#13973
Open
Dev-X25874 wants to merge 4 commits into
Open
Fix clip_skip being ignored for negative prompt embeddings in SDXL pipelines#13973Dev-X25874 wants to merge 4 commits into
Dev-X25874 wants to merge 4 commits into
Conversation
…eds in encode_prompt
…eds in img2img encode_prompt
…eds in inpaint encode_prompt
Contributor
|
Hi @Dev-X25874, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. |
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?
clip_skipwas silently ignored when computing negative prompt embeddingsin all three SDXL
encode_promptmethods. The positive prompt pathcorrectly branches on
clip_skip:but the negative prompt path unconditionally used
hidden_states[-2]regardless of the
clip_skipvalue. This means that wheneverclip_skipis set, positive and negative embeddings are extracted from different hidden
layers, breaking the symmetry that classifier-free guidance relies on.
Fixed by mirroring the existing conditional to the negative path in:
pipeline_stable_diffusion_xl.pypipeline_stable_diffusion_xl_img2img.pypipeline_stable_diffusion_xl_inpaint.pyA test is added to
test_stable_diffusion_xl.pythat callsencode_promptwith
clip_skip=1vsclip_skip=Noneand asserts that negative embeddingsdiffer between the two calls (i.e. clip_skip now actually affects them).
Fixes # (issue)
Before submitting
.ai/review-rules.md?documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@yiyixuxu @asomoza