-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add an argument "negative_prompt" #549
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
The documentation is not available anymore as the PR was closed or merged. |
Super useful against extra arms and wonky hands. Thanks for sharing this! |
That's great! Some remarks:
|
@leszekhanusz Thank you for the comments! I fixed them. |
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_onnx.py
Outdated
Show resolved
Hide resolved
@leszekhanusz Thank you! I forgot to make those changes. I fixed them. |
Super excited for this! |
@anton-l @patrickvonplaten Could you review this? |
I've been playing with this on Easy Diffusion and it's been working great, and generations so much better. This is definitely a needed feature. |
@shirayu, is there any guide to get this running in my local version while waiting for the update to main library ya? |
The easiest way is where your code downloads the git repo from huggingface to replace that with this branch from shirayu's fork. |
Is this related to Dream Booth cc @patil-suraj ? |
Schedulers no longer has a method |
Hi @WASasquatch! You are right, #651 should fix it. Sorry! |
This is generally applicable to all the stable diffusion classifier-free guidance pipelines. I don't think there's any particular connection to DreamBooth. |
I hope this gets added soon, so it doesn't have to be maintained so long while they do other stuff. You'd think it'd be pretty high on priority considering it's a masterful tool in prompt engineering. |
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_onnx.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_onnx.py
Outdated
Show resolved
Hide resolved
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.
Went through it again and it looks very nice! Thanks so much for working on this :-)
Added some suggestions to improve the error messages - would be nice if you could have a look and then potentially run make style
once if the test fails.
@patil-suraj @pcuenca - I agree with @shirayu that we should merge this soon |
Also we would need a test here, but I'm happy to take care of this when looking into: #551 |
…sion.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
…sion.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
…sion_inpaint.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
…sion_onnx.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
…sion_img2img.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
…sion_inpaint.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
…sion_onnx.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
@patrickvonplaten Thank you for your nice updates! |
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.
The code looks good, I just suggested minor nits. I haven't been able to test it yet, I'll do it later.
I have a question about how it works, though. Instead of using an empty prompt for the unconditioned generation we use the negative prompt, is that correct? Wouldn't this make those prompts appear for low values of guidance_scale
?
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_onnx.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_onnx.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_onnx.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_onnx.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py
Outdated
Show resolved
Hide resolved
@pcuenca Thank you for your suggestions. I update this PR. As far as I know, in almost all cases
Replacing blanks in unconditional generation is done in some applications like |
From #699: Shouldn't there be checks (printing a warning) for the maximum number of tokens in the negative prompt as well? |
Good suggestion! (Related to #472) |
I guess that's the tradeoff between separate pipelines which can easily be copied to create a own one and an architecture that can do much more but maybe harder to understand at first. In #699 and the Twitter poll it didn't look like there will be a unified pipeline soon. But maybe the tokenizing (with the warning when there are too many tokens) could be moved to a function (maybe even into one of the utility files?) so it can be reused for both prompts and in all the Pipelines. |
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.
Looks good to me, thanks a lot for working on this!
* Add an argument "negative_prompt" * Fix argument order * Fix to use TypeError instead of ValueError * Removed needless batch_size multiplying * Fix to multiply by batch_size * Add truncation=True for long negative prompt * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_onnx.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_onnx.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Fix styles * Renamed ucond_tokens to uncond_tokens * Added description about "negative_prompt" Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
* Add an argument "negative_prompt" * Fix argument order * Fix to use TypeError instead of ValueError * Removed needless batch_size multiplying * Fix to multiply by batch_size * Add truncation=True for long negative prompt * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_onnx.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_onnx.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Fix styles * Renamed ucond_tokens to uncond_tokens * Added description about "negative_prompt" Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
Add
negative_prompt
argument to customize unconditional input.Example
Bouquet of Roses
Bouquet of Roses (
negative_prompt
=red rose
)