-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
IndexError on num_inference_steps values: 3, 9, 27, ...? #444
Comments
I believe this is the issue well summarized in this comment. The original bug comes from the
Note how the number of steps is not The same off-by-1 issue is present in
The expected number of steps is 4, and not 5. Sidenote: it is a bit confusing that |
A loosely related question: why do we need the diffusers/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py Lines 220 to 223 in 5adb0a7
And it's not clear from the docs :D
|
I am sorry for opening duplicate report. Did not see that. I made a search for "num_inference_steps", not for "ddim_steps". But searching now for "num_inference_steps" also does not show this thread. |
@sausix the issue I referenced is in another repository, so it's all good :) |
Thanks for all the details on this, I'm going to take a look. |
@jonatanklosko I wrote the scheduler docs and saw the offset parameter in multiple schedulers. When I worked on them more it wasn't there, so I need to do more reading before writing accurate docs, so I'll look at this too (maybe we should make another issue for it, depending on how fast all these can be solved). |
Okay, I've tracked down what You can see where it is used in diffusers with this search (the stable diffusion pipelines). This is matching the stable diffusion implementation here (with a weird comment from the authors). Now for the harder one, checking the index error. I remember encountering this in the past, I'll likely add a test to the schedulers to cover this. |
@natolambert yeah, my confusion was mostly that in the original implementation it is set to 1 and same in the stable diffusion pipeline, so I wondered if Interestingly in CompVis/latent-diffusion they also use offset of 1 (ref), which is not the case in the latent diffusion pipeline (ref), not sure if that's expected or not. Another possible inconsistency I found is this: diffusers/src/diffusers/schedulers/scheduling_pndm.py Lines 338 to 339 in 8eaaa54
diffusers/src/diffusers/schedulers/scheduling_ddim.py Lines 204 to 205 in 8eaaa54
It's equivalent for |
Yeah I just realized the 1 vs |
@patrickvonplaten @patil-suraj, I'm not sure about the discrepancy @jonatanklosko brings up above with the indexing and offset. I vaguely remember there being some of the PNDM tests failing a while back confusing people. Maybe it was because this change was introduced? I'll keep looking a bit. |
@jonatanklosko I can tell you that the
And
Though I'm not sure why |
@natolambert sure I will! I'm also looking through openai/glide-text2im and I'm almost sure they don't use the 1 offset there, so maybe that's the reason for making it configurable. |
I opened #465 to keep this on track about the indexing error / confusion. |
@natolambert perfect, thank you! |
Okay, looks good to me, will close this issue as we will merge #466 shortly. >>> res = pipe("a photo of an astronaut riding a horse on mars", num_inference_steps=3, guidance_scale=7.5)
100%|██████████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:08<00:00, 2.02s/it]
>>> res = pipe("a photo of an astronaut riding a horse on mars", num_inference_steps=5, guidance_scale=7.5)
100%|██████████████████████████████████████████████████████████████████████████████████████████| 6/6 [00:08<00:00, 1.36s/it]
>>> res = pipe("a photo of an astronaut riding a horse on mars", num_inference_steps=6, guidance_scale=7.5)
100%|██████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:09<00:00, 1.40s/it]
>>> res = pipe("a photo of an astronaut riding a horse on mars", num_inference_steps=7, guidance_scale=7.5)
100%|██████████████████████████████████████████████████████████████████████████████████████████| 8/8 [00:11<00:00, 1.44s/it]
>>> res = pipe("a photo of an astronaut riding a horse on mars", num_inference_steps=9, guidance_scale=7.5)
100%|█████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:14<00:00, 1.48s/it] |
@natolambert Thank for fixing quickly. |
The offsetting is very specific to latnet/stable diffusion model, it's not used by other models like the original ddpm models. |
@patil-suraj I'm happy to send a PR, but it seems to me that |
Let's close the issue only when the PR is in main :-) |
Describe the bug
Some
num_inference_steps
values seem to be "problematic" and throw an IndexError.Also the iteration status output does not end on that value in any relation. If it's on purpose, it's still confusing:
num_inference_steps: 5
6it [00:49, 8.27s/it]
num_inference_steps: 6
8it [01:02, 7.87s/it]
num_inference_steps: 7
9it [01:10, 7.88s/it]
num_inference_steps: 8
9it [01:13, 8.19s/it]
Reproduction
Tested on command line too. Unrelated to PyCharm environment.
Logs
System Info
diffusers
version: 0.4.0.dev0The text was updated successfully, but these errors were encountered: