Skip to content

[schedulers] fix RecursionError in CosineDPMSolverMultistepScheduler#13754

Open
zxuhan wants to merge 1 commit into
huggingface:mainfrom
zxuhan:fix/cosine-dpm-brownian-bounds-13274
Open

[schedulers] fix RecursionError in CosineDPMSolverMultistepScheduler#13754
zxuhan wants to merge 1 commit into
huggingface:mainfrom
zxuhan:fix/cosine-dpm-brownian-bounds-13274

Conversation

@zxuhan
Copy link
Copy Markdown

@zxuhan zxuhan commented May 14, 2026

What does this PR do?

Fixes #13274.

CosineDPMSolverMultistepScheduler.step constructs BrownianTreeNoiseSampler with the config bounds (sigma_min, sigma_max), but the sampler is then queried with the discretized schedule in self.sigmas, which drifts outside those bounds at both ends:

  • The Karras/exponential reconstruction of the endpoints in fp32 lands a few ULPs off. For example with sigma_max=500 on the exponential schedule, self.sigmas[0] is 500.00006103515625. The first query violates torchsde's tb <= t1 check.
  • With the default final_sigmas_type="zero" the last query has sigma_next == 0, which is strictly below config.sigma_min. That violates ta >= t0.

torchsde reacts to either by recursively splitting its backing interval until Python's recursion limit is hit, producing the RecursionError: maximum recursion depth exceeded reported for stabilityai/stable-audio-open-1.0 in #13274.

This PR switches the Brownian bounds to the actual extrema of self.sigmas, matching the pattern already used in scheduling_dpmsolver_sde.py. After the change the sampler is always constructed over an interval that encloses every query issued during sampling.

A new regression test in tests/schedulers/test_scheduler_cosine_dpmsolver_multistep.py exercises both Karras and exponential schedules with final_sigmas_type="zero". Without the fix the exponential subtest reproduces the RecursionError; with the fix both subtests pass.

Before submitting

Who can review?

@yiyixuxu @sayakpaul

`CosineDPMSolverMultistepScheduler.step` initialised `BrownianTreeNoiseSampler`
with `sigma_min`/`sigma_max` from the config, but the sampler is queried with
`self.sigmas[step_index]` values that drift outside those bounds: the
Karras/exponential reconstruction of the endpoints in fp32 lands a few ULPs
off, and `final_sigmas_type="zero"` makes the last `sigmas` entry strictly
below `config.sigma_min`. Out-of-range queries push torchsde into unbounded
recursive interval splitting and trip Python's recursion limit (huggingface#13274).

Initialise the sampler with the actual `self.sigmas` extrema instead, matching
the pattern in `scheduling_dpmsolver_sde.py`. Adds a regression test covering
both Karras and exponential schedules with `final_sigmas_type="zero"`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][AMD] stabilityai/stable-audio-open-1.0 encounter RecursionError: maximum recursion depth exceeded

1 participant