-
Notifications
You must be signed in to change notification settings - Fork 6.5k
fix a bug in 2nd order schedulers when using in ensemble of experts config #5511
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
Changes from all commits
4b1e7d2
8ea162b
5a0ac58
443aa6b
de85e0b
ceb0f45
62a9b6e
a424a3f
ea590b8
2b959df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -867,8 +867,20 @@ def get_timesteps(self, num_inference_steps, strength, device, denoising_start=N | |
| - (denoising_start * self.scheduler.config.num_train_timesteps) | ||
| ) | ||
| ) | ||
| timesteps = list(filter(lambda ts: ts < discrete_timestep_cutoff, timesteps)) | ||
| return torch.tensor(timesteps), len(timesteps) | ||
|
|
||
| num_inference_steps = (timesteps < discrete_timestep_cutoff).sum().item() | ||
| if self.scheduler.order == 2: | ||
| # if the scheduler is a 2nd order scheduler we ALWAYS have to do +1 | ||
| # because `num_inference_steps` will always be even given that every timestep | ||
| # (except the highest one) is duplicated. If `num_inference_steps` is even it would | ||
| # mean that we cut the timesteps in the middle of the denoising step | ||
| # (between 1st and 2nd devirative) which leads to incorrect results. By adding 1 | ||
| # we ensure that the denoising process always ends after the 2nd derivate step of the scheduler | ||
| num_inference_steps = num_inference_steps + 1 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think sched = SCHEDULERS["DPM2"]
sched.set_timesteps(25)
denoising_start = 0.6
discrete_timestep_cutoff = int(
round(
sched.config.num_train_timesteps
- (denoising_start * sched.config.num_train_timesteps)
)
)
num_inference_steps = (sched.timesteps < discrete_timestep_cutoff).sum().item()
print(num_inference_steps)This prints 20. For denoising_start=0.5, it prints 25. So I think we should add 1 to it only if it's even, and not if it's odd. No?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah DPM2 can actually be different indeed if it interpolates, (Heun can't) Nice catch! I'll open a PR to fix it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @patrickvonplaten, all testcases I threw at it now produce good images. I am just curious why we don't need to do any logic in the base step (where denoising_end is supplied to the base SDXL pipeline without img2img) since I would expect that we would want to ensure that the final timestep there is a second order timestep, and as far as I can tell it still has the odd/even issue when splitting. Maybe I am wrong! In any case, latest |
||
|
|
||
| # because t_n+1 >= t_n, we slice the timesteps starting from the end | ||
| timesteps = timesteps[-num_inference_steps:] | ||
| return timesteps, num_inference_steps | ||
|
|
||
| return timesteps, num_inference_steps - t_start | ||
|
|
||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.