-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Same seed produces different results #1339
Comments
@thisislance98 looking at your code example it appears your not passing the seed information as latents to the pipe. Here is some information that should get you generating images using set seeds. Stable Diffusion with Repeatable Seeds (excerpt below) Latents Generation Latents are the initial random Gaussian noise that gets transformed to actual images during the diffusion process. To generate them, we'll use a different random seed for each latent, and we'll save them so we can reuse them later.
|
I can confirm that I have the same problem if using torch.bfloat16. The results are similar but different is details. I.E. the same lady in the same position but sometimes smiling, sometimes not. Or one time looking to the left, another time to the right. If using torch.float16 same seeds = same results. Also I am using the Euler(A) scheduler. |
@Marcophono2 can you share the code you are using to generate the image? |
maybe second pipe missing generator = torch.Generator(device="cuda").manual_seed(87)
display(pipe.text2img(prompt, negative_prompt=neg_prompt, width=512,height=512,max_embeddings_multiples=3, generator=generator).images[0])
generator = torch.Generator(device="cuda").manual_seed(87)
display(pipe.text2img(prompt, negative_prompt=neg_prompt, width=512,height=512,max_embeddings_multiples=3).images[0]) |
@averad I tried just the same latents in to text2img and am still getting different results https://colab.research.google.com/drive/1ypHAf2TBWnvxkLJf08cSMko3r48WYNYn?usp=sharing feel free to update the colab if you can get it to work |
@thisislance98 try for _ in range(2):
# Get a new random seed, store it and use it as the generator state
seed = 23 #generator.seed()
seeds.append(seed)
generator = torch.cuda.manual_seed_all(seed)
image_latents = torch.randn(
(1, pipe.unet.in_channels, height // 8, width // 8),
generator = generator,
device = device
)
# latents = image_latents if latents is None else torch.cat((latents, image_latents))
# image_latents = image_latents.half()
display(pipe.text2img(prompt, negative_prompt=neg_prompt,latents=image_latents, width=512,height=512,max_embeddings_multiples=3, num_inference_steps=steps).images[0]) |
Sure, @averad .
|
I made some more tests and could take notice that the differences decrease with increasing number of steps. That is surprising. I would have awaited a multiplication of the differences with every step. The very noisy image after step 1 is identical. But starting from step 2 there are differences. But after 250 steps there is only a very, very small difference in general noising left. But only if you switch between two different images at the same position. |
That's very interesting! @Marcophono2, are you running the code always on the same device, same hardware, etc...? |
Yes, @patrickvonplaten. |
lpw_stable_diffusion needs lots of updates |
I have just noticed that I am getting non-deterministic results too with EulerAncestral and enforcing all RNG to happen on the CPU (see #1514). The interesting thing is, results deterministic if I call |
BTW, this PR should help with this here a bit: #1718 |
I can confirm that I tried passing a list of generators using the new method described in PR #1718 but it didn't work Only solution was to disable xformers. Note that this will affect the performance
|
Hi, https://gist.github.com/takuma104/9d25bb87ae3b52e41e0132aa737c0b03 |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
Describe the bug
Basically is you set the scheduler to EulerAncestralDiscreteScheduler and the custom pipeline to lpw_stable_diffusion you will get different images when you generate
Reproduction
Here is a colab to reproduce the results
https://colab.research.google.com/drive/1ypHAf2TBWnvxkLJf08cSMko3r48WYNYn?usp=sharing
Logs
No response
System Info
I'm using colab with standard gpu
The text was updated successfully, but these errors were encountered: