Search

Search papers and lessons

Cosine Noise Schedule

Level 4 · 11 min read

A cosine noise schedule sets how much noise each diffusion step adds using a cosine-squared curve, destroying information more gently at the start and end of the process than the older linear schedule.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Discrete math
  • Linear algebra
  • Generative models
  • Inference
  • ReadReady to readNot yet

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.

  1. Start with a clean image x0x_0. Pixel values lie in [-1, 1]. At step 0 nothing has been added. Check: the image is intact, so the surviving fraction is 1.

  2. Choose the surviving fraction at step t, αˉt\bar{\alpha}_t. Compute a cosine-squared value f(t)f(t) at step t, then divide by f(0)f(0) 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: αˉ0=1\bar{\alpha}_0 = 1, and αˉt\bar{\alpha}_t falls as t grows.

  3. 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 αˉt\sqrt{\bar{\alpha}_t}, and the scale on the noise is 1−αˉt\sqrt{1 - \bar{\alpha}_t}. Check: at αˉt=1\bar{\alpha}_t = 1 there is no noise; at αˉt=0\bar{\alpha}_t = 0 there is only noise.

  4. Get the per-step noise if needed. Training code sometimes needs the amount added between step t−1 and step t. This is βt\beta_t, computed from the ratio αˉt/αˉt−1\bar{\alpha}_t / \bar{\alpha}_{t-1}. The paper clips βt\beta_t at 0.999 so the last step does not blow up. This βt\beta_t is the per-step rate of the Markov chain that the forward process follows. Check: βt\beta_t is small when αˉ\bar{\alpha} barely changes between steps, and the clip only matters at the very end.

  5. Use a small offset s. Without it, the first step's noise β1\beta_1 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

Definition: Cosine noise schedule

For total steps T and offset s, the surviving signal fraction is

αˉt=f(t)f(0),f(t)=cos⁡(t/T+s1+s⋅π2)2\bar{\alpha}_{t}=\frac{f(t)}{f(0)}, \qquad f(t)=\cos\left(\frac{t/T+s}{1+s}\cdot\frac{\pi}{2}\right)^{2}

and the per-step noise is βt=1−αˉt/αˉt−1\beta_t = 1 - \bar{\alpha}_t / \bar{\alpha}_{t-1}, clipped at 0.999.

The forward process samples a noised image directly from the clean one:

xt=αˉt x0+1−αˉt ϵ,ϵ∼N(0,I)x_t=\sqrt{\bar{\alpha}_t}\,x_0+\sqrt{1-\bar{\alpha}_t}\,\epsilon, \qquad \epsilon\sim\mathcal{N}(0,\mathbf{I})

Here ϵ\epsilon is a sample of Gaussian noise with mean 0 and identity covariance I\mathbf{I}, meaning each pixel gets independent noise with variance 1. So αˉt\bar{\alpha}_t sets the balance between signal and noise directly: the signal variance is αˉt\bar{\alpha}_t and the noise variance is 1−αˉt1 - \bar{\alpha}_t (see Mean and Variance). The ratio of the two is the signal-to-noise ratio at step t, αˉt/(1−αˉt)\bar{\alpha}_t / (1 - \bar{\alpha}_t).

Step 1 in symbols

x0x_0 is the clean image. The schedule is defined at t = 0, which gives αˉ0=f(0)/f(0)=1\bar{\alpha}_0 = f(0)/f(0) = 1.

Step 2 in symbols

The argument of the cosine is t/T+s1+s⋅π2\frac{t/T + s}{1 + s} \cdot \frac{\pi}{2}. At t = 0 it is a small angle, close to 0; at t = T it reaches π/2\pi/2 and the cosine goes to 0. Squaring the cosine keeps the values in [0, 1]. Dividing by f(0)f(0) rescales the curve so that it starts at exactly 1.

Step 3 in symbols

Given αˉt\bar{\alpha}_t, the noised image has the mixing weights αˉt\sqrt{\bar{\alpha}_t} and 1−αˉt\sqrt{1 - \bar{\alpha}_t}. 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 αˉt\bar{\alpha}_t alone.

Step 4 in symbols

βt=1−αˉt/αˉt−1\beta_t = 1 - \bar{\alpha}_t / \bar{\alpha}_{t-1}. This relates the per-step noise of the chain to the cumulative fraction αˉt\bar{\alpha}_t. The clip keeps βt≤0.999\beta_t \le 0.999.

Step 5 in symbols

With s = 0.008 the offset makes f(0)f(0) very close to 1, so the first step's β1\beta_1 is small but not zero. The authors chose s so that the square root of the first step's β\beta is just below one pixel bin on the 0 to 255 scale, which is 1/127.51/127.5 in the [-1, 1] range.

Worked examples

Example
Example 1: a four-step toy schedule

Setup: T = 4, s = 0, so αˉt=cos⁡2(t/4⋅π/2)\bar{\alpha}_t = \cos^2(t/4 \cdot \pi/2).

  1. At t = 0, the angle is 0, so cos(0) = 1 and αˉ0=1\bar{\alpha}_0 = 1.
  2. At t = 1, the angle is π/8 ≈ 0.3927. cos(0.3927) = 0.9239, and squaring gives αˉ1=0.8536\bar{\alpha}_1 = 0.8536.
  3. At t = 2, the angle is π/4. cos(π/4) = 0.7071, and squaring gives αˉ2=0.5\bar{\alpha}_2 = 0.5.
  4. At t = 3, the angle is 3π/8. cos(3π/8) = 0.3827, and squaring gives αˉ3=0.1464\bar{\alpha}_3 = 0.1464.
  5. At t = 4, the angle is π/2, so cos is 0 and αˉ4=0\bar{\alpha}_4 = 0.
  6. The per-step noise at step 1 is β1=1−0.8536/1=0.1464\beta_1 = 1 - 0.8536 / 1 = 0.1464.
  7. At step 2, β2=1−0.5/0.8536=1−0.5858=0.4142\beta_2 = 1 - 0.5 / 0.8536 = 1 - 0.5858 = 0.4142.
  8. At step 3, β3=1−0.1464/0.5=1−0.2929=0.7071\beta_3 = 1 - 0.1464 / 0.5 = 1 - 0.2929 = 0.7071.
  9. At step 4, β4=1−0/0.1464=1\beta_4 = 1 - 0 / 0.1464 = 1, 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.

Example
Example 2: the standard case at the midpoint

Setup: T = 1000, s = 0.008. Find αˉ\bar{\alpha} at t = 500.

  1. 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.
  2. cos(0.79163) = 0.70268. Square it: f(500) = 0.49376.
  3. Compute f(0): (0 + 0.008) / 1.008 = 0.007937. Times π/2 gives 0.012467. cos(0.012467) = 0.999922, squared = 0.999845.
  4. Divide: αˉ500=0.49376/0.999845=0.4938\bar{\alpha}_{500} = 0.49376 / 0.999845 = 0.4938, about 0.49.
  5. Compare with the linear schedule of Ho et al. at the same step. Its β\beta runs linearly from 0.0001 to 0.02 over 1000 steps, so at step 500 it is about 0.01 and the sum of β\beta over the first 500 steps is about 500 × (0.0001 + 0.01) / 2 = 2.5. Since αˉ\bar{\alpha} is roughly e−∑βe^{-\sum \beta}, that gives αˉ\bar{\alpha} 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.

Example
Example 3: a realistic training batch at the midpoint

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 αˉ500=0.49\bar{\alpha}_{500} = 0.49.

  1. The forward equation gives the noised image as xt=0.49 x0+0.51 ϵx_t = \sqrt{0.49}\,x_0 + \sqrt{0.51}\,\epsilon.
  2. The scale on the clean image is 0.49=0.70\sqrt{0.49} = 0.70. The scale on the noise is 0.51=0.71\sqrt{0.51} = 0.71.
  3. The signal-to-noise ratio is 0.49/0.51=0.960.49 / 0.51 = 0.96. The clean image and the noise are almost equally loud.
  4. The network is asked to predict the noise ϵ\epsilon from xtx_t 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.
  5. Contrast with the linear schedule at the same step: αˉ≈0.08\bar{\alpha} \approx 0.08, 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 αˉt=0.9\bar{\alpha}_t = 0.9 at some step, what is the signal-to-noise ratio? Answer: 0.9/0.1=90.9 / 0.1 = 9. 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 αˉ\bar{\alpha} and β\beta are interchangeable. In fact αˉ\bar{\alpha} is the cumulative surviving fraction and β\beta is the step-by-step noise. Training uses αˉ\bar{\alpha} directly, and β\beta 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 β\beta 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 αˉ\bar{\alpha}, 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 αˉt\bar{\alpha}_t is the cosine-squared curve, normalised so αˉ0=1\bar{\alpha}_0 = 1.
  • 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 αˉt\sqrt{\bar{\alpha}_t} and 1−αˉt\sqrt{1 - \bar{\alpha}_t}, so the signal-to-noise ratio is αˉt/(1−αˉt)\bar{\alpha}_t / (1 - \bar{\alpha}_t).
  • 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 αˉt\bar{\alpha}_t represent, and what are its values at t = 0 and t = T?Show answer
αˉt\bar{\alpha}_t is the fraction of the original signal that survives at step t, so the image's weight in the forward equation is αˉt\sqrt{\bar{\alpha}_t}. It equals 1 at t = 0, where nothing has been added, and it is 0 at t = T in the cosine schedule, where the image is pure noise.
QuestionComputation: with αˉt=0.64\bar{\alpha}_t = 0.64, what are the scales on the clean image and the noise in the forward equation, and what is the signal-to-noise ratio αˉ/(1−αˉ)\bar{\alpha}/(1-\bar{\alpha})?Show answer
The scale on the clean image is 0.64=0.8\sqrt{0.64} = 0.8. The scale on the noise is 0.36=0.6\sqrt{0.36} = 0.6. The signal-to-noise ratio is 0.64/0.36=1.780.64 / 0.36 = 1.78, so the signal is still somewhat stronger than the noise.
QuestionWhy does the cosine schedule use a small offset s instead of setting f(t)=cos⁡2(t/T⋅π/2)f(t) = \cos^2(t/T \cdot \pi/2) directly?Show answer
Without the offset, β\beta near t = 0 is almost zero, so the first steps add so little noise that the network cannot predict the noise accurately. The offset s = 0.008 makes the first step add a little under one pixel bin's worth of noise, which gives the network a signal to learn from at the start of the process.
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
The paper's gain was largest at 64 by 64 and smaller, so no improvement at 512 by 512 is consistent with that result. Test next whether the number of steps or the sampling budget changes the picture, and compare FID at the same budget rather than assuming the cosine curve will help.

Sources