fix: deduplicate timesteps in DPMSolverMultistepScheduler to prevent IndexError#13239
Open
Chase-Xuu wants to merge 1 commit intohuggingface:mainfrom
Open
fix: deduplicate timesteps in DPMSolverMultistepScheduler to prevent IndexError#13239Chase-Xuu wants to merge 1 commit intohuggingface:mainfrom
Chase-Xuu wants to merge 1 commit intohuggingface:mainfrom
Conversation
…IndexError When using `beta_schedule='squaredcos_cap_v2'` with `use_karras_sigmas=True`, the sigma-to-timestep mapping produces many nearly identical float values that collapse to the same integer timestep after rounding (e.g., 998.90, 998.80 both become 998). These duplicate timesteps cause the step_index counter to drift past the sigmas array, resulting in an IndexError at `self.sigmas[self.step_index + 1]`. Fix: - Round timesteps unconditionally (remove the squaredcos_cap_v2 exception) - Deduplicate timesteps after rounding, keeping only the first occurrence - Filter corresponding sigmas to match the deduplicated timesteps - Update num_inference_steps to reflect the actual number of unique steps This mirrors the existing deduplication logic in DPMSolverMultistepInverseScheduler. Fixes huggingface#12771
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #12771 —
DPMSolverMultistepSchedulercrashes withIndexError: index N is out of boundswhen usingbeta_schedule='squaredcos_cap_v2'withuse_karras_sigmas=True(oruse_lu_lambdas=True).Root cause
With the cosine (
squaredcos_cap_v2) noise schedule, the sigma-to-timestep mapping (_sigma_to_t) produces many nearly identical float values near the end of the schedule (e.g., 998.90, 998.80, 998.70...) that collapse to the same integer timestep (998) after casting to int64. The current code intentionally skips rounding for cosine schedules, but this only defers the problem — values like 998.9 and 998.8 still become 998 when converted to int64.These duplicate timesteps cause
index_for_timestepto return incorrect indices, makingstep_indexdrift past thesigmasarray bounds, crashing atself.sigmas[self.step_index + 1].Fix
squaredcos_cap_v2exception for karras/lu sigma paths, since rounding is now handled centrallynum_inference_stepsto reflect the actual number of unique stepsThis mirrors the existing deduplication logic already present in
DPMSolverMultistepInverseScheduler(lines 358-359).Test results
squaredcos_cap_v2+use_karras_sigmas(20 steps)squaredcos_cap_v2+use_lu_lambdas(20 steps)linear+use_karras_sigmas(20 steps)Who can review?
@yiyixuxu (who engaged with the original issue)