Skip to content

[Batched Generators] This PR adds generators that are useful to make batched generation fully reproducible #1718

Merged
patrickvonplaten merged 23 commits into
mainfrom
allow_batched_generators
Dec 17, 2022
Merged

[Batched Generators] This PR adds generators that are useful to make batched generation fully reproducible #1718
patrickvonplaten merged 23 commits into
mainfrom
allow_batched_generators

Conversation

@patrickvonplaten

@patrickvonplaten patrickvonplaten commented Dec 15, 2022

Copy link
Copy Markdown
Contributor

This PR adds two nice features:

  • Test that verifies that batched output and single output is identical
  • Adds a nice doc page explaining how "batched" generators can be used for nice prompt engineering

@HuggingFaceDocBuilderDev

HuggingFaceDocBuilderDev commented Dec 15, 2022

Copy link
Copy Markdown

The documentation is not available anymore as the PR was closed or merged.

@patrickvonplaten patrickvonplaten changed the title [Batched Generators] all batched generators [Batched Generators] This PR adds generators that are useful to make batched generation fully reproducible Dec 16, 2022
@patrickvonplaten

Copy link
Copy Markdown
Contributor Author

Tests are flaky I think.

Comment thread src/diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py Outdated

@anton-l anton-l left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Not sure about updating the types and docs for incompatible pipelines like DDPM and K-Diffusion though, but depends on how quickly we add the feature there afterwards :)

@pcuenca pcuenca left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be very useful, thanks a lot!

Comment thread docs/source/using-diffusers/reusing_seeds.mdx Outdated
Comment thread docs/source/using-diffusers/reusing_seeds.mdx Outdated
Comment thread docs/source/using-diffusers/reusing_seeds.mdx Outdated
>>> images
```

![img](https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/reusabe_seeds.jpg)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, that doesn't look like the style of Vermeer! Was he removed from the training set of 1.5? (Nothing to change here, just a comment; I was curious about the double eyes).

Comment thread docs/source/using-diffusers/reusing_seeds.mdx Outdated
Comment thread src/diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py Outdated
Comment on lines +237 to +238
# TODO(Pedro) - not sure why, but not at all reproducible at the moment it seems
# make sure that batched and non-batched is identical

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is possibly because of pytorch/pytorch#84039 (comment). We can't really support more than 1 image on mps yet.

patrickvonplaten and others added 2 commits December 17, 2022 11:02
Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
@patrickvonplaten patrickvonplaten merged commit c53a850 into main Dec 17, 2022
@patrickvonplaten patrickvonplaten deleted the allow_batched_generators branch December 17, 2022 10:13
sliard pushed a commit to sliard/diffusers that referenced this pull request Dec 21, 2022
…batched generation fully reproducible (huggingface#1718)

* [Batched Generators] all batched generators

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* hey

* up again

* fix tests

* Apply suggestions from code review

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>

* correct tests

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
@xiankgx

xiankgx commented Dec 21, 2022

Copy link
Copy Markdown

For a batched generation, how do I use the generator?

I passed in a list of generators (same length as the number of images per prompt) with the same manual seed number but the first image differs from the other images (other images 2, 3, 4 are the same) in a batch?

If I put in just one generator, then all the images in the batch are different. But using the same seed results in the same batch of images.

How do I do per image seed? Say if I use seed 42, 42, 42, 42 I expect all the images returned are the same image.


More findings, it seems that txt2img pipeline is fine but not img2img. This is Stable Diffusion btw.

@patrickvonplaten

Copy link
Copy Markdown
Contributor Author

Hey @xiankgx,

Could you please open a new issue with a reproducible code snippet?

@kylemcdonald

Copy link
Copy Markdown

@xiankgx @patrickvonplaten i monkeypatched it with this solution https://gist.github.com/kylemcdonald/208987e0b6c562886ae2cf42fb5fb743

use it like this:

from fixed_noise import fix_noise
...
fix_noise(pipe)

this will use the same random noise for all images in the batch.

yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
…batched generation fully reproducible (huggingface#1718)

* [Batched Generators] all batched generators

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* up

* hey

* up again

* fix tests

* Apply suggestions from code review

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>

* correct tests

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Latents / seeds are a mess. Make it easier to replicate a generated image using a seed.

6 participants