Skip to content

Add support for negative prompts #699

Closed
@allo-

Description

@allo-

Is your feature request related to a problem? Please describe.
Some forks stable diffusion added support for negative prompts.

I tested this in the StableDiffusionPipeline and it seems to work that way with diffusers as well. I currently don't see a way to implement it without creating an own Pipeline, so it would be useful when it could be added to the official pipelines, so downstream projects can use it without an own pipeline class.

Describe the solution you'd like
The implementation from the link is straightforward. Add a negative_prompt variable to __call__ and change uncond_input

-                [""] * batch_size, padding="max_length", max_length=max_length, return_tensors="pt"
+                [negative_prompt] * batch_size, padding="max_length", max_length=max_length, return_tensors="pt"

I'd create a pull request, but I think a clean implementation should probably at least do the length check from text_embeddings as well and there may be other things I've overlooked, as I mostly added what is documented in the link.

Describe alternatives you've considered

  • For testing I created a copy of the Pipeline to use it in my code. It would be outdated when diffusers changes things. Subclassing it wouldn't be easy as the change is in the middle of a method.
  • Implementing it in the other two pipelines would probably be straightforward, but maybe this feature should wait for the UnifiedPipeline to avoid duplicate code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions