Session S25

Diffusion Models

VAEs train stably but blur; GANs are sharp but unstable. Diffusion adds noise to data step by step and trains a network to remove it. What does the noising do to the data, what must its schedule get right, what does the network learn and why does it train stably, how do we judge what it generates, and how is sampling made faster, steerable and practical for images?

Deep Learning · CS 4715/5715 · University of Idaho

No class next week (Fall Recess).

No class next week, and what is due when we come back

Before the material, the course calendar around the break.

  • Final report: due at the end of the S29 week.
  • No class next week (Fall Recess).
  • The first class after the break is S26 (efficiency and scale). Read 4.4 over the break.
  • HW4 (evaluation and efficiency) goes out today and is due at S29, the last class meeting. You can do Tasks 1 and 4 now; Tasks 5–6 use S26, and Tasks 2–3 use S27.
  • Quiz 4 (Module 4, S23–S26, today included) is at S27, the Wednesday after the break, in the last 30 minutes of class.
  • If your team's baseline does not run end to end yet, come to office hours this week, before the break.

S24 showed that a GAN learns its loss and that its training is a game

Two generative families so far, each with one strength and one weakness:

how it trainsits samplesper sample
VAE (S23)maximizes a likelihood bound: stableblurryone decoder pass
GAN (S24)a generator against a discriminator, a game: unstablesharp; can collapse onto a few modesone forward pass
  • Why it collapses: each player answers the other's current state, so \(G\) can put all its mass where \(D\) accepts it now. Coverage counts show it; the losses do not.
  • How to judge samples: sample statistics such as FID, or precision and recall.
  • What it costs to sample: a GAN generates in one forward pass, while naive diffusion removes noise step by step and needs hundreds (S24's history page).

Today, as S24 announced: diffusion, trained with a plain regression loss and no game. Its weakness is slow sampling.

Today answers five questions, one part each

Five parts, each answering one clause of the title page's question; a sixth closes.

partthe question it answers
1 · Forward processWhat does the noising do to the data? One noising step, then a formula that jumps to any step; both are checked on two moons.
2 · The scheduleWhat must its schedule get right? With too few steps the noising stops short of pure noise; we find the cause and repair it.
3 · Reverse processWhat does the network learn, and why is training stable? It predicts the noise; sampling runs its step backwards.
4 · A tiny modelHow do we judge what it generates? We train a small model, sample from it, and compare its samples with the data in a table.
5 · Faster, steered, at scaleHow is sampling made faster, steerable and practical? A sampler that needs fewer steps, a label that steers the samples, and a latent space for images.
6 · CloseThe three families compared, six common mistakes, and today's answer.

Parts 1, 3 and 4 each end on a self-check. First, the forward process.

Diffusion destroys the data gradually, then learns to undo it

Part 1 · The forward process. The idea in one figure (reading 4.3):

Forward: add a little Gaussian noise at every step. This part is fixed, not learned.⋯⋯x0: the dataxt​xT: pure noiseReverse: a network removes one step of noise. This part is learned.Generation runs right to left, as achain of small denoising problems.Each step is ordinary supervisedregression, which is stable andwell understood, with noadversary anywhere.The panels are reading 4.3's two-moonspoints under DDPM's schedule, computedwith its script. Color shows the mooneach point started on.
  • The working recipe is DDPM's (Denoising Diffusion Probabilistic Models; Ho, Jain & Abbeel, NeurIPS 2020). Later image generators build on it, including Stable Diffusion, DALL-E 2 and Imagen.

Part 1 is the forward half: fixed, with nothing to train.

One forward step shrinks the signal a little and adds a little noise

  • The noise schedule is the list \(\beta_1,\dots,\beta_T\), one number per step. \(\beta_t\) is the variance of the noise added at step \(t\), a small number between 0 and 1 that increases with \(t\) (not S23's KL weight).
  • \(\alpha_t=1-\beta_t\) is slightly less than 1. DDPM's \(\beta_t\) runs from 0.0001 to 0.02, so its \(\alpha_t\) falls from \(1-0.0001=0.9999\) to \(1-0.02=0.98\).
\[\mathbf{x}_t=\sqrt{1-\beta_t}\;\mathbf{x}_{t-1}+\sqrt{\beta_t}\;\boldsymbol{\varepsilon}_t=\sqrt{\alpha_t}\;\mathbf{x}_{t-1}+\sqrt{1-\alpha_t}\;\boldsymbol{\varepsilon}_t\]
Example: βt​ = 0.02, the largest step of DDPM's schedule, so αt​ = 0.98xt−1​× 0.990εt​× 0.141xt​+=0.990 = √0.98 = √αt​, slightly less than 1:xt−1​, the signal, shrinks a little0.141 = √0.02 = √(1 − αt​), small:a little new noise is addedThe two squares are the twocoordinates of one point.
  • Shapes: \(\mathbf{x}_t\) has the data's shape, (4000, 2) for today's 4,000 points in 2-D; \(\boldsymbol{\varepsilon}_t\sim\mathcal{N}(\mathbf{0},\mathbf{I})\) is a fresh draw of the same shape. Both operations are elementwise.

Shrinking before adding the noise keeps the variance at 1

The step multiplies \(\mathbf{x}_{t-1}\) by \(\sqrt{1-\beta_t}\) before it adds the noise. The reason is the variance of each coordinate:

  • With the shrink: multiplying by \(\sqrt{1-\beta_t}\) multiplies a variance by \(1-\beta_t\), and independent terms add their variances. If each coordinate of \(\mathbf{x}_{t-1}\) has variance 1, then \(\mathbf{x}_t\) has \((1-\beta_t)\cdot1+\beta_t=1\).
  • Without the shrink: \(\mathbf{x}_t=\mathbf{x}_{t-1}+\sqrt{\beta_t}\;\boldsymbol{\varepsilon}_t\) would add \(\beta_t\) to the variance at every step, so the variance would keep growing. The factor \(\sqrt{1-\beta_t}\) removes exactly the variance that the noise adds.
Example: βt​ = 0.02. Variance of one coordinate after the step:0.98 = 0.990² from the signal0.02 = 0.141² from the noise0.98 + 0.02 = 1

One step barely changes \(\mathbf{x}\), and the variance of each coordinate stays 1.

Two forward steps combine into one step of the same form

Substitute one step into the next; two independent Gaussian noises sum to one Gaussian:

x0​x1​x2​xt​xT​⋯⋯each gray arrow: one step,× √αt​, plus noise of variance βt​
  1. Two steps: \(\mathbf{x}_t=\sqrt{\alpha_t}\big(\sqrt{\alpha_{t-1}}\,\mathbf{x}_{t-2}+\sqrt{1-\alpha_{t-1}}\,\boldsymbol{\varepsilon}_{t-1}\big)+\sqrt{1-\alpha_t}\,\boldsymbol{\varepsilon}_t\).
  2. The noise: \(\boldsymbol{\varepsilon}_{t-1}\) and \(\boldsymbol{\varepsilon}_t\) carry variances \(\alpha_t(1-\alpha_{t-1})\) and \(1-\alpha_t\), which sum to \(1-\alpha_t\alpha_{t-1}\). So \(\mathbf{x}_t=\sqrt{\alpha_t\alpha_{t-1}}\,\mathbf{x}_{t-2}+\sqrt{1-\alpha_t\alpha_{t-1}}\;\boldsymbol{\varepsilon}\), with one fresh \(\boldsymbol{\varepsilon}\).

Two steps have the form of one step, with the product \(\alpha_t\alpha_{t-1}\) in place of \(\alpha_t\).

The closed form collapses many steps into one jump

The previous page merged two steps into \(\mathbf{x}_t=\sqrt{\alpha_t\alpha_{t-1}}\,\mathbf{x}_{t-2}+\sqrt{1-\alpha_t\alpha_{t-1}}\;\boldsymbol{\varepsilon}\), one step of the same form.

  • Repeat down to \(\mathbf{x}_0\): \(\bar\alpha_t=\alpha_1\alpha_2\cdots\alpha_t\), a running product and not a mean, takes the place of \(\alpha_t\alpha_{t-1}\).
  • Three steps give \(\alpha_t\alpha_{t-1}\alpha_{t-2}\) in the same two places, and so on.
x0​x1​x2​xt​xT​⋯⋯one jumpeach gray arrow: one step,× √αt​, plus noise of variance βt​the blue jump: × √ᾱt​, plus noise ofvariance 1 − ᾱt​, in one draw
\[\mathbf{x}_t=\sqrt{\bar\alpha_t}\;\mathbf{x}_0+\sqrt{1-\bar\alpha_t}\;\boldsymbol{\varepsilon},\qquad \boldsymbol{\varepsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})\]

Jump straight from \(\mathbf{x}_0\) to any \(\mathbf{x}_t\), without simulating the steps in between.

What each factor of the closed form does

\(\sqrt{\bar\alpha_t}\) scales the signal and \(\sqrt{1-\bar\alpha_t}\) the noise; \(\bar\alpha_t\) falls from near 1 toward 0 as \(t\) grows.

Example: ᾱt​ = 0.25x0​× 0.5+ε× 0.866=xt​0.250.750.5² + 0.866² = 0.25 + 0.75 = 1
  • The squares of the two factors sum to \(\bar\alpha_t+(1-\bar\alpha_t)=1\) at every \(t\): for unit-variance data, the standard deviation of \(\mathbf{x}_t\) stays 1.
  • Standardizing the data makes that hold; it is a convention, not a requirement of the method.
  • A schedule has to do two things. Each \(\beta_t\) is small, so \(\mathbf{x}_t\approx\mathbf{x}_{t-1}\) and undoing one step is learnable. By step \(T\) the noising has finished: \(\bar\alpha_T\approx0\), so \(\mathbf{x}_T\approx\mathcal{N}(\mathbf{0},\mathbf{I})\), which generation can sample without any data.

Whether the noising finishes is worth seeing in numbers, not trusting.

The data is 4,000 standardized points on two moons

Reading 4.3's toy data, used for the rest of today:


import torch

torch.manual_seed(0)

# Two-moons data, generated in-code and standardized
def two_moons(n):
    t = torch.rand(n) * torch.pi
    outer = torch.stack([torch.cos(t[: n // 2]), torch.sin(t[: n // 2])], dim=1)
    inner = torch.stack([1 - torch.cos(t[n // 2 :]), 0.5 - torch.sin(t[n // 2 :])], dim=1)
    x = torch.cat([outer, inner]) + 0.05 * torch.randn(n, 2)
    return (x - x.mean(0)) / x.std(0)

x0 = two_moons(4000)
  
  • x0 is (4000, 2): rows 0–1999 are the outer moon (blue in every panel today), rows 2000–3999 the inner moon (orange). The figure draws every 16th point.
  • x.mean(0) and x.std(0) run over the 4,000 rows, so each coordinate is standardized to mean 0 and standard deviation 1: the previous page's unit-variance case.
  • Inside two_moons, t is an angle along each half circle, not a diffusion step.

A script prints the schedule's statistics at chosen steps

To see whether the noising finishes, a script forms \(\mathbf{x}_t\) with the closed form at chosen steps and prints three statistics:


def report(T, beta_max, ts):
    betas = torch.linspace(1e-4, beta_max, T)     # T evenly spaced values: beta_1 .. beta_T
    alpha_bar = torch.cumprod(1 - betas, dim=0)   # running product: every alpha-bar_t
    print(f"T = {T}, betas 1e-4 .. {beta_max}")
    print(f"{'t':>4} {'sqrt(a_bar)':>12} {'std(x_t)':>9} {'corr(x_t, x0)':>14}")
    for t in ts:
        eps = torch.randn_like(x0)
        xt = alpha_bar[t].sqrt() * x0 + (1 - alpha_bar[t]).sqrt() * eps
        corr = torch.corrcoef(torch.stack([xt[:, 0], x0[:, 0]]))[0, 1]  # correlation, first coordinates
        print(f"{t:>4} {alpha_bar[t].sqrt().item():>12.4f} "
              f"{xt.std().item():>9.4f} {corr.item():>14.4f}")

# The DDPM paper's schedule: T=1000, betas from 1e-4 to 0.02
report(1000, 0.02, [0, 249, 499, 749, 999])
  
  • alpha_bar[t] is one number, so xt is (4000, 2), like x0. Code counts steps from 0: alpha_bar[T - 1] is \(\bar\alpha_T\).

Predict: at the last index, t = 999, about what are sqrt(a_bar) and corr(x_t, x0)?

Under DDPM's schedule the moons spread into noise

The printed table, one panel per row: the points \(\mathbf{x}_t\) the script computed, and the row's numbers.

tsqrt(a_bar)std(x_t)corr(x_t, x0)00.99990.99980.99992490.72390.99880.71924990.28030.99730.28917490.05790.99980.04329990.00640.9902-0.0082The rows are the reading's printout; the panels are the points xt its script computes at each row.Color shows the moon each point started on.
  • corr(x_t, x0), how much of the data is left, is −0.0082 at t = 999: statistically zero, so \(\mathbf{x}_T\) is pure noise. For unit-variance data it equals \(\sqrt{\bar\alpha_t}\) up to sampling error, so the sqrt(a_bar) and corr rows nearly agree. std(x_t), the scale, stays near 1.0.

Under DDPM's schedule the noising finishes: \(\mathbf{x}_T\) is pure noise.

Self-check on the forward process

Three questions on Part 1.

(a) With \(\bar\alpha_t=0.64\), write the closed form for \(\mathbf{x}_t\) with its two numbers. What is the standard deviation of \(\mathbf{x}_t\) for unit-variance data?

(b) Part 3's training will need \(\mathbf{x}_t\) at a randomly chosen step \(t\) for every example. Why not get it by running the forward steps one at a time?

(c) In the \(T=1000\) table, what do corr falling to about 0 and std(x_t) staying near 1 each show?

(a) \(\mathbf{x}_t=0.8\,\mathbf{x}_0+0.6\,\boldsymbol{\varepsilon}\), from \(\sqrt{0.64}\) and \(\sqrt{0.36}\); \(0.64+0.36=1\), so the standard deviation is 1.

(b) The closed form gives any \(\mathbf{x}_t\) in one draw; stepping there takes \(t\) steps.

(c) No data is left at the end; the overall scale is held at 1.

Any step is one draw away, and under DDPM's schedule nothing of the data survives to \(T\).

With 200 steps and the same \(\beta\) range, the noising does not finish

Part 2 · The schedule. Does any schedule finish the noising? Generation runs the network once per step, so fewer steps make sampling faster. Here are 200 steps instead of 1000, with \(\beta\) still from 1e-4 to 0.02, in Part 1's report:


# Same beta range but only 200 steps: noising never finishes
report(200, 0.02, [0, 99, 199])
  
tsqrt(a_bar)std(x_t)corr(x_t, x0)1000 steps, β up to 0.029990.00640.9902-0.0082200 steps, β up to 0.021990.36361.01200.3533Not pure noise:blue points still sit higher,orange lower. Sampling stillstarts from N(0, I).The panels and numbers come from the reading's script(rows t = 0 and 99 omitted).Color shows the moon each point started on.
  • The endpoint keeps a 0.35 correlation with the data, yet sampling starts from \(\mathcal{N}(\mathbf{0},\mathbf{I})\), an input the model never saw at the last step. Nothing errors.

The endpoint depends on the sum of the \(\beta_t\)

Take logs of \(\bar\alpha_T=(1-\beta_1)(1-\beta_2)\cdots(1-\beta_T)\), and use \(\ln(1-\beta)\approx-\beta\) for small \(\beta\):

  1. \(\ln\bar\alpha_T=\sum_t\ln(1-\beta_t)\approx-\sum_t\beta_t\), so \(\sqrt{\bar\alpha_T}\approx e^{-\frac12\sum_t\beta_t}\).
  2. For a linear schedule, \(\sum_t\beta_t\) is the area under the ramp: \(T(\beta_1+\beta_T)/2\).
1000 steps, β up to 0.020.05010000area Σβt​ = 10.05e−area/2 ≈ 0.0066printed sqrt(a_bar) 0.0064200 steps, β up to 0.020.05010000area Σβt​ = 2.01e−area/2 ≈ 0.37printed sqrt(a_bar) 0.3636200 steps, β up to 0.050.05010000next page's repairarea Σβt​ = 5.01e−area/2 ≈ 0.082printed sqrt(a_bar) 0.0782stepβt​

Five times fewer steps over the same \(\beta\) range leave a fifth of the area, so \(\sqrt{\bar\alpha_T}\) rises from 0.0064 to 0.3636. \(T\) and the \(\beta\) range set the endpoint together.

Raising \(\beta_{\max}\) to 0.05 brings 200 steps close to pure noise

Keep 200 steps and raise the last \(\beta\) to 0.05, the reading's repair (Part 4 trains on it). Part 1's report checks it:


# 200 steps with beta_max rescaled: noising completes again
report(200, 0.05, [0, 99, 199])
  
tsqrt(a_bar)std(x_t)corr(x_t, x0)200 steps, β up to 0.021990.36361.01200.3533200 steps, β up to 0.051990.07821.00490.0720Repaired: the correlationfalls from 0.35 to 0.07 andthe colors mix again.(1000 steps reached −0.01.)The panels and numbers come from the reading's script(rows t = 0 and 99 omitted).Color shows the moon each point started on.

\(T\) and the \(\beta\) range are one design decision, not two. A schedule fails silently; only the statistics of \(\mathbf{x}_T\) show whether the noising finishes, so print them whenever either changes.

The network learns to predict the noise, with plain mean squared error

Part 3 · The reverse process. What does the network learn? Generation runs the noising backwards, and undoing a step needs the noise that was added. So DDPM's network \(\boldsymbol{\varepsilon}_\theta(\mathbf{x}_t,t)\) looks at \(\mathbf{x}_t\) and \(t\) and estimates the noise \(\boldsymbol{\varepsilon}\) that was mixed in:

\[L=\mathbb{E}_{t,\mathbf{x}_0,\boldsymbol{\varepsilon}}\big[\lVert\boldsymbol{\varepsilon}-\boldsymbol{\varepsilon}_\theta(\mathbf{x}_t,t)\rVert^2\big],\qquad \mathbf{x}_t=\sqrt{\bar\alpha_t}\,\mathbf{x}_0+\sqrt{1-\bar\alpha_t}\,\boldsymbol{\varepsilon}\]
x0tepsx0: a data pointt: a random stepε ∼ N(0, I)closed formxt = √ᾱt x0 + √(1 − ᾱt) εxt​xtεθ(xt, t)tε̂predmean of(ε̂ − ε)²lossthe target: the noise we drewbackward, step
  1. Sample a data point \(\mathbf{x}_0\), a step \(t\) and noise \(\boldsymbol{\varepsilon}\); form \(\mathbf{x}_t\) with Part 1's closed form.
  2. Regress \(\boldsymbol{\varepsilon}_\theta(\mathbf{x}_t,t)\) onto \(\boldsymbol{\varepsilon}\), and step the optimizer.

The target is noise we drew ourselves, so every example comes with its answer.

Why this trains stably where a GAN does not

S24's discriminator changed as the generator trained. Here nothing changes but the network's parameters \(\theta\):

GAN (S24)diffusion
what the network is trained towarda discriminator that is itself trainingnoise we drew, which training does not change
the lossa two-player gamemean squared error
one minibatchone move in the gamea fresh supervised problem with known answers
  • Training is ordinary supervised regression: no adversary whose improvement degrades your gradient signal, and no game to balance.
  • The cost moves to sampling: one network call per step, for every step from \(T\) down to 1.

Stable, because it is regression onto a target that training does not change.

Why predict the noise rather than the clean point

Given \(\mathbf{x}_t\), either target determines the other: solve the closed form for \(\mathbf{x}_0\), with the predicted noise \(\hat{\boldsymbol{\varepsilon}}=\boldsymbol{\varepsilon}_\theta(\mathbf{x}_t,t)\) in place of \(\boldsymbol{\varepsilon}\):

\[\hat{\mathbf{x}}_0=\frac{\mathbf{x}_t-\sqrt{1-\bar\alpha_t}\;\hat{\boldsymbol{\varepsilon}}}{\sqrt{\bar\alpha_t}}\]
  • So the choice is not about information. The two targets weight the steps differently in the loss and behave differently numerically.
  • The noise target has unit scale at every \(t\). DDPM found noise prediction effective in its setup; modern systems also train other targets, such as \(\mathbf{x}_0\) itself.

Both targets carry the same information; the noise target has the same scale at every step, and the next page shows how the two weight the steps.

Predicting the noise makes every step count equally in the loss

The second difference between the targets is the weighting. Subtract the closed form, solved for \(\mathbf{x}_0\) with the true \(\boldsymbol{\varepsilon}\), from the previous page's \(\hat{\mathbf{x}}_0\), and square:

\[\lVert\hat{\mathbf{x}}_0-\mathbf{x}_0\rVert^2=\frac{1-\bar\alpha_t}{\bar\alpha_t}\;\lVert\hat{\boldsymbol{\varepsilon}}-\boldsymbol{\varepsilon}\rVert^2\]
10²110⁻²10⁻⁴0199code index tWeight (1 − ᾱt​) / ᾱt​ against the code indext (log scale), Part 2's repaired schedule.t = 0: ᾱt​ = 0.9999, weight about 10⁻⁴.t = 199: ᾱt​ = 0.0782² ≈ 0.0061,weight about 160 (0.0782 is Part 2'sprinted sqrt(a_bar)).
  • Measured as an \(\mathbf{x}_0\) error, the same noise error is \((1-\bar\alpha_t)/\bar\alpha_t\) times as large. On Part 2's repaired schedule that is about \(10^{-4}\) at t = 0 and about 160 at t = 199 (the curve). So an \(\mathbf{x}_0\) loss counts the last steps about 160 times more than the noise loss does, and the first steps almost not at all.
  • Treat the target and its weighting as part of the recipe, not as a ranking in which noise prediction always wins (reading 4.3).

Choosing the noise target is a choice of weighting: every step counts equally.

The loss levels off above zero

The training loss averages over every \(t\), and at some steps the noise cannot be told apart from the data:

small t (t = 0)The noise is tiny next to the data'sown variation and cannot beseparated from it, even in principle.large t (t = 199)xt is almost pure noise, so thenoise is easy to predict.Points computed with reading 4.3's script at 200 steps, β up to 0.05.Color shows the moon each point started on.
  • So the loss levels off well above zero even for the best possible network; the residual error comes from the small-\(t\) steps.
  • A plateau usually means converged, not stalled. Judge the model by its samples, not by the loss curve.

The loss has a floor above zero; a flat loss means converged.

Sampling repeats one learned step from \(t=T\) down to 1

Part 3, continued · Sampling. Training is done; the trained network now generates a sample. Start from \(\mathbf{x}_T\sim\mathcal{N}(\mathbf{0},\mathbf{I})\). With \(\alpha_t=1-\beta_t\) and \(\hat{\boldsymbol{\varepsilon}}=\boldsymbol{\varepsilon}_\theta(\mathbf{x}_t,t)\), each step is:

\[\mathbf{x}_{t-1}=\frac{1}{\sqrt{\alpha_t}}\Big(\mathbf{x}_t-\frac{\beta_t}{\sqrt{1-\bar\alpha_t}}\,\hat{\boldsymbol{\varepsilon}}\Big)+\sqrt{\beta_t}\;\mathbf{z},\qquad \mathbf{z}\sim\mathcal{N}(\mathbf{0},\mathbf{I})\]
xT ∼ N(0, I)⋯xt​xt−1​⋯x0, a sampleone step, repeatedfor every txt​εθ(xt, t)tε̂the predicted noise, one numberper coordinate of xt​from xt, remove a share of ε̂,then rescale by 1/√αt​fresh noise √βt z, everystep except the lastxt−1​
  • The fresh \(\mathbf{z}\), at every step except the last, is part of the algorithm: without it, samples collapse toward the middle and lose the moons.
  • Part 5's deterministic sampler uses a different update; it is not this formula with \(\mathbf{z}\) deleted.

Step \(t\) added a share \(\beta_t/(1-\bar\alpha_t)\) of the noise in \(\mathbf{x}_t\), on average

The network estimates all the noise in \(\mathbf{x}_t\), but one sampling step should remove only what step \(t\) added. How much is that? \(\boldsymbol{\varepsilon}_t\) is step \(t\)'s own fresh noise; \(\boldsymbol{\varepsilon}\) is the closed form's total noise, which \(\hat{\boldsymbol{\varepsilon}}\) estimates.

  1. Undo step \(t\): \(\mathbf{x}_{t-1}=(\mathbf{x}_t-\sqrt{\beta_t}\,\boldsymbol{\varepsilon}_t)/\sqrt{\alpha_t}\). The network does not see \(\boldsymbol{\varepsilon}_t\), only an estimate of the total.
  2. Split the total, as in Part 1: the total noise \(\sqrt{1-\bar\alpha_t}\,\boldsymbol{\varepsilon}\) has two independent parts: the earlier steps' noise, which step \(t\) scaled by \(\sqrt{\alpha_t}\), so its variance is \(\alpha_t(1-\bar\alpha_{t-1})\); and step \(t\)'s own \(\sqrt{\beta_t}\,\boldsymbol{\varepsilon}_t\), with variance \(\beta_t\). The variances sum to \(1-\bar\alpha_t\).
  3. Expected share: given the sum of independent zero-mean Gaussians, each part is expected to carry its share of the variance. So \(\mathbb{E}[\sqrt{\beta_t}\,\boldsymbol{\varepsilon}_t\mid\boldsymbol{\varepsilon}]=\big(\beta_t/(1-\bar\alpha_t)\big)\sqrt{1-\bar\alpha_t}\,\boldsymbol{\varepsilon}=\big(\beta_t/\sqrt{1-\bar\alpha_t}\big)\,\boldsymbol{\varepsilon}\).
Step 2 as a bar: 1 − ᾱt​, split in two (widths for step 100 of Part 2's repaired schedule, where step t's share is 3.5%)the earlier steps' noise: αt​ (1 − ᾱt−1​)step t's noise: βt​

The sampling step removes step \(t\)'s expected share of the noise

Put the share from the previous page, \(\sqrt{\beta_t}\,\boldsymbol{\varepsilon}_t\approx(\beta_t/\sqrt{1-\bar\alpha_t})\,\hat{\boldsymbol{\varepsilon}}\) on average, into the undone step \(\mathbf{x}_{t-1}=(\mathbf{x}_t-\sqrt{\beta_t}\,\boldsymbol{\varepsilon}_t)/\sqrt{\alpha_t}\):

\[\mathbb{E}[\mathbf{x}_{t-1}\mid\mathbf{x}_t]\approx\frac{1}{\sqrt{\alpha_t}}\Big(\mathbf{x}_t-\frac{\beta_t}{\sqrt{1-\bar\alpha_t}}\,\hat{\boldsymbol{\varepsilon}}\Big)\]
  • This is the sampling step's first term; \(\sqrt{\beta_t}\,\mathbf{z}\) then adds spread around this mean.

Check: at \(t=1\), \(\bar\alpha_1=\alpha_1\). What share of the noise is step 1's, and what does the step return?

All of it: \(\beta_1/(1-\alpha_1)=1\). The step returns \((\mathbf{x}_1-\sqrt{\beta_1}\,\hat{\boldsymbol{\varepsilon}})/\sqrt{\alpha_1}\), Part 3's \(\hat{\mathbf{x}}_0\) at \(t=1\).

Each sampling step subtracts the average share of the noise that step \(t\) added, then adds fresh noise around that mean.

Self-check on the reverse process

Two questions on Part 3.

(a) For a minibatch of 256 points in 2-D, what are the shapes of t, eps, xt and the network's output? Is the loss a vector?

(b) The loss is the mean of \((\hat{\boldsymbol{\varepsilon}}-\boldsymbol{\varepsilon})^2\), where \(\boldsymbol{\varepsilon}\) is drawn from \(\mathcal{N}(\mathbf{0},\mathbf{I})\). Suppose a network ignores its input and predicts \(\hat{\boldsymbol{\varepsilon}}=\mathbf{0}\) for both coordinates. What value does the loss take, on average?

(a) t is (256,); the other three are (256, 2), one noise estimate per coordinate. The loss is one number, the mean over the batch and both coordinates.

(b) With \(\hat{\boldsymbol{\varepsilon}}=\mathbf{0}\) the loss is the mean of \(\varepsilon^2\), the variance of standard normal noise: about 1. A network that has learned anything must score below 1.

Regression onto noise we drew trains stably, and its loss stays above zero.

The tiny model reuses Part 1's data and Part 2's repaired schedule

Part 4 · A tiny model. How do we judge what a diffusion model generates? We train a small network on two moons, sample from it, and compare the samples with the data. The setup reuses Part 1's two_moons and Part 2's repaired schedule (reading 4.3's script):


import torch
import torch.nn as nn
torch.manual_seed(0)
data = two_moons(4000)

T = 200
betas = torch.linspace(1e-4, 0.05, T)   # beta_max rescaled so noising completes in 200 steps
alphas = 1 - betas
alpha_bar = torch.cumprod(alphas, dim=0)
  

The tiny model is a small MLP that also sees the step

The rest of the setup gives the step as five features and builds the network that predicts the noise:


def t_embed(t):  # t: (n,) integer timesteps -> (n, 5) features
    ts = t.float() / T
    return torch.stack([ts, torch.sin(2 * torch.pi * ts), torch.cos(2 * torch.pi * ts),
                        torch.sin(8 * torch.pi * ts), torch.cos(8 * torch.pi * ts)], dim=1)

net = nn.Sequential(nn.Linear(7, 128), nn.ReLU(), nn.Linear(128, 128), nn.ReLU(),
                    nn.Linear(128, 2))          # predicts the noise eps
opt = torch.optim.Adam(net.parameters(), lr=1e-3)
  
xtt_embed(t)Linear(7, 128)ReLULinear(128, 128)ReLULinear(128, 2)pred(n, 7)(n, 128)(n, 128)(n, 128)(n, 128)(n, 2)(n, 2)(n, 5)side by sideone noise estimate per coordinate
  • t_embed gives the step as \(t/T\) and four sines and cosines: (n, 5), the same idea as S16's sinusoidal positional encodings.
  • nn.Linear(7, 128) takes 7 inputs: the 2 coordinates of xt and the 5 step features. The last layer returns 2 values, one noise estimate per coordinate.

Training runs Part 3's step 4,000 times

Each pass is the training step of Part 3, on a batch of 256:


for step in range(4000):
    x0 = data[torch.randint(0, len(data), (256,))]
    t = torch.randint(0, T, (256,))
    eps = torch.randn_like(x0)
    xt = alpha_bar[t, None].sqrt() * x0 + (1 - alpha_bar[t, None]).sqrt() * eps
    pred = net(torch.cat([xt, t_embed(t)], dim=1))
    loss = ((pred - eps) ** 2).mean()  # mean over batch and both coordinates
    opt.zero_grad(); loss.backward(); opt.step()
    if step % 1000 == 0 or step == 3999:
        print(f"step {step:4d}  denoising loss {loss.item():.4f}")
  

step    0  denoising loss 0.9931
step 1000  denoising loss 0.3516
step 2000  denoising loss 0.3581
step 3000  denoising loss 0.3481
step 3999  denoising loss 0.3213
  
  • alpha_bar[t, None] is (256, 1), broadcast over the two coordinates of x0, (256, 2).
  • The network sees xt beside t_embed(t), (256, 7); pred is (256, 2), one noise estimate per coordinate.
  • From 0.99, close to the 1 that predicting zero would score (Part 3's self-check), to about 0.35 by step 1,000 (single batches 0.32–0.36), then a plateau: the floor of Part 3, the noise that cannot be recovered at small \(t\).

Sampling runs Part 3's step from the last index down to 0

Start 2,000 points at pure noise and apply the sampling step 200 times (this step-by-step sampler is called ancestral sampling):


# Ancestral sampling: start from pure noise, denoise step by step
with torch.no_grad():
    x = torch.randn(2000, 2)
    for t in reversed(range(T)):
        tt = torch.full((2000,), t)   # 2,000 copies of t
        eps_hat = net(torch.cat([x, t_embed(tt)], dim=1))
        x = (x - betas[t] / (1 - alpha_bar[t]).sqrt() * eps_hat) / alphas[t].sqrt()
        if t > 0:
            x = x + betas[t].sqrt() * torch.randn_like(x)
  
  • tt is (2000,), so t_embed(tt) is (2000, 5) and eps_hat, the \(\hat{\boldsymbol{\varepsilon}}\), is (2000, 2).
  • Code t runs 199 down to 0, the math's \(t=T\) down to 1. The x = (x - ...) line is the formula's first term; if t > 0 adds \(\sqrt{\beta_t}\,\mathbf{z}\) at every step but the last. Sampling needs no gradients.

One batch of samples costs 200 network calls, one per step.

Judging the samples with numbers, not a picture

A scatter plot shows that samples look right, but not how far off they are, and images cannot be plotted this way. So the code compares the samples with the data twice, first by means, spreads and correlation, then by each point's distance to its nearest data point.


def stats(name, s):
    corr = torch.corrcoef(s.T)[0, 1]   # s.T is (2, 2000): one row per coordinate
    print(f"{name:>10}  mean ({s[:, 0].mean():+.4f}, {s[:, 1].mean():+.4f})  "
          f"std ({s[:, 0].std():.4f}, {s[:, 1].std():.4f})  corr(x1,x2) {corr:+.4f}")

stats("data", data)
stats("samples", x)
stats("N(0, I)", torch.randn(2000, 2))

# Average distance from each sample to its nearest data point
holdout = two_moons(2000)   # fresh points, never trained on
for name, s in [("held-out data", holdout), ("model samples", x),
                ("N(0, I) noise", torch.randn(2000, 2))]:
    d = torch.cdist(s, data).min(dim=1).values.mean()
    print(f"mean nearest-data distance, {name:>14}: {d.item():.4f}")
  
  • torch.cdist(s, data) is (2000, 4000), every sample's distance to every data point; .min(dim=1).values keeps each row's smallest.

Held-out data and noise give the two reference scores

Before the printout, a prediction.

Held-out data shows what a perfect model scores, and plain noise what the starting point scores before any denoising. Where should good samples land?


      data  mean (+0.0000, +0.0000)  std (1.0000, 1.0000)  corr(x1,x2) -0.4531
   samples  mean (+0.0429, -0.0370)  std (0.9788, 1.0005)  corr(x1,x2) -0.4410
   N(0, I)  mean (+0.0095, +0.0371)  std (0.9841, 0.9846)  corr(x1,x2) -0.0200
mean nearest-data distance,  held-out data: 0.0162
mean nearest-data distance,  model samples: 0.0480
mean nearest-data distance,  N(0, I) noise: 0.2544
  
  • Means and standard deviations cannot tell the samples from noise: all three rows are near 0 and 1. The correlation between the two coordinates can: the samples reach −0.44, against the data's −0.45 and the noise's −0.02 (the two coordinates of \(\mathcal{N}(\mathbf{0},\mathbf{I})\) are independent).

The samples learn the shape but sit farther from the data than held-out points

The three point sets behind the previous page's distances, then its printout on two number lines:

held-out data: 0.0162model samples: 0.0480N(0, I) noise: 0.2544Every 8th of eachset's 2,000 points,from the run thatprinted the numbers.
corr(x1,x2), read off the previous page's tableFrom noise at −0.0200, the sampler ends at−0.4410, next to the data at −0.4531.−0.50datasamplesN(0, I)mean nearest-data distance00.25held-outsamplesnoise5× closer than noise (0.0480 against 0.2544)3× farther than held-out data(0.0480 against 0.0162)

Both facts came from a table, which still works when the data has too many dimensions to plot.

Self-check on judging the tiny model

Two questions on Part 4.

(a) Another model's samples sit at the held-out distance, 0.016, but their coordinate correlation is near 0, not −0.45. What might they be doing?

(b) The loss levels off near 0.35. Should you tune to push it lower?

(a) Lying on the data without covering it: for example, all on one moon, S24's mode collapse (a whole moon is symmetric about its own middle, so its correlation is near 0: 0.01 for the outer moon, −0.04 for the inner).

(b) No: most of it is Part 3's floor, the noise that cannot be recovered at small \(t\). Judge by the samples' table.

A table against held-out data and noise judges the samples, but sampling took 200 calls.

DDIM keeps the network and samples deterministically in fewer steps

Part 5 · Faster, steered, at scale. How is sampling made faster? Sampling took 200 network calls per batch here, against one in a GAN (S24). DDIM (Denoising Diffusion Implicit Models; Song, Meng & Ermon, ICLR 2021) keeps the trained network and changes only the sampler:

A first guess of the clean point from pure noise is poor. So DDIM repeats: at each step it visits, ask the network once, guess the clean point, and mix that guess with the same noise at the next step's level; the network then sees a slightly cleaner input.

  1. Predict \(\hat{\boldsymbol{\varepsilon}}\) at step \(t\) and form Part 3's \(\hat{\mathbf{x}}_0=(\mathbf{x}_t-\sqrt{1-\bar\alpha_t}\,\hat{\boldsymbol{\varepsilon}})/\sqrt{\bar\alpha_t}\).
  2. Noise it again to the next step you visit, \(s\lt t\), with the same \(\hat{\boldsymbol{\varepsilon}}\), using the closed form, which holds at any step: \(\mathbf{x}_s=\sqrt{\bar\alpha_s}\,\hat{\mathbf{x}}_0+\sqrt{1-\bar\alpha_s}\,\hat{\boldsymbol{\varepsilon}}\).
  3. No fresh noise (DDIM's noise weight \(\eta=0\)): a deterministic map from \(\mathbf{x}_T\) to a sample, and \(s\) need not be \(t-1\).

With 10 steps, DDIM calls the network at 10 of the 200 steps

The steps one batch of samples passes through, from \(t=T\) on the left down to the sample on the right:

199176154132110886644220Gray ticks: DDPM's 200 steps, one network call each.Blue: DDIM with 10 steps, one network call at each blue dot, torch.linspace(T - 1, 0, 10).long().
samplernetwork callssteps it visits
DDPM200every step
DDIM, 50 steps50about every 4th
DDIM, 20 steps20about every 10th
DDIM, 10 steps10about every 22nd

Training is unchanged; the sampler visits 50, 20 or 10 steps instead of 200.

In code, DDIM guesses the clean point and re-noises it at each visited step

Reading 4.3's sampler, run with the network trained in Part 4:


def ddim_sample(n, n_steps):
    ts = torch.linspace(T - 1, 0, n_steps).long()      # strided timestep subsequence
    x = torch.randn(n, 2)
    for i, t in enumerate(ts):
        tt = torch.full((n,), t.item())
        eps_hat = net(torch.cat([x, t_embed(tt)], dim=1))
        x0_hat = (x - (1 - alpha_bar[t]).sqrt() * eps_hat) / alpha_bar[t].sqrt()
        ab_prev = alpha_bar[ts[i + 1]] if i + 1 < len(ts) else torch.tensor(1.0)
        x = ab_prev.sqrt() * x0_hat + (1 - ab_prev).sqrt() * eps_hat   # eta = 0
    return x
  
  • ts is the strided list, (n_steps,); .long() drops the fraction, so 10 steps visit 199, 176, 154, …, 0 (the previous page's figure). The x0_hat line guesses the clean point; the last line mixes it with the same eps_hat at the next step's level, with ab_prev as \(\bar\alpha_s\).
  • After the last visited step, ab_prev is 1: the sample is x0_hat itself.

DDIM loses little down to 10 steps, then a lot

Reading 4.3's script retrains Part 4's network (same seed, so the same weights) and scores 2,000 points per row, with random draws of its own. NN dist is Part 4's mean nearest-data distance (NN: nearest neighbor):


       sampler  NN dist  corr(x1,x2)  (denoiser calls)
 held-out data   0.0152      -0.4166
      DDPM 200   0.0485      -0.4417  (200)
       DDIM 50   0.0482      -0.4485  (50)
       DDIM 20   0.0521      -0.4755  (20)
       DDIM 10   0.0574      -0.4899  (10)
        DDIM 5   0.0900      -0.5854  (5)
        DDIM 2   0.2489      +0.0386  (2)
  
2510205020000.10.2network calls (log scale)NN dist, read off the tableheld-out data, 0.0152DDPM 200DDIM2 steps: 0.24895: 0.0900
  • In this run, 50 steps come close to 200 (0.0482 against 0.0485) with four times fewer calls; 10 are worse but usable; at 2 the distance jumps to 0.2489 and the correlation falls to about 0.
  • Error grows slowly with the stride, then sharply below 10 steps. Production systems use 20–50 steps, or train a second network to imitate the sampler in 1–4 steps (distillation).

Classifier-free guidance runs one network with and without the label

So far we sample a point, not one we ask for: nothing says which moon it comes from. Classifier-free guidance (Ho & Salimans, 2022) lets us ask:

  • The network gets one more input, a label \(c\) (here, which moon).
  • Training sets the label to 0 for a random 15% of the examples. Without this the network would never see an input with no label, and its prediction without the label would be untrained.
  • \(\boldsymbol{\varepsilon}_{\text{cond}}\) is the network's prediction with the label, and \(\boldsymbol{\varepsilon}_{\text{uncond}}\) its prediction without it.
  • At sampling time each step runs the network twice, with the label and without it:
xt​, t, the label cthe network εθ​εcond​ = εθ​(xt​, t, c)xt​, t, no label (c = 0)the same network εθ​εuncond​ = εθ​(xt​, t, 0)

Dropping the label in training is what lets one network make both predictions.

Guidance multiplies the label's effect on the prediction by \(s\)

Sampling combines the previous page's two predictions with a guidance scale \(s\) (from here on \(s\) is this scale, no longer DDIM's step):

\[\boldsymbol{\varepsilon}_{\text{guided}}=\boldsymbol{\varepsilon}_{\text{uncond}}+s\,\big(\boldsymbol{\varepsilon}_{\text{cond}}-\boldsymbol{\varepsilon}_{\text{uncond}}\big)\]
00.20.40.60.81−0.4−0.200.20.40.60.810.30.4εuncond​, s = 0εcond​, s = 1εguided​, s = 2
  • An example, drawn to scale. The label's effect is the difference of the two predictions: \((0.5,0.3)-(0.2,-0.1)=(0.3,0.4)\).
  • \(s=0\) gives the unconditional prediction, and \(s=1\) the conditional one.
  • \(s\gt1\) goes past the conditional prediction. At \(s=2\): \((0.2,-0.1)+2\,(0.3,0.4)=(0.8,0.7)\).

A larger \(s\) amplifies the part of the prediction that the label is responsible for.

Training sets the label to 0 for a random 15% of each batch

How does training drop the label? It keeps every example and changes only the label that the network sees:

\[L=\mathbb{E}\big[\lVert\boldsymbol{\varepsilon}-\boldsymbol{\varepsilon}_\theta(\mathbf{x}_t,t,\tilde c)\rVert^2\big]\]
  • \(\tilde c\) is the label after dropping: 0 with probability 0.15, and otherwise \(c\), which is +1 or −1. This is Part 3's loss with one more input to the network.
  • Part 4's training loop changes in three places: it reads the label, sets it to 0 for about 15% of the batch, and feeds it to the network as an 8th input (nn.Linear(8, 128)).

Every example stays in the batch and in the loss; only its label input is set to 0, with probability 0.15.

In code, the label enters Part 4's training loop

The previous page's three changes in code; the full script is in reading 4.3:


for step in range(4000):
    idx = torch.randint(0, len(data), (256,))
    x0, y = data[idx], labels[idx]
    c = torch.where(y == 0, 1.0, -1.0)
    c = c * (torch.rand(256) > 0.15).float()      # drop the label 15% of the time
    t = torch.randint(0, T, (256,))
    eps = torch.randn_like(x0)
    xt = alpha_bar[t, None].sqrt() * x0 + (1 - alpha_bar[t, None]).sqrt() * eps
    pred = net(torch.cat([xt, t_embed(t), c[:, None]], dim=1))
    loss = ((pred - eps) ** 2).mean()
    opt.zero_grad(); loss.backward(); opt.step()
  
  • labels holds each point's moon, 0 for the outer and 1 for the inner, so torch.where(y == 0, 1.0, -1.0) makes c +1 on the outer moon and −1 on the inner.
  • (torch.rand(256) > 0.15).float() is 0 for about 15% of the batch, so those examples get c = 0, which means no label; they stay in the batch and in the loss.

The guided sampler calls the network twice per step

Where does the guided prediction enter sampling? This is Part 4's sampling loop with three new lines: the network runs with the label (eps_c), runs with 0 for no label (eps_u), and the previous page's formula combines them (eps_hat).


def sample_guided(n, scale, target=1.0):
    """DDPM sampling with classifier-free guidance toward c = target."""
    x = torch.randn(n, 2)
    for t in reversed(range(T)):
        tt = torch.full((n,), t)
        feats = t_embed(tt)
        eps_c = net(torch.cat([x, feats, torch.full((n, 1), target)], dim=1))
        eps_u = net(torch.cat([x, feats, torch.zeros(n, 1)], dim=1))
        eps_hat = eps_u + scale * (eps_c - eps_u)
        x = (x - betas[t] / (1 - alpha_bar[t]).sqrt() * eps_hat) / alphas[t].sqrt()
        if t > 0:
            x = x + betas[t].sqrt() * torch.randn_like(x)
    return x
  
  • torch.full((n, 1), target) is a column of n copies of target (1.0, the outer moon), and scale is \(s\).

As guidance grows, purity rises and the spread shrinks below the data's

Reading 4.3's script draws 2,000 samples at each of five scales, always asking for the outer moon. Purity is the share of samples whose nearest data point is on the outer moon; NN dist is the mean distance to the nearest outer-moon point; spread is the mean per-coordinate standard deviation.


 scale  purity  NN dist  spread
   0.0   0.468   0.4389  1.0041
   1.0   0.997   0.0232  0.7140
   2.0   1.000   0.0161  0.6390
   4.0   1.000   0.0140  0.5776
   8.0   1.000   0.0137  0.5155
outer-moon data spread: 0.7294
  
  • \(s=1\) already matches the outer moon: purity 0.997, and spread 0.714 against the moon's own 0.729.
  • Above 1, purity reaches 1.000 and samples sit tighter on the moon (distance 0.023 down to 0.014), but the spread keeps shrinking past the data's own, to 0.52 at \(s=8\), about 30% below it.

At scale 8 the samples leave the ends of the moon uncovered

Three rows of the previous page's table as pictures: every 8th of the 2,000 samples in purple, over the data in gray (the outer moon darker); the outer moon's own spread is 0.73.

scale 0purity 0.468, spread 1.00scale 1purity 0.997, spread 0.71scale 8purity 1.000, spread 0.52
  • Text-to-image systems use scales around 5–10, chosen by a sweep like this one.

A larger \(s\) raises purity and lowers the spread: the samples match the label more closely and cover less of the moon.

Stable Diffusion runs the same steps in a latent space

A photograph has hundreds of thousands of values, so every one of the many network calls is expensive. Stable Diffusion keeps today's steps and changes the components:

Stable Diffusion's design (latent diffusion)noise in thelatent spacethe network: a larger one (a U-Netor a transformer) instead of the MLP,with proper time embeddings and asmoother β schedulemany steps; fast samplers such as DDIMneed dozens instead of a thousandclass or text embeddingconditioning; classifier-freeguidance amplifies the label's effectcleanlatentdecoderimageThe latent holds far fewer valuesthan the image. The decoder belongsto the autoencoder (a VAE, S23) thatcompressed the images; VAEs remain acomponent of production systems.Smoother β schedule: Nichol & Dhariwal, ICML 2021. Guidance: Ho & Salimans, 2022. Latent diffusion: Rombach et al., CVPR 2022.DDIM (Denoising Diffusion Implicit Models): Song, Meng & Ermon, ICLR 2021.
  • Latent diffusion runs the denoising in a compressed autoencoder latent, so each network call works on far fewer values; it is Stable Diffusion's design. "Stable" is a product and model name from Stability AI, not a claim about training stability.

DDIM cuts the calls, guidance trades diversity for adherence, a latent space cuts compute.

Each generative family has one strength and one weakness

Part 6 · Close. Which of the three families should you use? Compare them across S23–S25 (reading 4.3); coverage and fidelity are S24's recall and precision:

familytrainingsamplingstrengthweakness
VAEstable (a likelihood bound)one decoder passa usable latent spaceblur
GANan adversarial gameone forward passsharp samplesunstable training, mode collapse
diffusionstable (regression on noise)many stepscoverage and fidelityslow, iterative sampling

Modern systems combine them. A VAE supplies the latent space and diffusion generates in it; some also train a second network adversarially to imitate the sampler in 1–4 steps (adversarial distillation), for speed.

No family is best in every column, so modern systems combine them.

Six mistakes in your own diffusion runs, each with its cause and its fix

Reading 4.3's pitfalls; the second (in bold) is the one today's Part 2 worked through:

symptomcausefix
the loss levels off above zero, and you keep tuningthe noise objective has a floor well above zerojudge by sampling and distribution statistics
nothing errors, yet \(\mathbf{x}_T\) still correlates with the data (corr 0.35 at \(T=200\), Part 2)\(T\) changed, \(\beta\) schedule kept: the noising does not finishcheck sqrt(a_bar) and corr(x_T, x0); rescale beta_max with \(T\)
DDPM sampling gives over-smoothed samplesthe fresh noise \(\mathbf{z}\) omitted, or the wrong varianceimplement the chosen variance exactly; do not mix in DDIM's update
training diverges or starts at an enormous lossa data scale far from the noise's unit scalestandardize first, undo it after sampling
striding DDPM's sampling step degrades samples even at many stepsits coefficients hold only for adjacent stepsuse DDIM's update for a strided list
guided samples score well but all look alikea high guidance scale shrinks the spreadsweep \(s\); report purity and spread at a stated scale

Today's answer takes the title page's question clause by clause

Back to the title page's question.

  • What the noising does: \(\mathbf{x}_t=\sqrt{\bar\alpha_t}\,\mathbf{x}_0+\sqrt{1-\bar\alpha_t}\,\boldsymbol{\varepsilon}\). The signal shrinks and the noise grows, the scale stays 1 for standardized data, and any \(t\) is one jump away.
  • What the schedule must get right: finish the noising. \(\sqrt{\bar\alpha_T}\approx e^{-\frac12\sum_t\beta_t}\), so \(T\) and the \(\beta\) range are one decision; reprint the statistics of \(\mathbf{x}_T\) whenever either changes.
  • What the network learns: the noise, by mean squared error onto a target we drew, which is why training is stable; the loss levels off above zero. Sampling runs the noising step backwards, 200 network calls for 200 steps.
  • How to judge it: a table against held-out data and noise; the tiny model learned the shape, three times farther from the data than held-out points.
  • Faster, steerable, practical: DDIM skips steps, and 10 network calls lose little against 200; guidance makes samples match the label more closely and lowers their spread; latent diffusion denoises in an autoencoder's latent.

For next time (after Fall Recess)

  • Next session: S26, the Monday after Fall Recess: efficiency and scale, what it costs to train and to run a model.
  • Read over the break: 4.4 Efficiency and Scale.
  • Optional: reading 4.3's Try it yourself #2, which applies DDPM's sampling step at every 4th step only: expect worse samples, as in the fifth row of today's table of mistakes.