[SDXL] Fix clip_skip not applied to negative prompt embeddings in encode_prompt#13796
[SDXL] Fix clip_skip not applied to negative prompt embeddings in encode_prompt#13796Dev-X25874 wants to merge 2 commits into
Conversation
5c489fb to
fdbad1e
Compare
|
you should AT LEAST provide examples |
|
@bghira Here's an example showing the bug and fix: |
|
please less AI slop comment replies, by example i mean generate images before and after with a clip skip specific model that will show the effect properly |
|
@bghira Here are the before/after outputs side by side, clip_skip=2, seed 42, SDXL base 1.0, same prompt both sides. Shadow artifact visible on the right is CFG corruption from the layer mismatch — gone on the left after the fix.
|
…eddings consistently
… positive and negative prompt embeddings
fdbad1e to
51b0be7
Compare
|
but clip_skip 2 is already applied by the vanilla diffusers SDXL code. when you say 2, you mean 4? |
|
also, SDXL uses zeroes for the negative embed, unlike SD1x which uses an encoded empty string. for most use cases that go for the defaults (no negative prompt) it would not have been noticed. you should try empty string as well for comparison. |
|
just curious are you using OpenClaw for all of this? your responses all look directly copy-pasted from the language model, even with the em-dashes and LLM-speak, "cleaner demo". |
|
@sayakpaul what's the Diffusers' project policy on autonomous agents doing things like this? |


What does this PR do?
In
StableDiffusionXLPipeline.encode_prompt, the positive prompt correctlyrespects
clip_skipwhen selecting the hidden layer:But the negative prompt path (line 473) always hardcodes
hidden_states[-2]regardless of
clip_skip:This means when a user passes
clip_skip=1(or any non-None value), thepositive and negative embeddings are extracted from different CLIP layers,
which corrupts classifier-free guidance since CFG subtracts the two vectors.
This PR fixes the negative prompt path to mirror the positive prompt logic
exactly, and adds a test that calls
encode_promptwithclip_skip=1andasserts the negative embeddings change accordingly.
Before submitting
Who can review?
@yiyixuxu @asomoza