No jobs
Core 12 min 2 of 4

Learning to undo one step

The network never returns an image. It supplies the one missing term of a posterior that a sampler then integrates.

What this repairs

Believing the network denoises an image in one shot, when it estimates one term of a posterior that a sampler then integrates.

Reversing the forward process means sampling from q(xt1xt)q(x_{t-1} \mid x_t) , and that distribution is hopeless. It depends on the distribution of all natural images: to know what the slightly-less-noisy version of a noisy patch looked like, you have to know what patches exist in the world.

But there is a conditional that is tractable. If you also knew x0x_0 — the clean image — then q(xt1xt,x0)q(x_{t-1} \mid x_t, x_0) is Gaussian with a mean and a variance you can write down in closed form, because both of the densities it is built from are Gaussians you already have.

We do not have x0x_0 . So we estimate it. That sentence is the entire derivation of the training objective, and it is the one that gets skipped: the network is not inverting the forward process, it is supplying the single unavailable term of a posterior whose other parts are known exactly.

The posterior that is available

  1. q(xt1xt,x0)=q(xtxt1,x0)  q(xt1x0)q(xtx0)q(x_{t-1} \mid x_t, x_0) = \frac{q(x_t \mid x_{t-1}, x_0)\; q(x_{t-1} \mid x_0)}{q(x_t \mid x_0)}

    Bayes, conditioned on x₀ throughout. Nothing has been assumed yet; this is a rearrangement of the definition of conditional probability.

  2. q(xtxt1,x0)=q(xtxt1)q(x_t \mid x_{t-1}, x_0) = q(x_t \mid x_{t-1})

    The forward process is Markov by construction, so conditioning on x₀ as well tells the step nothing new. This is why the numerator is made only of things the previous concept already wrote down.

  3. exp ⁣((xtαtxt1)22βt(xt1αˉt1x0)22(1αˉt1))\propto \exp\!\left(-\frac{(x_t - \sqrt{\alpha_t}\,x_{t-1})^2}{2\beta_t} - \frac{(x_{t-1} - \sqrt{\bar{\alpha}_{t-1}}\,x_0)^2}{2(1-\bar{\alpha}_{t-1})}\right)

    Both surviving factors are Gaussian in x_{t−1} — one from the single step, one from the closed form — and the denominator does not contain x_{t−1} at all, so it is a normalising constant.

  4. μ~t(xt,x0)=αˉt1βt1αˉtx0  +  αt(1αˉt1)1αˉtxt\tilde{\mu}_t(x_t, x_0) = \frac{\sqrt{\bar{\alpha}_{t-1}}\,\beta_t}{1-\bar{\alpha}_t}\,x_0 \;+\; \frac{\sqrt{\alpha_t}\,(1-\bar{\alpha}_{t-1})}{1-\bar{\alpha}_t}\,x_t

    A product of two Gaussians in the same variable is a Gaussian; completing the square in x_{t−1} gives its mean. Note the shape of the answer — it is a weighted blend of the clean image and the sample you already hold, not a correction applied to one of them.

  5. β~t=1αˉt11αˉtβt\tilde{\beta}_t = \frac{1-\bar{\alpha}_{t-1}}{1-\bar{\alpha}_t}\,\beta_t

    The variance falls out of the same completion of the square, and it depends on the schedule alone — not on the image, not on the network, and not on anything that has to be learned.

  6. pθ(xt1xt)=N ⁣(μ~t(xt,x^0(xt,t)), β~tI)p_\theta(x_{t-1} \mid x_t) = \mathcal{N}\!\left(\tilde{\mu}_t\big(x_t, \hat{x}_0(x_t, t)\big),\ \tilde{\beta}_t I\right)

    The whole model, in one line: take the exact posterior and substitute an estimate for the one term you cannot observe. Everything else on this page is known in closed form before training starts.

From a KL divergence to a plain squared error

  1. Lt1=DKL ⁣(q(xt1xt,x0)  pθ(xt1xt))\mathcal{L}_{t-1} = D_{\mathrm{KL}}\!\left(q(x_{t-1} \mid x_t, x_0)\ \|\ p_\theta(x_{t-1} \mid x_t)\right)

    The variational bound decomposes into one of these per timestep. This is where the objective actually comes from, and it is a divergence between distributions rather than an error on an image.

  2. =12β~tμ~tμθ2+const= \frac{1}{2\tilde{\beta}_t}\left\lVert \tilde{\mu}_t - \mu_\theta \right\rVert^2 + \text{const}

    Both sides are Gaussians with one and the same fixed variance, because we chose p_θ that way. The KL between two equal-variance Gaussians is just the squared distance between their means — so a divergence becomes an L2, and it is the variance choice that did it.

  3. =αˉt1βt22β~t(1αˉt)2x0x^02= \frac{\bar{\alpha}_{t-1}\,\beta_t^{2}}{2\tilde{\beta}_t\,(1-\bar{\alpha}_t)^{2}}\left\lVert x_0 - \hat{x}_0 \right\rVert^2

    Substitute the posterior mean for both. The two means differ only in their x₀ slot, so everything else cancels and the coefficient in front of x₀ comes out squared.

  4. =βt22β~tαt(1αˉt)εε^2= \frac{\beta_t^{2}}{2\tilde{\beta}_t\,\alpha_t\,(1-\bar{\alpha}_t)}\left\lVert \varepsilon - \hat{\varepsilon} \right\rVert^2

    Reparameterise x₀ through the closed form, x₀ = (x_t − √(1−ᾱ)ε)/√ᾱ. Predicting the noise and predicting the image are the same task in different coordinates, and this line is where that first shows up.

  5. Lsimple=Et[εε^2]\mathcal{L}_{\text{simple}} = \mathbb{E}_{t}\left[\left\lVert \varepsilon - \hat{\varepsilon} \right\rVert^2\right]

    And then the weight is thrown away. This is a choice, not an identity: the unweighted loss is no longer the variational bound, it up-weights the high-noise timesteps relative to it, and it trains better. Which weighting you are implicitly choosing is the subject of the next concept.

Check yourself

Your network emits a perfect ε̂ at t = 999 — the exact noise that was added. Why is the image not finished?

Show answer

Because a perfect ε^\hat{\varepsilon} at t=999t = 999 still only tells the sampler where to move by 0.08%0.08\% of the distance to x^0\hat{x}_0 . The posterior q(x998x999,x0)q(x_{998} \mid x_{999}, x_0) is a distribution over slightly-less-noisy images, not over clean ones, and μ~\tilde{\mu} is dominated by the xtx_t term you already had.

There is a sharper version of the same answer. The network's output is only used to choose a distribution; the sampler then draws from it, adding β~t\sqrt{\tilde{\beta}_t} of fresh noise back in. Even a perfect network run at every timestep does not produce a deterministic image under DDPM — it produces a draw from the data distribution, which is the entire point of a generative model and the thing an L2L2 regressor cannot do.

Euler View - ML Experiment Monitor