diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

Fix duplicate timesteps in DPMSolverMultistepScheduler with sigma conversion methods

Open Aznix07 opened this issue 1 month ago • 0 comments

What does this PR do?

Fixes duplicate timesteps issue in DPMSolverMultistepScheduler when using various sigma conversion methods (Karras, Lu, exponential, beta) combined with beta_schedule="squaredcos_cap_v2".

Before this PR

  • Timesteps were not being rounded for squaredcos_cap_v2 schedule
  • This caused multiple sigma values to map to the same timestep
  • Example: timestep 998 appeared 9 times instead of once
  • Resulted in "index out of bounds" errors during sampling

After this PR

  • All sigma conversion methods now properly round timesteps
  • Duplicate timesteps are detected and removed
  • Users are warned when fewer unique timesteps are generated
  • Sampling completes without errors

Changes Made

  1. Added _ensure_unique_timesteps() helper method to handle duplicate timesteps consistently
  2. Updated all sigma conversion methods to unconditionally round timesteps
  3. Applied duplicate detection and removal to:
    • use_karras_sigmas
    • use_lu_lambdas
    • use_exponential_sigmas
    • use_beta_sigmas
  4. Added comprehensive test test_no_duplicate_timesteps_with_sigma_methods

Testing

✅ All 42 existing tests pass ✅ New test passes ✅ No regression detected ✅ Tested with multiple sigma methods and beta schedules

Fixes #12771

Before submitting

  • [x] Did you read the [contributor guideline]?
  • [x] Was this discussed/approved via a GitHub issue? https://github.com/huggingface/diffusers/issues/12771
  • [x] Did you write any new necessary tests?

Who can review?

@yiyixuxu

Aznix07 avatar Dec 04 '25 04:12 Aznix07