diffusers
diffusers copied to clipboard
Fix duplicate timesteps in DPMSolverMultistepScheduler with sigma conversion methods
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_v2schedule - 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
- Added
_ensure_unique_timesteps()helper method to handle duplicate timesteps consistently - Updated all sigma conversion methods to unconditionally round timesteps
- Applied duplicate detection and removal to:
use_karras_sigmasuse_lu_lambdasuse_exponential_sigmasuse_beta_sigmas
- 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