TL;DR
A diffusion model learns to generate data by reversing a process that adds noise step by step. The noise schedule decides how much noise each step adds. The cosine schedule, from Nichol and Dhariwal in 2021, defines the amount of surviving signal with a cosine-squared curve. It keeps the image readable for longer at the start and avoids being pure noise too early at the end, which gave better samples on small images than the older linear schedule.
Builds on: Diffusion Model, Signal-to-Noise Ratio, Gaussian (Normal) Distribution · Leads to: Improved DDPM, which adopts this schedule
Where it's used
Image generation at small sizes. The paper that introduced the schedule trained on CIFAR-10 at 32 by 32 pixels and on ImageNet at 64 by 64. The authors found that the linear schedule of DDPM wasted many steps on nearly pure noise at the end, and the cosine schedule improved sample quality on those sizes, measured with FID.
Choosing the number of steps. The schedule is written in terms of t/T, so changing the total number of steps T stretches the same curve. That matters when you want fewer steps for faster sampling, as in DDIM sampling, because the curve keeps its shape.
How it works
Think of the forward process as a dial that goes from clean to pure noise over T steps. At step t the dial sets how much of the original image survives.
-
Start with a clean image . Pixel values lie in [-1, 1]. At step 0 nothing has been added. Check: the image is intact, so the surviving fraction is 1.
-
Choose the surviving fraction at step t, . Compute a cosine-squared value at step t, then divide by so the value at step 0 is exactly 1. The result starts at 1, falls in the middle, and reaches 0 at the end. The curve is flat near the ends and steep in the middle. Check: , and falls as t grows.
-
Turn the fraction into a mix of image and noise. At step t, the noised image is the scaled clean image plus scaled Gaussian noise. The scale on the clean image is , and the scale on the noise is . Check: at there is no noise; at there is only noise.
-
Get the per-step noise if needed. Training code sometimes needs the amount added between step t−1 and step t. This is , computed from the ratio . The paper clips at 0.999 so the last step does not blow up. This is the per-step rate of the Markov chain that the forward process follows. Check: is small when barely changes between steps, and the clip only matters at the very end.
-
Use a small offset s. Without it, the first step's noise would be almost zero, and the network would find tiny amounts of noise hard to predict. The paper sets s = 0.008, which makes the first step add a little less than one pixel bin's worth of noise. Check: with s = 0 the first steps would add almost no noise.
The math
For total steps T and offset s, the surviving signal fraction is
and the per-step noise is , clipped at 0.999.
The forward process samples a noised image directly from the clean one:
Here is a sample of Gaussian noise with mean 0 and identity covariance , meaning each pixel gets independent noise with variance 1. So sets the balance between signal and noise directly: the signal variance is and the noise variance is (see Mean and Variance). The ratio of the two is the signal-to-noise ratio at step t, .
Step 1 in symbols
is the clean image. The schedule is defined at t = 0, which gives .
Step 2 in symbols
The argument of the cosine is . At t = 0 it is a small angle, close to 0; at t = T it reaches and the cosine goes to 0. Squaring the cosine keeps the values in [0, 1]. Dividing by rescales the curve so that it starts at exactly 1.
Step 3 in symbols
Given , the noised image has the mixing weights and . These are the coefficients from the forward equation above. The training loss of DDPM, a mean squared error on the noise, only needs these weights, so the schedule enters training through alone.
Step 4 in symbols
. This relates the per-step noise of the chain to the cumulative fraction . The clip keeps .
Step 5 in symbols
With s = 0.008 the offset makes very close to 1, so the first step's is small but not zero. The authors chose s so that the square root of the first step's is just below one pixel bin on the 0 to 255 scale, which is in the [-1, 1] range.
Worked examples
Setup: T = 4, s = 0, so .
- At t = 0, the angle is 0, so cos(0) = 1 and .
- At t = 1, the angle is π/8 ≈ 0.3927. cos(0.3927) = 0.9239, and squaring gives .
- At t = 2, the angle is π/4. cos(π/4) = 0.7071, and squaring gives .
- At t = 3, the angle is 3π/8. cos(3π/8) = 0.3827, and squaring gives .
- At t = 4, the angle is π/2, so cos is 0 and .
- The per-step noise at step 1 is .
- At step 2, .
- At step 3, .
- At step 4, , which is above the 0.999 clip, so the clip replaces it with 0.999.
Interpretation: the per-step noise grows toward the end (0.146, then 0.414, then 0.707), so the last steps do most of the destroying. The clip is needed only at the final step.
Setup: T = 1000, s = 0.008. Find at t = 500.
- Compute the angle at t = 500: (500/1000 + 0.008) / 1.008 = 0.508 / 1.008 = 0.50397. Multiply by π/2: 0.50397 × 1.5708 = 0.79163.
- cos(0.79163) = 0.70268. Square it: f(500) = 0.49376.
- Compute f(0): (0 + 0.008) / 1.008 = 0.007937. Times π/2 gives 0.012467. cos(0.012467) = 0.999922, squared = 0.999845.
- Divide: , about 0.49.
- Compare with the linear schedule of Ho et al. at the same step. Its runs linearly from 0.0001 to 0.02 over 1000 steps, so at step 500 it is about 0.01 and the sum of over the first 500 steps is about 500 × (0.0001 + 0.01) / 2 = 2.5. Since is roughly , that gives around 0.08 (a first-order estimate).
Interpretation: at the halfway point the cosine schedule still keeps about half the signal, while the linear schedule has already destroyed most of it. That is the paper's point: the linear schedule throws information away too early.
Setup: an image model trains on 64 by 64 images with T = 1000 and the cosine schedule. A training sample is drawn at t = 500 with .
- The forward equation gives the noised image as .
- The scale on the clean image is . The scale on the noise is .
- The signal-to-noise ratio is . The clean image and the noise are almost equally loud.
- The network is asked to predict the noise from and t. At this step both parts are strong enough to learn from, which is the reason the schedule spends its steps around the middle.
- Contrast with the linear schedule at the same step: , so the signal-to-noise ratio is about 0.09. The network sees an image that is mostly noise, and much of the training effort at this step goes into near-pure noise.
Try it: with at some step, what is the signal-to-noise ratio? Answer: . The image is nine times as strong as the noise in power terms, so it is still mostly clean.
Common mistakes and tradeoffs
It is tempting to think the cosine schedule is always better than the linear one. In fact the gain was largest at the small image sizes the paper tested, because the linear schedule wasted steps on near-pure noise there. The original linear schedule was designed for larger images, and the benefit shrinks as resolution grows. The choice depends on the resolution and the sampling budget. Many high-resolution systems also work in a compressed space, see Latent Diffusion Model, so the pixel schedule matters less there.
It is tempting to think and are interchangeable. In fact is the cumulative surviving fraction and is the step-by-step noise. Training uses directly, and is only needed where the reverse step is written in terms of the one-step chain.
It is tempting to think the offset s is a fine detail. In fact, without it the first steps add so little noise that the network has a hard time predicting it, and the paper chose s by a visual argument about pixel bins.
When to use it: small or medium images, and models that will be trained for a fixed number of steps. When not to use it: if you already use a schedule tuned for your data, or you are working at very high resolution where the linear schedule is known to be fine. Alternatives: the linear schedule of DDPM, and learned schedules that tune the curve during training.
History
In 2020 Ho and colleagues showed that a diffusion model with a linear noise schedule could generate high-quality images, and this became the standard recipe in DDPM. Their schedule ramped linearly from a small value to a larger one across the steps.
In 2021 Nichol and Dhariwal studied the schedule directly and found that the linear one destroyed information too quickly at the end, which hurt smaller images. They proposed the cosine curve in terms of , the offset s, and the clip at 0.999, and reported better sample quality at 32 by 32 and 64 by 64 resolution. The cosine schedule then became a common default in later diffusion work.
Recap
- A Diffusion Model adds noise over T steps, and the noise schedule sets how much signal survives each step.
- The surviving signal fraction is the cosine-squared curve, normalised so .
- The offset s = 0.008 stops the first steps from adding too little noise, and the clip at 0.999 stops the last step from blowing up.
- At each step the forward equation mixes the clean image and noise with weights and , so the signal-to-noise ratio is .
- Compared with the linear schedule, the cosine schedule keeps more signal in the middle of the process, which matters most at small image sizes.
Next, read DDPM for the training loss that uses these weights, and Improved DDPM for the paper that introduced the schedule.
Check yourself
QuestionRecall: what does represent, and what are its values at t = 0 and t = T?Show answer
QuestionComputation: with , what are the scales on the clean image and the noise in the forward equation, and what is the signal-to-noise ratio ?Show answer
QuestionWhy does the cosine schedule use a small offset s instead of setting directly?Show answer
QuestionApplied: a team trains a diffusion model on 512 by 512 images with the linear schedule and sees good samples. They switch to the cosine schedule and see no improvement. What would you conclude, and what would you test next?Show answer
Sources
- Nichol and Dhariwal, Improved Denoising Diffusion Probabilistic Models (arXiv:2102.09672)
- Ho, Jain and Abbeel, Denoising Diffusion Probabilistic Models (arXiv:2006.11239)