-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
DDIMScheduler (or DDPM) of StableDiffusion with 1000 num_inference_steps bugs out #10003
Comments
I think
Additionally you can go through tutorial here to improve quality of SD |
The scheduler config has diffusers/src/diffusers/schedulers/scheduling_ddim.py Lines 323 to 328 in 7ac6e28
from diffusers import DDIMScheduler
model_id = "CompVis/stable-diffusion-v1-4"
scheduler = DDIMScheduler.from_pretrained(model_id, subfolder="scheduler")
scheduler.set_timesteps(1000)
scheduler.timesteps
>>> tensor([1000, 999, ..., 2, 1])
timestep_spacing= from diffusers import DDIMScheduler
model_id = "CompVis/stable-diffusion-v1-4"
scheduler = DDIMScheduler.from_pretrained(model_id, subfolder="scheduler", steps_offset=0)
scheduler.set_timesteps(1000)
scheduler.timesteps
>>> tensor([999, 998, ..., 1, 0]) Most schedulers use default timestep_spacing= from diffusers import DDIMScheduler
model_id = "CompVis/stable-diffusion-v1-4"
scheduler = DDIMScheduler.from_pretrained(model_id, subfolder="scheduler", timestep_spacing="linspace")
scheduler.set_timesteps(1000)
scheduler.timesteps
>>> tensor([999, 998, ..., 1, 0]) DDIM explicitly doesn't support > 1000 steps, other schedulers don't have this check diffusers/src/diffusers/schedulers/scheduling_ddim.py Lines 306 to 311 in 7ac6e28
scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler", timestep_spacing="linspace")
scheduler.set_timesteps(1111)
scheduler.timesteps
>>> tensor([9.9900e+02, 9.9810e+02, 9.9720e+02, ..., 1.8000e+00, 9.0000e-01,
0.0000e+00]) Inference tested for a few steps: from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
model_id = "CompVis/stable-diffusion-v1-4"
scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler", timestep_spacing="linspace")
pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler)
pipe("an image of a cat", num_inference_steps=1111) There is a difference in casting for diffusers/src/diffusers/schedulers/scheduling_euler_discrete.py Lines 380 to 383 in 7ac6e28
DDIM diffusers/src/diffusers/schedulers/scheduling_ddim.py Lines 317 to 322 in 7ac6e28
Euler diffusers/src/diffusers/schedulers/scheduling_euler_discrete.py Lines 392 to 399 in 7ac6e28
DDIM diffusers/src/diffusers/schedulers/scheduling_ddim.py Lines 329 to 334 in 7ac6e28
|
@hlky Thanks for the detailed reply! However I'm still a bit confused what to actually do. diffusers/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py Lines 212 to 224 in 7ac6e28
@SahilCarterr Thank you for your comment, however |
@HilaManor Thanks for checking this! You're right looks like |
Cc: @yiyixuxu here. |
@hlky Thanks again for your comment. timestep_spacing="trailing" does solve this only for t=1000, however in my case I also sometimes need less steps, which then causes differences from leading: leading for 10 steps: tensor([901, 801, 701, 601, 501, 401, 301, 201, 101, 1], device='cuda:0')
trailing for 10 steps: tensor([999, 899, 799, 699, 599, 499, 399, 299, 199, 99], device='cuda:0') An interesting question is also is it expected for the last timestep to be 1 when setting less steps? I know that it calculates if noise should be added in the last step (and it doesn't in this case), however the t=1 denoiser shouldn't be expected to output x_0 directly theoretically. |
I think the following bug is related: Using "leading" leads to a constant tensor of 1000 values of 0.0413 with a trailing 0. "trailing" I think may be close to the expected behaviour? the reason is the timesteps vector- in leading it's just 0s, and in linspace the middle timestep is repeated |
Describe the bug
There's something going on with the set_timesteps offset parameters on Stable Diffusion (1v4). The timesteps are set from 1->1000 instead from 0, and so it tries to index out of bounds
Reproduction
gives
IndexError: index 1000 is out of bounds for dimension 0 with size 1000
because
scheduler.timesteps
gives:tensor([1000, 999, 998, 997, ..., 3, 2, 1], device='cuda:0')
instead of
tensor([999, 998, 997, ..., 3, 2, 1, 0], device='cuda:0')
Logs
No response
System Info
ste the text below in your GitHub issue and FILL OUT the two last points.
Who can help?
@yiyixuxu @asomoza @sayakpaul @DN6
The text was updated successfully, but these errors were encountered: