Skip to content
BIASED

DDPM: the forward process

How diffusion destroys data on purpose: a Markov chain of small Gaussian steps, a closed-form jump to any step t, and noise schedules that end in N(0, I).

Many small steps

The topic Energy-based models ended with a bill: sampling an EBM takes hundreds of gradient steps on a learned landscape, and training needs such samples after every update. Diffusion models keep the walk from noise to data but change what is learned. They reach noise in many small steps of a fixed process, each step adds a little Gaussian noise, and no step has to be invertible, unlike the layers of a flow (see The change of variables).

Start from a data point x0∈RDx_0 \in \mathbb R^D, say an image. Add a little noise to get x1x_1, a little more to get x2x_2, and so on up to xTx_T:

x0  ⟶  x1  ⟶  x2  ⟶  ⋯  ⟶  xT.x_0 \;\longrightarrow\; x_1 \;\longrightarrow\; x_2 \;\longrightarrow\; \cdots \;\longrightarrow\; x_T .

This is the forward process. Two properties define it. First, each step looks only at the previous point: xtx_t is drawn from a distribution q(xt∣xt−1)q(x_t \mid x_{t-1}) that ignores x0,…,xt−2x_0, \dots, x_{t-2}. A chain like this is a Markov chain. Second, qq is fixed in advance. It has no parameters, and nothing in it is trained.

Why destroy data on purpose? Because of where the chain ends. We want xTx_T to be distributed as N(0,I)\mathcal N(0, I), whatever image we started from. That is a prior we can sample from, like p(z)p(z) in a VAE or a flow. If a model learns to walk the chain backwards, from xTx_T to x0x_0, it turns noise into data. The idea comes from Sohl-Dickstein et al. (2015); DDPM (Ho, Jain and Abbeel, 2020) made it produce good images. This topic builds the forward chain. The walk back comes next.

First attempt: just add noise

The simplest step adds fresh noise with variance β\beta to every coordinate:

xt=xt−1+β εt,εt∼N(0,I).x_t = x_{t-1} + \sqrt{\beta}\,\varepsilon_t, \qquad \varepsilon_t \sim \mathcal N(0, I).

The square root is there because β\beta is a variance: c εc\,\varepsilon has variance c2c^2. Each εt\varepsilon_t is drawn independently of everything before it.

Several steps merge into one. Unrolled, x2=x0+β ε1+β ε2x_2 = x_0 + \sqrt\beta\,\varepsilon_1 + \sqrt\beta\,\varepsilon_2. A sum of independent Gaussians is Gaussian, and the variances add (see Multivariate Gaussians). So x2x_2 has the same distribution as x0+2β εx_0 + \sqrt{2\beta}\,\varepsilon with a single ε∼N(0,I)\varepsilon \sim \mathcal N(0, I). After tt steps,

q(xt∣x0)=N(x0, tβ I).q(x_t \mid x_0) = \mathcal N\big(x_0,\ t\beta\, I\big).

This is a useful shortcut and a useless destination. The mean stays at x0x_0 forever, and the variance tβt\beta grows without bound. The chain never settles on any fixed distribution, let alone N(0,I)\mathcal N(0, I). The image does not disappear; it drowns in ever larger noise. Such a process is called variance-exploding. Some models do use it and stop at a large finite noise level, but DDPM takes a different route.

Shrink, then add noise

To pull the mean towards zero, each step must also shrink the previous point. Give it a scale a>0a > 0:

xt=a xt−1+β εt.x_t = a\, x_{t-1} + \sqrt{\beta}\,\varepsilon_t .

Track the variance of one coordinate. The fresh noise is independent of xt−1x_{t-1}, so the variances add, and the scale enters squared:

Var⁡(xt)=a2Var⁡(xt−1)+β.\operatorname{Var}(x_t) = a^2 \operatorname{Var}(x_{t-1}) + \beta .

With a=1a = 1 this is the exploding chain: +β+\beta at every step. With a<1a < 1 the old variance shrinks while fresh noise refills it. The target N(0,I)\mathcal N(0, I) has variance 11 in every coordinate. So we want a step that leaves variance 11 alone: if Var⁡(xt−1)=1\operatorname{Var}(x_{t-1}) = 1, then Var⁡(xt)=1\operatorname{Var}(x_t) = 1 as well.

You have met such a step. In Multivariate Gaussians, for independent x,ε∼N(0,1)x, \varepsilon \sim \mathcal N(0, 1) the mix 0.6 x+0.8 ε0.6\,x + 0.8\,\varepsilon was again N(0,1)\mathcal N(0, 1). That is this step with a=0.6a = 0.6 and β=0.64\beta = 0.64. A step that keeps variance 11 in place has a second virtue: it pulls any other variance towards 11, a little at every step.

Jump straight to step t

Requiring a2+β=1a^2 + \beta = 1, that is a=1−βa = \sqrt{1 - \beta}, gives the DDPM step. Let the noise variance change from step to step, β1,…,βT\beta_1, \dots, \beta_T, and write αt=1−βt\alpha_t = 1 - \beta_t. Then

xt=αt xt−1+βt εt,q(xt∣xt−1)=N(αt xt−1, βtI).x_t = \sqrt{\alpha_t}\, x_{t-1} + \sqrt{\beta_t}\,\varepsilon_t, \qquad q(x_t \mid x_{t-1}) = \mathcal N\big(\sqrt{\alpha_t}\, x_{t-1},\ \beta_t I\big).

Now merge two steps, as we did for the naive chain. Substitute x1=α1 x0+β1 ε1x_1 = \sqrt{\alpha_1}\,x_0 + \sqrt{\beta_1}\,\varepsilon_1 into the second step:

x2=α2α1  x0+α2β1  ε1+β2  ε2.x_2 = \sqrt{\alpha_2\alpha_1}\; x_0 + \sqrt{\alpha_2\beta_1}\;\varepsilon_1 + \sqrt{\beta_2}\;\varepsilon_2 .

The two noises are independent, so they merge into one Gaussian with variance α2(1−α1)+1−α2=1−α1α2\alpha_2(1 - \alpha_1) + 1 - \alpha_2 = 1 - \alpha_1\alpha_2. The same thing happens at every further step, by induction. Write αˉt=∏s=1tαs\bar\alpha_t = \prod_{s=1}^{t} \alpha_s and suppose xt−1=αˉt−1 x0+1−αˉt−1 ε′x_{t-1} = \sqrt{\bar\alpha_{t-1}}\,x_0 + \sqrt{1 - \bar\alpha_{t-1}}\,\varepsilon', with ε′\varepsilon' built from the earlier noises and so independent of εt\varepsilon_t. One more step multiplies the coefficient of x0x_0 by αt\sqrt{\alpha_t}, giving αˉt\sqrt{\bar\alpha_t}, and the noise variance becomes αt(1−αˉt−1)+1−αt=1−αˉt\alpha_t(1 - \bar\alpha_{t-1}) + 1 - \alpha_t = 1 - \bar\alpha_t. Then

q(xt∣x0)=N(αˉt x0, (1−αˉt) I),xt=αˉt x0+1−αˉt  ε,ε∼N(0,I).q(x_t \mid x_0) = \mathcal N\big(\sqrt{\bar\alpha_t}\, x_0,\ (1 - \bar\alpha_t)\, I\big), \qquad x_t = \sqrt{\bar\alpha_t}\, x_0 + \sqrt{1 - \bar\alpha_t}\;\varepsilon, \quad \varepsilon \sim \mathcal N(0, I).

This is the affine sampling trick again: z=μ+σ⊙εz = \mu + \sigma \odot \varepsilon from The reparameterization trick, with mean μ=αˉt x0\mu = \sqrt{\bar\alpha_t}\,x_0 and scale σ=1−αˉt\sigma = \sqrt{1 - \bar\alpha_t}. One draw of ε\varepsilon gives xtx_t for any tt directly, without running the t−1t - 1 steps before it. That matters for training, which will need noisy images at random steps over and over. The two squared coefficients always sum to 11. With αˉ0=1\bar\alpha_0 = 1, the formula covers t=0t = 0 too.

Where the chain ends

As long as the steps do not shrink towards zero, say every βs≥βmin⁡>0\beta_s \ge \beta_{\min} > 0, the product obeys αˉt≤(1−βmin⁡)t\bar\alpha_t \le (1 - \beta_{\min})^t and falls to zero as tt grows. (Factors merely below 11 are not enough: with βs\beta_s shrinking fast, the product can stall at a positive value.) In the closed form the image term αˉt x0\sqrt{\bar\alpha_t}\,x_0 fades out, the noise scale 1−αˉt\sqrt{1 - \bar\alpha_t} rises to 11, and q(xt∣x0)q(x_t \mid x_0) approaches N(0,I)\mathcal N(0, I), whatever the image.

Here is a constant β=0.02\beta = 0.02, so that αˉt=0.98t\bar\alpha_t = 0.98^t, next to the naive chain with the same β\beta:

tt αˉt\bar\alpha_t mean coefficient αˉt\sqrt{\bar\alpha_t} noise std 1−αˉt\sqrt{1 - \bar\alpha_t} naive noise std tβ\sqrt{t\beta}
11 0.9800.980 0.9900.990 0.1410.141 0.1410.141
1010 0.8170.817 0.9040.904 0.4280.428 0.4470.447
5050 0.3640.364 0.6030.603 0.7970.797 1.0001.000
200200 0.01760.0176 0.1330.133 0.9910.991 2.0002.000

For small tt the two chains agree. Then the naive noise overshoots 11 and keeps growing, while DDPM's approaches 11 from below.

The whole data distribution behaves the same way, not just one image. Draw x0x_0 from the data, independently of ε\varepsilon. Then, per coordinate, Var⁡(xt)=αˉtVar⁡(x0)+1−αˉt\operatorname{Var}(x_t) = \bar\alpha_t \operatorname{Var}(x_0) + 1 - \bar\alpha_t, that is, Var⁡(xt)−1=αˉt (Var⁡(x0)−1)\operatorname{Var}(x_t) - 1 = \bar\alpha_t\,\big(\operatorname{Var}(x_0) - 1\big). Variance 11 stays 11 at every step, and for any other variance the gap to 11 is multiplied by αˉt\bar\alpha_t. That is why this chain is called variance-preserving. The two-bump density from The change of variables would spread out, its bumps would drift towards 00 and merge, and it would end as a single bell, N(0,1)\mathcal N(0, 1).

In practice TT is finite, so xTx_T is close to N(0,I)\mathcal N(0, I) but not equal to it. DDPM uses T=1000T = 1000 and ends at αˉT≈4.0⋅10−5\bar\alpha_T \approx 4.0 \cdot 10^{-5}, so αˉT≈0.006\sqrt{\bar\alpha_T} \approx 0.006. Images are scaled to [−1,1][-1, 1] first, so what remains of the image is tiny next to noise of scale 11. That is why generation can start from xT∼N(0,I)x_T \sim \mathcal N(0, I). A chain too short to forget the image would break this: a sampler started from pure noise would start from the wrong distribution.

Noise schedules

The list β1,…,βT\beta_1, \dots, \beta_T is the noise schedule. It sets how fast αˉt\bar\alpha_t falls, that is, how fast the image is destroyed.

DDPM uses a linear schedule: T=1000T = 1000, and βt\beta_t grows linearly from β1=10−4\beta_1 = 10^{-4} to βT=0.02\beta_T = 0.02. Small early steps keep the first xtx_t close to the image; larger late steps finish the job. With this schedule αˉt\bar\alpha_t drops below 0.50.5 at t=260t = 260 and stays below 0.010.01 from t=674t = 674 on. The last third of the chain works on what is already almost pure noise.

Nichol and Dhariwal (2021) found this wasteful for small images (32×3232 \times 32 and 64×6464 \times 64). On ImageNet 64×6464 \times 64, a model trained with the linear schedule loses almost nothing in quality when the noisiest 20%20\% of its reverse steps are skipped. Their cosine schedule prescribes αˉt\bar\alpha_t directly instead of βt\beta_t:

αˉt=f(t)f(0),f(t)=cos⁡2 ⁣(t/T+s1+s⋅π2),s=0.008.\bar\alpha_t = \frac{f(t)}{f(0)}, \qquad f(t) = \cos^2\!\Big(\frac{t/T + s}{1 + s}\cdot\frac{\pi}{2}\Big), \qquad s = 0.008 .

Here αˉt\bar\alpha_t falls almost linearly through the middle of the chain and changes slowly near both ends:

schedule αˉ250\bar\alpha_{250} αˉ500\bar\alpha_{500} αˉ750\bar\alpha_{750} αˉt<0.5\bar\alpha_t < 0.5 from
linear 0.5240.524 0.0790.079 0.00340.0034 t=260t = 260
cosine 0.8470.847 0.4940.494 0.1440.144 t=497t = 497

Information is destroyed more evenly over time. The small offset ss keeps the first step from being vanishingly small. The steps βt\beta_t are then recovered from αˉt\bar\alpha_t and capped at 0.9990.999, because the formula gives αˉT=0\bar\alpha_T = 0 at the very end.

Signal and noise

Schedules are easier to compare on one scale. In xt=αˉt x0+1−αˉt εx_t = \sqrt{\bar\alpha_t}\,x_0 + \sqrt{1 - \bar\alpha_t}\,\varepsilon the squared coefficient of the image is αˉt\bar\alpha_t and the noise variance is 1−αˉt1 - \bar\alpha_t. Their ratio is the signal-to-noise ratio:

SNRt=αˉt1−αˉt.\mathrm{SNR}_t = \frac{\bar\alpha_t}{1 - \bar\alpha_t} .

For data of unit variance it is the ratio of the signal variance to the noise variance. It falls monotonically with tt; for the linear schedule, from about 10410^4 at t=1t = 1 to 4⋅10−54 \cdot 10^{-5} at t=Tt = T. Signal and noise are equally strong where SNRt=1\mathrm{SNR}_t = 1. A schedule is just a choice of how SNRt\mathrm{SNR}_t, often its logarithm, goes down from large to nearly zero. Everything else in the forward process stays the same.

So the forward process is complete. It is fixed, it has no parameters, and for any tt it hands us a noisy xtx_t in a single draw. To generate, we have to run it backwards: start from xT∼N(0,I)x_T \sim \mathcal N(0, I) and step from xtx_t to xt−1x_{t-1} until we reach x0x_0. The next topic, DDPM: reverse process and objective, sets up a model for that step back and the loss that trains it.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Go deeper — optional

Code and labs do not count toward the main percentage or the certificate.

  • DDPM: β schedule and sampling x_toptional

    Computes ᾱ_t for a linear β schedule and checks marginal variance. Self-check in the notebook.

    ~20 min · easier on a computer · DDPM forward process topic read.

    Self-check in the notebook — not part of mastery or the certificate.

Full notes

Answers are saved on the server and tied to this browser until you sign in.