Skip to content

← Generative Models step 5 of 11

Easy Primitives

DDPM Noise Schedule

A diffusion noise schedule specifies the variance added at each step. Implement linear_beta_schedule(num_steps, beta_start=0.0001, beta_end=0.02) to build a linear schedule and its cumulative alpha values.

Inputs and output

num_steps is a positive integer T. The endpoints are finite floats with 0 <= beta_start <= beta_end < 1.

Return a float32 tensor of shape (2, T):

  • Row 0 contains the beta values.
  • Row 1 contains alpha_bar, the cumulative product of 1 - beta.

For T greater than 1, create T evenly spaced beta values including both endpoints. For T=1, use only beta_start, even if beta_end differs.

Cumulative products and indexing

Use zero-based array indices:

alphas[t] = 1 - betas[t]
alpha_bar[t] = alphas[0] * alphas[1] * ... * alphas[t]

The product includes index t. In particular, alpha_bar[0] is 1 - beta_start, not 1: index 0 represents the first noising step. Index t therefore describes t + 1 steps.

For T=3, beta_start=0.1 and beta_end=0.3, return these rows:

betas:     [0.1, 0.2, 0.3]
alpha_bar: [0.9, 0.72, 0.504]

The forward-noising exercise uses sqrt(alpha_bar[t]) to scale the clean input and sqrt(1 - alpha_bar[t]) to scale standard Gaussian noise. alpha_bar itself is not the multiplier applied directly to the clean input.

The final cumulative value depends on both endpoints and the number of steps. A short schedule need not end near zero. If every beta is zero, every cumulative alpha is one.

See Denoising Diffusion Probabilistic Models by Ho, Jain and Abbeel.