Skip to content

DPMSolverMultistepScheduler out-of-bounds error when using beta_schedule="squaredcos_cap_v2" + use_karras_sigmas=True #12771

Description

@dylanzhao25

Describe the bug

Hi, I might be misunderstanding something here — I’m not very experienced with submitting issues to Diffusers yet, so please feel free to correct me if I’ve overlooked anything.

When using DPMSolverMultistepScheduler with the combination:

DPMSolverMultistepScheduler(
    beta_schedule="squaredcos_cap_v2",
    use_karras_sigmas=True,
)

calling set_timesteps(20) produces duplicate timesteps, which causes the multistep solver’s internal index tracking to drift, eventually leading to an index out of bounds error during sampling.

Reproduction

import diffusers
import torch
from diffusers import DPMSolverMultistepScheduler

print("Diffusers version:", diffusers.__version__)
print("Torch version:", torch.__version__)

scheduler = DPMSolverMultistepScheduler(
    beta_schedule="squaredcos_cap_v2",
    use_karras_sigmas=True,
)

scheduler.set_timesteps(20)

print("Timesteps:", scheduler.timesteps)

latents = torch.randn(1, 4, 64, 64)
noise_pred = torch.randn_like(latents)

for i, t in enumerate(scheduler.timesteps):
    print(f"Step {i}: t={t.item()}")
    try:
        result = scheduler.step(noise_pred, t, latents)
        latents = result.prev_sample
    except Exception as e:
        print(f"ERROR: {e}")
        break

Logs

Diffusers version: 0.35.2
Torch version: 2.9.0+cu128
Timesteps: tensor([998, 998, 998, 998, 998, 998, 998, 998, 998, 997, 996, 994, 989, 978,
        949, 867, 623, 221,  33,   0])
Step 0: t=998
Step 1: t=998
Step 2: t=998
Step 3: t=998
Step 4: t=998
Step 5: t=998
Step 6: t=998
Step 7: t=998
Step 8: t=998
Step 9: t=997
Step 10: t=996
Step 11: t=994
Step 12: t=989
Step 13: t=978
Step 14: t=949
Step 15: t=867
Step 16: t=623
Step 17: t=221
Step 18: t=33
Step 19: t=0
ERROR: index 21 is out of bounds for dimension 0 with size 21

System Info

  • 🤗 Diffusers version: 0.35.2
  • Platform: Linux-6.8.0-88-generic-x86_64-with-glibc2.39
  • Running on Google Colab?: No
  • Python version: 3.12.3
  • PyTorch version (GPU?): 2.9.0+cu128 (True)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Huggingface_hub version: 0.35.3
  • Transformers version: 4.57.1
  • Accelerate version: 1.10.1
  • PEFT version: not installed
  • Bitsandbytes version: not installed
  • Safetensors version: 0.6.2
  • xFormers version: not installed
  • Accelerator: NVIDIA GeForce RTX 4070 Ti SUPER, 16376 MiB
  • Using GPU in script?:
  • Using distributed or parallel set-up in script?:

Who can help?

No response

Activity

  1. github-actions commented on Jan 9, 2026

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

    Please note that issues that do not follow the contributing guidelines are likely to be ignored.

  2. removed
    staleIssues that haven't received updates
    on Jan 10, 2026
  3. yiyixuxu commented on Jan 10, 2026

    @yiyixuxu
    Collaborator

    hey @scp3125

    Do you have an actual use case for squaredcos_cap_v2 + use_karras_sigmas? I'm not entirely sure why squaredcos_cap_v2 was excluded from rounding in the scheduler code. I can dig into the git commits history, but any change here would require extensive testing from our end, so I want to make sure there's a real use case first.
    Thanks!

  4. dylanzhao25 commented on Jan 11, 2026

    @dylanzhao25
    Author

    hey @scp3125

    Do you have an actual use case for squaredcos_cap_v2 + use_karras_sigmas? I'm not entirely sure why squaredcos_cap_v2 was excluded from rounding in the scheduler code. I can dig into the git commits history, but any change here would require extensive testing from our end, so I want to make sure there's a real use case first. Thanks!

    Yes, this is a real inference use case.

    import diffusers
    import torch
    from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline
    
    print("Diffusers:", diffusers.__version__)
    print("Torch:", torch.__version__)
    
    device = "cuda" if torch.cuda.is_available() else "cpu"
    
    pipe = StableDiffusionPipeline.from_pretrained(
        "stable-diffusion-v1-5/stable-diffusion-v1-5",
        requires_safety_checker=False,
    ).to(device)
    pipe.set_progress_bar_config(disable=True)
    
    pipe.scheduler = DPMSolverMultistepScheduler.from_config(
        pipe.scheduler.config,
        beta_schedule="squaredcos_cap_v2",
        use_karras_sigmas=True,
    )
    
    pipe.scheduler.set_timesteps(20, device=device)
    print("Timesteps:", pipe.scheduler.timesteps)
    
    out = pipe(
        prompt=["an astronaut riding a horse on mars"],
        num_inference_steps=20,
    )
    print("OK, got", len(out.images), "images")

    Output:

    Diffusers: 0.35.2
    Torch: 2.8.0
    Loading pipeline components...: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:00<00:00, 29.48it/s]
    Timesteps: tensor([998, 998, 998, 998, 998, 998, 998, 998, 998, 997, 996, 994, 989, 978,
            949, 867, 623, 221,  33,   0])
    Traceback (most recent call last):
      File "/Users/py-test/./src/demo/main.py", line 25, in <module>
        out = pipe(
              ^^^^^
      File "/Users/py-test/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context
        return func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^
      File "/Users/py-test/.venv/lib/python3.12/site-packages/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py", line 1061, in __call__
        latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0]
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/py-test/.venv/lib/python3.12/site-packages/diffusers/schedulers/scheduling_dpmsolver_multistep.py", line 1112, in step
        prev_sample = self.multistep_dpm_solver_second_order_update(self.model_outputs, sample=sample, noise=noise)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/py-test/.venv/lib/python3.12/site-packages/diffusers/schedulers/scheduling_dpmsolver_multistep.py", line 835, in multistep_dpm_solver_second_order_update
        self.sigmas[self.step_index + 1],
        ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
    IndexError: index 21 is out of bounds for dimension 0 with size 21
    

    Version:

    - 🤗 Diffusers version: 0.35.2
    - Platform: macOS-26.2-arm64-arm-64bit
    - Running on Google Colab?: No
    - Python version: 3.12.11
    - PyTorch version (GPU?): 2.8.0 (False)
    - Flax version (CPU?/GPU?/TPU?): not installed (NA)
    - Jax version: not installed
    - JaxLib version: not installed
    - Huggingface_hub version: 0.35.3
    - Transformers version: 4.57.3
    - Accelerate version: 1.10.1
    - PEFT version: 0.18.0
    - Bitsandbytes version: not installed
    - Safetensors version: 0.6.2
    - xFormers version: not installed
    - Accelerator: Apple M4 Pro
    - Using GPU in script?: <fill in>
    - Using distributed or parallel set-up in script?: <fill in>
    
  5. github-actions commented on Feb 4, 2026

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

    Please note that issues that do not follow the contributing guidelines are likely to be ignored.

  6. added 2 commits that reference this issue on Mar 10, 2026
    7a6ed10
    9efe640
  7. xThreeh commented on Oct 7, 2026

    @xThreeh

    @yiyixuxu on the use-case question: kandinsky-community/kandinsky-3 ships DDPMScheduler with beta_schedule="squaredcos_cap_v2", so swapping in a faster solver the usual way, X.from_config(pipe.scheduler.config, use_karras_sigmas=True), hits this.

    It isn't limited to DPMSolverMultistepScheduler. With that config and 25 steps on current main:

    Scheduler Duplicated timesteps Result
    DPMSolverMultistep 11 IndexError: index 26 is out of bounds
    UniPCMultistep 10 AssertionError
    DEISMultistep 10 IndexError: index 26 is out of bounds
    DPMSolverSinglestep 10 IndexError: list index out of range
    SASolver 10 AssertionError

    In each case the Karras sigmas map to near-identical timesteps at the top of the cosine schedule, and the step index drifts past the end. #13240 only touches DPMSolverMultistepScheduler.

    Would you take a fix that covers all five, with a test running each of them on the cosine + Karras config? Happy to put it together if that's the direction you want.

    Found while property-testing the schedulers; prepared with AI assistance, reproduced and checked by me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleIssues that haven't received updates

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions