Skip to content

EulerDiscreteScheduler(interpolation_type="log_linear") builds one sigma too many, so sampling stops before the final sigma #15481

Backlog

Description

@javierdejesusda

Describe the bug

With interpolation_type="log_linear" and otherwise default schedule settings, EulerDiscreteScheduler.set_timesteps(25) produces 25 timesteps and 27 sigmas. The loop stops at sigma 0.0100. With linear, it produces 26 sigmas and reaches the configured final sigma of 0.

The CPU reproduction uses a fixed clean-sample prediction. The maximum absolute error in the final sample is 0.0341 with log_linear and 0.0000 with linear. Diffusers 0.43.0 gives the same results.

log_linear creates one more grid point than linear before the final sigma is appended. Each call to step() advances to the next sigma, so the extra point consumes the last step. Schedule construction · Euler update

The released stabilityai/sd-x2-latent-upscaler scheduler config selects EulerDiscreteScheduler with "interpolation_type": "log_linear"; loading that config and calling set_timesteps(25) also gives 25 timesteps and 27 sigmas.

I'd be happy to fix this and add CPU regression tests if the scope looks appropriate.

Reproduction

import diffusers
import torch
from diffusers import EulerDiscreteScheduler

print("diffusers", diffusers.__version__, "torch", torch.__version__)

x0 = torch.full((1, 4, 8, 8), 0.5)
for interpolation_type in ["linear", "log_linear"]:
    scheduler = EulerDiscreteScheduler(interpolation_type=interpolation_type, prediction_type="sample")
    scheduler.set_timesteps(25)
    sample = torch.randn(x0.shape, generator=torch.Generator().manual_seed(0)) * scheduler.init_noise_sigma
    for t in scheduler.timesteps:
        scheduler.scale_model_input(sample, t)
        sample = scheduler.step(x0, t, sample).prev_sample  # a denoiser that always predicts x0 exactly
    print(
        f"{interpolation_type:>10}: {len(scheduler.timesteps)} timesteps, {len(scheduler.sigmas)} sigmas, "
        f"last sigma reached = {scheduler.sigmas[len(scheduler.timesteps)].item():.4f}, "
        f"max |final sample - x0| = {(sample - x0).abs().max().item():.4f}"
    )
print("expected: len(sigmas) == len(timesteps) + 1 and the loop ends at sigma 0, as with interpolation_type='linear'")
if len(scheduler.sigmas) != len(scheduler.timesteps) + 1:
    raise SystemExit("interpolation_type='log_linear' builds one sigma too many; the loop stops before sigma 0")

Context

Found while reading EulerDiscreteScheduler.set_timesteps and comparing its log_linear branch with the linear branch; reproduced with the script in this issue through the public API on main at 12d5c7a (run on 2026-12-03).

Logs

diffusers 0.44.0.dev0 torch 2.15.0+cpu
    linear: 25 timesteps, 26 sigmas, last sigma reached = 0.0000, max |final sample - x0| = 0.0000
log_linear: 25 timesteps, 27 sigmas, last sigma reached = 0.0100, max |final sample - x0| = 0.0341
expected: len(sigmas) == len(timesteps) + 1 and the loop ends at sigma 0, as with interpolation_type='linear'
interpolation_type='log_linear' builds one sigma too many; the loop stops before sigma 0

System Info

  • Diffusers: 0.44.0.dev0 (main, 12d5c7a)
  • Python: 3.11.15
  • PyTorch: 2.15.0+cpu
  • NumPy: 2.4.6
  • OS: Linux x86_64
  • Using GPU in script? No

Who can help?

No response

Activity

  1. adimalkar commented on Dec 4, 2026

    @adimalkar

    I'd like to fix this. It's still on main: the log_linear branch builds num_inference_steps + 1 points (scheduling_euler_discrete.py:441) and the final sigma is appended after that, so the schedule has one sigma too many and sampling stops short of it. My plan is to build num_inference_steps points so it matches linear, and add a test that log_linear gives num_inference_steps + 1 sigmas ending at the configured final sigma. Since the released stabilityai/sd-x2-latent-upscaler config uses log_linear, its outputs would change slightly. Is that OK to go ahead with?

  2. ldj7672 commented on Dec 4, 2026

    @ldj7672

    I independently reproduced this on an Apple Silicon Mac using the released stabilityai/sd-x2-latent-upscaler scheduler config and synthetic samples, with no model weights. On both CPU and MPS, 25 requested steps produced 27 sigmas and stopped at 0.029168. With a denoiser that predicts the clean sample exactly, the maximum residual was 0.09848. The linear control reached zero with 26 sigmas and zero residual.

    One extra case for the regression tests: with timestep_type="continuous" and prediction_type="v_prediction", 25 requested steps currently produce 26 timesteps and reach zero. That branch derives the timesteps from the sigma array. Karras, exponential, and beta rescheduling already gave 25 timesteps and reached zero in the CPU controls.

    AI assistance was used to run and summarize these checks.

  3. adimalkar commented on Dec 4, 2026

    @adimalkar

    Thanks @ldj7672, good catch. The fix I have locally (building num_inference_steps log-linear sigmas instead of num_inference_steps + 1) covers that case too: with timestep_type="continuous" and v_prediction, 25 steps now give 25 timesteps and 26 sigmas, ending at zero. I added it to the regression test next to both final_sigmas_type values. I will open the PR once a maintainer is OK with the approach.

  4. ldj7672 commented on Dec 4, 2026

    @ldj7672

    One edge case for the sigma_min regression. I checked the released SD x2 scheduler config with 25 steps. Rebuilding the log-linear grid with 25 points puts the last model evaluation at essentially the same sigma as the appended sigma_min (difference about 4e-9). The assertion on 25 timesteps and 26 sigmas passes, but only 24 transitions change sigma by more than 1e-7.

    Replacing the unused endpoint with sigma_last instead preserved all 25 model-evaluation sigmas and gave 25 nontrivial transitions for both terminal settings in this check. This is a compatibility trade-off worth making explicit in the test.

  5. javierdejesusda commented on Dec 4, 2026

    @javierdejesusda
    ContributorAuthor

    Thanks @ldj7672, that matches what I found. I've had a fix in progress since I opened this, and my local patch does what you describe: it drops the unused last point of the log-linear grid instead of rebuilding it with num_inference_steps points. With the default config and 25 steps, that gives 25 timesteps and 26 sigmas, keeps the first 25 sigmas identical to main, and every one of the 25 steps changes sigma, for both final_sigmas_type values and for timestep_type="continuous" with v_prediction.

    @yiyixuxu, I'd like to take the fix. Could you assign it to me, or let me know if this approach works for you? I'll open the PR once you're OK with it.

  6. adimalkar commented on Dec 5, 2026

    @adimalkar

    Thanks @javierdejesusda, your approach is the better one, since it keeps the evaluated sigmas unchanged for the released upscaler. Since you opened this and already have it in progress, it's all yours. Happy to review the PR.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions