Vocabulary for this course

The terms the chapters assume, in plain words. You can open this from any chapter.

closed form
A formula that gives a value directly, without stepping through every earlier stage.
denoising
Removing some random corruption from a sample in one step, as the model was trained to do.
diffusion model
A generator trained to turn random noise into data by undoing a chain of small corruptions.
forward process
The fixed chain that adds a little random corruption to a clean sample at each step.
Gaussian
A bell-shaped spread of values around a mean, described by that mean and a width.
guidance
Pushing each sampling step harder toward the text you asked for, trading variety for a closer match.
latent space
A smaller space of numbers where a compressor places images, so the model works on short codes.
noise
Random values added to a sample to corrupt it, drawn from a Gaussian.
noise schedule
The rule that decides how much corruption each step adds, and how fast the real pattern fades.
reverse process
The learned chain that removes corruption step by step, starting from pure randomness.
sampler
The procedure that runs the reverse process to produce a finished sample.
signal-to-noise ratio
How much real structure remains compared with the corruption at a given step.
timestep
One position in the corruption chain, numbered from clean to fully random.
VAE
A model that squeezes an image into a small code and rebuilds it, trained to keep what matters.

Diffusion models from the ground up

Noise schedules

The betas decide where the model spends its capacity. A good schedule spreads the work evenly across signal-to-noise ratios instead of destroying the signal early.

Part 4 of 10

Advanced16 min readBack to Courses

The schedule is a design choice

The betas are not learned and not sacred. A schedule is a curve from almost no noise to almost pure noise, and its shape decides how the model spends its capacity. The original linear schedule moves from one in ten thousand to two hundredths over a thousand steps. It works, but it destroys the signal early. By the halfway point alpha_bar is already tiny, so most of the second half is spent denoising pure noise.

A good schedule spends roughly equal effort across the range of signal-to-noise ratios where the model can learn something. That is a vague target. The cosine schedule is a practical approximation. Its alpha_bar follows a cosine squared curve, which keeps more signal for longer and reaches zero smoothly at the end. Stable Diffusion uses a scaled linear schedule with a different start and end, tuned for latents rather than pixels.

Reading a schedule

Three numbers tell you most of what a schedule does. The first is where alpha_bar crosses one half, which is roughly where signal and noise are balanced. The second is how many steps have a signal-to-noise ratio below one. That is the part of training spent on mostly noise. The third is the value at the final step. A schedule that ends above zero has not destroyed the data, and the sampler will have to finish the job itself.

Plot log signal-to-noise ratio against t, and the curve is almost a straight line for a well-behaved schedule. That is not an accident. The model’s difficulty is roughly uniform in log SNR. A schedule that is linear in log SNR therefore gives every difficulty an equal share of steps. The cosine curve is close to that. The linear beta curve is not, and that is exactly its weakness. The linear curve spends its first two hundred steps at a log SNR above four, where almost any denoiser succeeds. It spends its last six hundred below zero, where the target is nearly pure noise.

A cosine schedule

import torch
from diffusers import DDPMScheduler

scheduler = DDPMScheduler(
    num_train_timesteps=1000,
    beta_schedule="squaredcos_cap_v2",
)
print(scheduler.betas[:5])
print(scheduler.alphas_cumprod[[0, 250, 500, 750, 999]])

# The Stable Diffusion schedule is a scaled linear one.
sd = DDPMScheduler(
    num_train_timesteps=1000,
    beta_schedule="scaled_linear",
    beta_start=0.00085,
    beta_end=0.012,
)

Linear against cosine

Compare a linear beta schedule with a cosine alpha_bar curve. Find where each one loses half the signal and count the steps spent with more noise than signal.

Output
Click "Run" to execute your code

Zero terminal SNR and its consequences

Some schedules are built to reach alpha_bar of exactly zero at the last step. That sounds like a detail and is not. If the final distribution is not exactly standard normal, the sampler starts from the wrong distribution. The model also never sees the pure-noise case it is asked to invert. Zero terminal SNR fixes the mismatch, and it makes the model’s job at the last step well defined.

It also breaks the simple noise parameterization at the final step. There the coefficient of x_0 is zero and the coefficient of eps is one, so predicting eps and predicting x_0 are degenerate. That is one reason v-prediction and zero-terminal schedules are often paired. If you change one of these choices, check the others. A schedule, a parameterization and a sampler form a set, and mixing them across a checkpoint is how silent quality loss happens.

A schedule is part of the checkpoint. Loading weights trained on a cosine schedule into a pipeline that defaults to linear gives a model that denoises the wrong distribution at every step, and nothing in the code will complain.

Resolution and the schedule

A schedule is defined in terms of variance, not pixels. It transfers between image sizes better than most people expect. What does not transfer is how hard the task is. A 1024 image has more spatial detail, and the same alpha_bar leaves a different amount of visible structure. Models trained at one resolution and sampled at another often need the timestep range shifted. The trick is called dynamic thresholding or trailing timesteps.

The practical rule is to keep the schedule fixed at training. Treat any change at sampling as a guess that must be measured. Fewer steps, a shifted range, a different final alpha: each is a change to the distribution the model was trained on. Some are harmless, some are not. The only way to know is a fixed evaluation set and a metric you trust. A schedule is cheap to change and expensive to get wrong.

Steps evenly spaced in log SNR

Map seven target log signal-to-noise ratios onto timesteps for a cosine schedule. Compare that list with timesteps spaced evenly in t and see which range gets more attention.

Output
Click "Run" to execute your code

Check what you learned

One question at a time. A wrong answer explains itself — take another go.

Part 1 of 5

What does a noise schedule decide?