Skip to content

Commit

Permalink
[Schedulers] Fix 2nd order other than heun (huggingface#5526)
Browse files Browse the repository at this point in the history
* [Schedulers] Fix 2nd order other than heun

* Apply suggestions from code review
  • Loading branch information
patrickvonplaten authored Oct 25, 2023
1 parent ade7213 commit 4578cad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,9 +898,9 @@ def get_timesteps(self, num_inference_steps, strength, device, denoising_start=N
)

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
if self.scheduler.order == 2 and num_inference_steps % 2 == 0:
# if the scheduler is a 2nd order scheduler we might have to do +1
# because `num_inference_steps` might 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,9 @@ def get_timesteps(self, num_inference_steps, strength, device, denoising_start=N
)

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
if self.scheduler.order == 2 and num_inference_steps % 2 == 0:
# if the scheduler is a 2nd order scheduler we might have to do +1
# because `num_inference_steps` might 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,9 @@ def get_timesteps(self, num_inference_steps, strength, device, denoising_start=N
)

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
if self.scheduler.order == 2 and num_inference_steps % 2 == 0:
# if the scheduler is a 2nd order scheduler we might have to do +1
# because `num_inference_steps` might 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
Expand Down

0 comments on commit 4578cad

Please sign in to comment.