Skip to content

fixed_large_log variance sampling returns NaNs #14569

Open

Description

@Robertboy18

Describe the finding

DDPMScheduler.step() and DDPMParallelScheduler.step() treat fixed_large_log like an ordinary variance and take its square root. _get_variance() returns log(current_beta_t) for this mode, though, so the square root is applied to a negative value and the sample becomes NaN.

The intended scale is exp(0.5 * log_variance), which is equivalent to the sqrt(variance) used by fixed_large.

I have a small fix ready for both scheduler implementations, along with CPU regression tests comparing fixed_large_log against the equivalent fixed_large sampling result. Happy to open the PR if this approach sounds right : )

Reproduction

import torch
from diffusers import DDPMScheduler, DDPMParallelScheduler

for scheduler_class in (DDPMScheduler, DDPMParallelScheduler):
    scheduler = scheduler_class(variance_type="fixed_large_log")
    sample = torch.zeros((1, 2, 2, 2))
    model_output = torch.zeros_like(sample)
    output = scheduler.step(
        model_output,
        500,
        sample,
        generator=torch.Generator().manual_seed(0),
    ).prev_sample
    print(scheduler_class.__name__, torch.isnan(output).sum().item())

Current output:

DDPMScheduler 8
DDPMParallelScheduler 8

Expected: both outputs are finite and match fixed_large when using the same generator.

System info

  • Diffusers version: 0.40.0.dev0 (main at 58eb52c)
  • Python: 3.12.13
  • PyTorch: 2.13.0+cu130
  • Platform: Linux
  • GPU used by reproduction: No
  • Distributed setup: No

@yiyixuxu

Activity

  1. lllakshit commented on Aug 23, 2026

    @lllakshit

    I reproduced this on current main for both DDPMScheduler and DDPMParallelScheduler. Opened #14571 with the exp(0.5 * log) conversion in step() plus regression tests that check samples are finite and match fixed_large at the same seed.

  2. Robertboy18 commented on Nov 15, 2026

    @Robertboy18
    Author

    Thanks @lllakshit for #14571, and sorry for the slow reply!

  3. 1OF1Research commented on Nov 16, 2026

    @1OF1Research

    Reproduced on diffusers 0.43.0, and the mechanism is visible in the shipped code.

    DDPMScheduler._get_variance for fixed_large_log returns torch.log(current_beta_t) — a negative number — and does not convert it back. In step(), the noise term for this type falls into the general branch, (_get_variance(...) ** 0.5) * variance_noise: the square root of a negative log-variance, which is NaN. (The two neighbouring log types avoid this in opposite ways: fixed_small_log exponentiates inside _get_variance, and learned_range is exponentiated in step().)

    Seeded run (identical protocol for every type, 20 steps, 100 train timesteps, CPU):

    variance_type nonfinite steps
    fixed_small 0/20
    fixed_small_log 0/20
    fixed_large 0/20
    fixed_large_log 19/20
    learned 0/20
    learned_range 0/20

    The one finite step under fixed_large_log is the final t=0 step, which adds no noise. Direct probe agrees: _get_variance(t, variance_type="fixed_large_log") returns −9.21 at t=0 through −3.91 at t=99 — log values, all negative.

    Fix shape: give fixed_large_log the same treatment as fixed_small_log — return exp(0.5 * log(beta_t)) from _get_variance, or exponentiate this type in step() alongside learned_range. A test that runs each documented variance type for a few steps and asserts finite samples would catch this class.

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