4.5.12Generative Models

Noise scheduling

2,202 words10 min readdifficulty · medium

What Is Noise Scheduling?

WHY does this matter? The schedule determines:

  1. Training stability: Bad schedules → gradient vanishing/exploding
  2. Sample quality: Poor schedules → artifacts, mode collapse
  3. Speed: Number of steps T needed for good samples

Deriving the Schedule Mathematics

From Single-Step to Multi-Step

Start with the recurrence (why: we need to relate xtx_t to x0x_0):

xt=αtxt1+1αtϵt1,ϵt1N(0,I)x_t = \sqrt{\alpha_t} x_{t-1} + \sqrt{1-\alpha_t} \epsilon_{t-1}, \quad \epsilon_{t-1} \sim \mathcal{N}(0, I)

Expand recursively: xt=αt(αt1xt2+1αt1ϵt2)+1αtϵt1x_t = \sqrt{\alpha_t}(\sqrt{\alpha_{t-1}} x_{t-2} + \sqrt{1-\alpha_{t-1}} \epsilon_{t-2}) + \sqrt{1-\alpha_t} \epsilon_{t-1}

Key insight: Sum of independent Gaussians. If Z1N(0,σ12)Z_1 \sim \mathcal{N}(0, \sigma_1^2) and Z2N(0,σ22)Z_2 \sim \mathcal{N}(0, \sigma_2^2), then: Z1+Z2N(0,σ12+σ22)Z_1 + Z_2 \sim \mathcal{N}(0, \sigma_1^2 + \sigma_2^2)

Apply: xt=αtαt1xt2+αt(1αt1)+(1αt)ϵx_t = \sqrt{\alpha_t \alpha_{t-1}} x_{t-2} + \sqrt{\alpha_t(1-\alpha_{t-1}) + (1-\alpha_t)} \epsilon

Simplify the variance (why this step: algebra to combine noise terms): αt(1αt1)+(1αt)=αtαtαt1+1αt=1αtαt1\alpha_t(1-\alpha_{t-1}) + (1-\alpha_t) = \alpha_t - \alpha_t\alpha_{t-1} + 1 - \alpha_t = 1 - \alpha_t\alpha_{t-1}

Continue to x0x_0: xt=αˉtx0+1αˉtϵ,αˉt=s=1tαsx_t = \sqrt{\bar{\alpha}_t} x_0 + \sqrt{1-\bar{\alpha}_t} \epsilon, \quad \bar{\alpha}_t = \prod_{s=1}^t \alpha_s

WHY αˉt\bar{\alpha}_t matters: Single number that captures total signal remaining at step tt.

Figure — Noise scheduling

Common Schedules

Design Principles

1. Signal-to-Noise Ratio (SNR)

Define SNR at step tt: SNR(t)=αˉt1αˉt\text{SNR}(t) = \frac{\bar{\alpha}_t}{1-\bar{\alpha}_t}

Derivation:

  • Variance of signal component: αˉtx02\bar{\alpha}_t \|x_0\|^2
  • Variance of noise: (1αˉt)d(1-\bar{\alpha}_t) d (dimension dd)
  • Ratio gives SNR

WHY it matters: Neural network learns best when SNR changes smoothly (≈ constant difficulty per step).

2. Boundary Conditions

At t=0t=0 (start):

  • Want αˉ01\bar{\alpha}_0 \approx 1 (almost no noise added); in an SNR parametrization we cap it at 1ε1-\varepsilon to keep log-SNR finite
  • β1\beta_1 should be very small but non-zero (numerical stability)

At t=Tt=T (end):

  • Need αˉT0\bar{\alpha}_T \approx 0 (indistinguishable from prior N(0,I)\mathcal{N}(0,I))
  • Typically aim for αˉT<102\bar{\alpha}_T < 10^{-2}

WHY: Poor boundaries → network must work harder at edges, artifacts appear.

Adaptive Schedules

Connections

  • 4.5.11-Forward-and-reverse-diffusion-process — Schedule defines forward process q(xtxt1)q(x_t|x_{t-1})
  • 4.5.13-Denoising-objective — Schedule determines loss weighting across timesteps
  • 4.5.15-Score-matching — SNR affects score function magnitude xtlogp(xt)\nabla_{x_t} \log p(x_t)
  • 4.5.18-Fast-sampling — Schedule choice enables step-skipping strategies (DDIM)
Recall Explain to a 12-year-old

Imagine you're trying to guess what a picture looks like, but someone keeps adding more and more blur to it. The noise schedule is like the recipe for how much blur to add each second.

If you add tons of blur right away, you'll lose important details like faces or text — game over. If you add blur super slowly, it'll take forever to blur it completely. The best schedules (like "cosine") add blur slowly at first (keeping details), speed up in the middle, then slow down again at the end.

Why? Because our "de-blurring robot" (the neural network) learns better when each step is equally hard. If one step is too easy and another is impossible, the robot gets confused. A good schedule makes every step just-right difficult!

#flashcards/ai-ml

What is the mathematical relationship between βt\beta_t, αt\alpha_t, and αˉt\bar{\alpha}_t in noise scheduling?
αt=1βt\alpha_t = 1 - \beta_t (per-step signal retention), αˉt=s=1tαs\bar{\alpha}_t = \prod_{s=1}^t \alpha_s (cumulative signal retention from x0x_0 to xtx_t)
What is the correct linear schedule formula?
βt=β1+(t1)(βTβ1)T1\beta_t = \beta_1 + \frac{(t-1)(\beta_T - \beta_1)}{T-1} — a linear interpolation from β1\beta_1 (typically 10410^{-4}) to βT\beta_T (typically 0.020.02)
Why does cosine schedule outperform linear schedule in diffusion models?
Cosine provides S-curve decay: preserves signal longer initially (fewer early artifacts), smoother SNR gradient (stable training), avoids the linear schedule's early collapse where signal is nearly gone by the midpoint, wasting late steps
Derive the direct sampling formula xt=αˉtx0+1αˉtϵx_t = \sqrt{\bar{\alpha}_t} x_0 + \sqrt{1-\bar{\alpha}_t} \epsilon
Start with xt=αtxt1+1αtϵt1x_t = \sqrt{\alpha_t} x_{t-1} + \sqrt{1-\alpha_t}\epsilon_{t-1}. Expand recursively, use Gaussian sum property N(0,σ12)+N(0,σ22)=N(0,σ12+σ22)\mathcal{N}(0,\sigma_1^2) + \mathcal{N}(0,\sigma_2^2) = \mathcal{N}(0,\sigma_1^2+\sigma_2^2), simplify variances to get αˉt\sqrt{\bar{\alpha}_t} coefficient on x0x_0
What is the SNR at timestep tt and why does it matter for schedule design?
SNR(t)=αˉt/(1αˉt)\text{SNR}(t) = \bar{\alpha}_t/(1-\bar{\alpha}_t). Measures signal-to-noise ratio; constant logSNR\log \text{SNR} decay ensures uniform difficulty per denoising step, leading to stable gradients and better convergence
Why is logSNR(0)\log\text{SNR}(0) ill-defined and how do we fix it in an SNR-based schedule?
At t=0t=0, αˉ0=1\bar{\alpha}_0=1 so SNR(0)=1/0=\text{SNR}(0)=1/0=\infty and logSNR=+\log\text{SNR}=+\infty. Fix by regularizing: cap αˉ0\bar{\alpha}_0 at 1ε1-\varepsilon (giving finite λmax=log1εε\lambda_{\max}=\log\frac{1-\varepsilon}{\varepsilon}) or start the schedule at tmin>0t_{\min}>0
Why must β1>0\beta_1 > 0 (not exactly zero) even though we want to preserve information initially?
Exactly zero causes: (1) division by α1=1\sqrt{\alpha_1}=1 numerical issues, (2) zero gradient flow (no learning signal), (3) infinite/undefined log-SNR since αˉ1=1\bar{\alpha}_1=1. Tiny β1104\beta_1\approx 10^{-4} provides stability without significant information loss
What boundary conditions must a good noise schedule satisfy?
At t=0t=0: αˉ01\bar{\alpha}_0 \approx 1 (no noise; capped at 1ε1-\varepsilon for finite log-SNR). At t=Tt=T: αˉT<0.01\bar{\alpha}_T < 0.01 (nearly pure noise, matches prior N(0,I)\mathcal{N}(0,I)). Poor boundaries cause edge artifacts
How is βt\beta_t computed from a αˉt\bar{\alpha}_t schedule?
From definition αˉt=αˉt1αt=αˉt1(1βt)\bar{\alpha}_t = \bar{\alpha}_{t-1} \alpha_t = \bar{\alpha}_{t-1}(1-\beta_t), rearrange: βt=1αˉt/αˉt1\beta_t = 1 - \bar{\alpha}_t/\bar{\alpha}_{t-1}. Clamp to valid range [104,0.999][10^{-4}, 0.999] for numerical stability

Concept Map

defines

reparam as

product gives

enables

instance

instance

drives

smooth decay of

affects

affects

affects

Noise Schedule beta_t

Forward process q x_t given x_t-1

alpha_t = 1 - beta_t

Cumulative alpha_bar_t

Direct sampling from x_0

Linear Schedule DDPM

Cosine Schedule Improved DDPM

Training Stability

Sample Quality

Steps T Needed

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, diffusion models ka basic idea simple hai: hum ek clean image mein thoda-thoda karke noise add karte hain jab tak woh pure random noise na ban jaye, aur phir model ko sikhate hain ki is process ko ulta kaise kare. Yahan noise scheduling ka matlab hai ki har step par kitna noise add karna hai - ye ek recipe hai. Socho tum ek photo ko acid mein dhire-dhire ghula rahe ho: agar shuru mein hi bahut tezi se ghula doge to important details permanently lost ho jayengi aur model reverse nahi kar payega; agar bahut slowly karoge to time waste hoga. Isliye schedule (βt\beta_t ya αt\alpha_t values) ko carefully balance karna padta hai.

Ab maths ki taraf - ek badi khubsurat baat ye hai ki independent Gaussian noises ko add karne se variance simply add ho jaata hai. Isi property ki wajah se hum recurrence ko expand karke ek direct formula nikaal sakte hain: xt=αˉtx0+1αˉtϵx_t = \sqrt{\bar{\alpha}_t}\, x_0 + \sqrt{1-\bar{\alpha}_t}\, \epsilon. Yahan αˉt\bar{\alpha}_t (cumulative product of α\alpha values) ek single number hai jo batata hai step tt par original signal ka kitna hissa bacha hai. Iska practical fayda ye hai ki hume step-by-step noise add nahi karna padta - kisi bhi timestep ka noisy image ek hi shot mein sample kar sakte hain, jo training ko fast banata hai.

Ab linear vs cosine schedule ka farak samajhna zaroori hai. Linear schedule shuru mein hi signal ko jaldi khatam kar deta hai - t=500t=500 tak toh signal almost gaya, matlab baaki ke late steps kaafi waste ho jaate hain kyunki wahan already pure noise hai. Cosine schedule zyada smart hai: ye signal ko lambe time tak zinda rakhta hai (S-curve shape mein - slow start, fast middle, slow end), destruction ko evenly distribute karta hai. Isse gradients stable rehte hain, artifacts kam aate hain aur sample quality behtar hoti hai. Ye matter karta hai kyunki galat schedule se tumhara model ya toh train hi nahi hoga (vanishing/exploding gradients) ya phir ghatiya, blurry images banayega - toh scheduling ek chhoti si cheez lagti hai par poore model ki performance decide karti hai.

Go deeper — visual, from zero

Test yourself — Generative Models

Connections