-
Couldn't load subscription status.
- Fork 6.4k
Fixed noise_pred_text referenced before assignment. #9537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…n using PAG with guidance scale and guidance rescale at the same time.
|
Thanks for your PR, could you provide a reproducible snippet that raises the error? |
|
I am also going to cc @sunovivid (PAG first author) to brainstorm if allowing guidance rescale with PAG + guidance scale makes sense. |
import torch
import diffusers
pipeline = diffusers.AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.bfloat16, enable_pag=True)
pipeline.to("cuda")
pipeline(
prompt="test",
guidance_scale=5,
guidance_rescale=0.5,
pag_scale=3,
num_inference_steps=35,
)produces the below error |
|
same issue reported here #9220 fix looks good to me! |
|
can you run |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
Thank you for the contributions and experiments!
It looks reasonable to use guidance rescale with PAG + guidance scale. Noise rescale modifies the scale of the 'guided' prediction to the original text-conditioned prediction to cut off extra scale from guidance extrapolation. So rescaling PAG + CFG guided prediction to the original prediction looks reasonable. After the cut-off, the noise rescale function mixes the rescaled noise with the original 'text' prediction. It seems also reasonable because our main component is 'text' prediction, both in CFG and PAG. I think it is a very good fix! cc @sayakpaul |
|
The style is fixed now. |
| noise_pred_text, noise_pred_perturb = noise_pred.chunk(2) | ||
| noise_pred = noise_pred_text + pag_scale * (noise_pred_text - noise_pred_perturb) | ||
| return noise_pred | ||
| return noise_pred, noise_pred_text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like we broke the tests; I looked up the import of PAGMixin on github, not many but some so let's try to not making a breaking change here
we can add a argument return_pred_text; default to False but set True when calling from our pipelines.
|
Should be fixed now. |
|
@LagPixelLOL merged! thanks for your PR! |
* Fixed local variable noise_pred_text referenced before assignment when using PAG with guidance scale and guidance rescale at the same time. * Fixed style. * Made returning text pred noise an argument.
* Fixed local variable noise_pred_text referenced before assignment when using PAG with guidance scale and guidance rescale at the same time. * Fixed style. * Made returning text pred noise an argument.
Fixed local variable noise_pred_text referenced before assignment when using PAG with guidance scale and guidance rescale at the same time.
@yiyixuxu @asomoza
I'm not sure if allowing guidance rescale with PAG + guidance scale is actually a thing, but from my tests it does work with PAG + guidance scale. If it's not allowed then it can be fixed with adding a condition or raising an error when all PAG scale, guidance scale, and guidance rescale are passed at the same time.
Before this fix it currently does raise an error when passing all 3 at the same time, but it's an unbounded local variable error, which is extremely confusing.