Chapter 4: Reverse Process & Denoising
The reverse process is where the magic happens: starting from pure noise, a neural network learns to iteratively denoise, reconstructing data step by step. This chapter covers score functions, denoising score matching, the reverse SDE, the DDPM training objective, noise prediction parameterizations, and loss weighting strategies.
- Topics
- 6
- Demo
- 1
- Videos
- 3
- Min read
- 35
Chapter Overview
The forward process systematically destroys data by adding noise. The reverse process learns to undo this destruction, transforming pure Gaussian noise into structured data samples. This is the generative core of diffusion models: if we can accurately reverse each noising step, we can generate new data by starting from random noise and iteratively denoising.
The key mathematical object is the score function ---the gradient of the log-density of the noisy data distribution at time . Anderson's theorem (1982) proves that knowing the score function at every time is sufficient to reverse the forward SDE exactly. Since we cannot compute the score analytically (it requires knowing the full data distribution), we train a neural network to approximate it.
Denoising score matching provides an elegant training objective: instead of estimating the score directly, we can equivalently train the network to predict the noise that was added to a clean sample to produce a noisy sample . This connection---score estimation equals noise prediction---is the foundation of DDPM and all modern diffusion models.
This chapter covers:
- Score Functions: The gradient of the log-density and its role in generative modeling
- Denoising Score Matching: Training neural networks to estimate scores via noise prediction
- The Reverse SDE: Anderson's theorem and the reverse-time diffusion process
- DDPM Training Objective: The simplified loss function that makes training practical
- Parameterizing the Noise Predictor: -prediction vs -prediction vs -prediction
- Loss Weighting Strategies: How different timestep weightings affect sample quality
Chapter Roadmap
Click any topic to jump in
Score Functions
∇ₓ log p(x) — the key quantity defining how to reverse diffusion.
Score matching and SDE reversal
Denoising Score Matching
Learning the score by predicting noise — avoiding intractable normalizing constants.
Reverse SDE
The reverse process is also an SDE, determined by forward SDE and the score.
Loss and architecture
DDPM Objective
Predicting noise ε at each timestep — equivalent to score matching.
Noise Predictor
U-Net with time embedding, self-attention, and skip connections.
Loss Weighting
Uniform, SNR-weighted, min-SNR — balancing the loss across timesteps.
Topics
6 topics in this chapter
The forward-process chapter taught us to destroy data: any sample becomes pure Gaussian noise through the reparameterized kernel . Generation demands the opposite, turning noise back into data, and that reversal needs a quantity we have not yet met: the score function , the gradient of the log-density. The problem it solves is fundamental. To sample from a distribution we would normally need its density , but computing requires an intractable normalizing integral over all possible data. The score sidesteps this entirely: it points toward higher-probability regions, it can be estimated from samples alone, and the normalizing constant cancels out of the gradient. This topic first defines the score and its geometry for a single Gaussian, then examines the far richer multimodal structure of a Gaussian mixture, and finally connects the score at any noise level to the Bayesian optimal denoiser, the key identity that makes the entire reverse process learnable from data.
Definition
The score function is the gradient of the log-probability density with respect to . It is a vector field pointing toward regions of higher likelihood, independent of the intractable normalizing constant, so it can be estimated from data samples alone. Knowing the score at every noise level suffices to reverse the diffusion process.
In this topic
- 1Definition and Geometric Meaning
- 2Score of a Gaussian Mixture
- 3Score for Noisy Distributions
Definition and Geometric Meaning
The score function is the gradient of the log-density. At any point in data space, it gives a vector pointing toward higher probability regions. For a Gaussian , the score is , always pointing toward the mean . The magnitude is larger far from the mean (strong pull) and smaller near the mean (weak pull). This gradient field defines a vector field over the entire data space.
The score is a vector field over the entire data space. For a Gaussian , the score is , a linear restoring force toward the mean. Crucially, the score does not depend on the normalizing constant , because . This is what makes score-based methods tractable: we avoid the intractable partition function entirely.
Compute the score function for a 1D Gaussian at .
Score of a Gaussian Mixture
For a mixture of Gaussians, the score is a posterior-weighted average of the individual component scores, where the weights are the responsibilities, the probability that each component generated . Near component the score is dominated by that component's linear pull toward ; between components the score interpolates, steering toward whichever mode is nearest. This multimodal structure is exactly what makes score estimation hard: the network must learn a complex, spatially varying vector field with basins around every mode and unstable saddle points between them. It connects directly to the single-Gaussian case from the previous concept, which is the special one-component limit where the responsibilities collapse to one.
For a mixture , the score is a posterior-weighted average: where are the responsibilities. Between modes, the score interpolates and can be zero at saddle points. The score field reveals the topology of the distribution: basins of attraction around modes, separatrices between them.
For a 50-50 mixture of and , what is the score at ?
Score for Noisy Distributions
At noise level the score relates directly to the conditional expectation of the clean data given the noisy observation. Because , the score points from toward the posterior mean , rescaled by the noise variance . This reveals the identity at the heart of the chapter: estimating the score is equivalent to estimating the denoised sample , the Bayesian optimal denoiser. The connection, formalized by Tweedie's formula, means a network trained simply to denoise implicitly learns the score, which is what the next topic exploits.
Tweedie's formula connects the score to the optimal denoiser: . Rearranging gives . This is the fundamental identity: the score equals the posterior-expected noise scaled by , making noise prediction equivalent to score estimation.
If and the model predicts given , what is the estimated score?
Theory Exercise
Problem:
Show that for data with the forward process , the score of the marginal distribution satisfies in expectation over given , where is the noise used to generate .
Hints:
- Start from $q(x_t | x_0) = \mathcal{N}(x_t; \sqrt{\bar{\alpha}_t}\, x_0, (1 - \bar{\alpha}_t) I)$
- The score of a Gaussian $\mathcal{N}(\mu, \sigma^2 I)$ is $-(x - \mu)/\sigma^2$
- Use Tweedie's formula: $\mathbb{E}[x_0 | x_t] = (x_t + (1 - \bar{\alpha}_t) \nabla_{x_t} \log p_t(x_t)) / \sqrt{\bar{\alpha}_t}$
Related Problems on PixelBank
The previous topic ended on a tantalizing identity: the score of the noisy distribution equals the negative expected noise, rescaled. But it left a practical gap. We cannot train a network by directly matching , because that true score depends on the unknown data density we set out to avoid computing in the first place. Denoising score matching, introduced by Vincent in 2011, closes the gap with a beautiful trick. Instead of matching the intractable marginal score, we match the score of the known noise kernel , which is simply , a quantity we can compute exactly for every training sample. The theorem guarantees these two objectives share the same optimum, so a network that learns to denoise recovers the true score for free. This topic builds the argument in three steps: the ideal but intractable score matching objective, the denoising score matching theorem that replaces it, and the final reduction to plain noise prediction that DDPM actually implements.
Definition
Denoising score matching trains a network to match the score of the tractable noise kernel , rather than the intractable marginal score . The two objectives share the same optimum, so a network that learns to denoise noisy samples provably recovers the true score, reducing score estimation to simple noise prediction.
In this topic
- 1The Score Matching Objective
- 2Denoising Score Matching Theorem
- 3From Score Matching to Noise Prediction
The Score Matching Objective
The ideal objective is to minimize the expected squared error between the model's score and the true score. However, this requires knowing , which is intractable. The seminal insight of score matching (Hyv"arinen, 2005) is that this objective can be rewritten using integration by parts to avoid computing the true score, but the resulting expression involves the Hessian trace of , which is expensive. Denoising score matching provides a simpler alternative.
The explicit score matching loss is intractable because requires knowing . Hyvärinen (2005) showed via integration by parts that this equals , avoiding the true score but requiring the Jacobian trace, which is for -dimensional data. Denoising score matching avoids both issues.
Why can't we directly minimize using training data?
Denoising Score Matching Theorem
The denoising score matching loss is equivalent to the true score matching loss up to a constant. Instead of matching the intractable true score, we match the score of the noise kernel , which is simply . At the optimum, for all and . The proof relies on the fact that .
The DSM loss equals the true score matching loss up to a -independent constant. The proof uses the tower property: . The cross-terms match, so the objectives have the same optimizer: .
Show that minimizing the DSM loss over yields the true marginal score at the optimum.
From Score Matching to Noise Prediction
Rather than parameterizing the score network directly, DDPM parameterizes a noise-prediction network and defines the score implicitly through . Substituting this into the denoising score matching loss collapses everything to : just predict the noise. This reparameterization is both simpler and numerically better conditioned than regressing the score directly, because the target has unit variance at every timestep whereas the score magnitude blows up as . It is the direct payoff of the theorem in the previous concept, turning an abstract score-matching guarantee into the concrete mean-squared-error objective used in practice.
Reparameterizing absorbs the timestep-dependent scaling into the loss. The DSM loss becomes . Dropping the weighting gives the DDPM simple loss, which empirically outperforms the correctly-weighted version. This works because has unit variance at all , providing a well-conditioned regression target.
If predicts at , what is the implied score estimate?
Theory Exercise
Problem:
Prove that the denoising score matching objective differs from the true score matching objective only by a constant independent of .
Hints:
- Expand both squared norms and compare term by term
- The cross-term in DSM involves $\mathbb{E}_{x_0|x_t}[\nabla_{x_t} \log q(x_t|x_0)]$
- Use the identity $\nabla_{x_t} \log p_t(x_t) = \mathbb{E}_{q(x_0|x_t)}[\nabla_{x_t} \log q(x_t|x_0)]$
Related Problems on PixelBank
We now have a way to learn the score at every noise level. The remaining question is mechanical but deep: given the score, how do we actually run the process backward, turning a sample of pure noise into data? The answer is Anderson's theorem from 1982, a result in stochastic calculus that predates diffusion models by decades. It states that any forward SDE which carries data to noise has a companion reverse-time SDE that carries noise back to data, and the two differ only by a single extra term built from the score function . Everything the reverse process needs is therefore the one quantity the previous two topics taught us to estimate. This topic works through three consequences. First, Anderson's reverse SDE itself and how its score-correction term fights the forward noise. Second, the deterministic probability flow ODE that shares the same marginals but removes all randomness, enabling exact likelihoods and fast solvers. Third, how we discretize the continuous reverse process into the concrete DDPM sampling step that runs on hardware.
Definition
The reverse SDE runs the diffusion backward in time from noise to data. It shares the forward drift and diffusion but adds a score-correction term that steers each step toward higher-probability regions. Its only unknown is the score, which the trained network supplies, making generation possible.
In this topic
- 1Anderson's Reverse-Time SDE
- 2The Probability Flow ODE
- 3Discretizing the Reverse Process
Anderson's Reverse-Time SDE
The reverse SDE runs backward in time from to . It has the same drift and diffusion as the forward SDE, plus a correction term that fights against the noise injection. This correction term uses the score function to steer the process toward high-probability regions at each timestep. The is a reverse-time Brownian motion, which is a standard Brownian motion when time runs backward.
Anderson's theorem (1982) states that the reverse of is . The correction term exactly counteracts the entropy increase from the forward diffusion. Intuitively, the forward SDE increases entropy (adds uncertainty), while the score correction decreases entropy (adds structure). At the continuous limit, these balance to produce exact reversal.
Write the reverse SDE for the VP-SDE where and .
The Probability Flow ODE
A deterministic counterpart to the reverse SDE, the probability flow ODE generates samples from the same distribution but without randomness. It has no term. The key property is that the probability flow ODE induces the same marginal distributions at every time as the SDE. This means we can compute exact likelihoods via the change-of-variables formula (instantaneous change of variables / continuous normalizing flows). The ODE formulation also enables deterministic sampling (same initial noise always produces the same image) and more efficient solvers.
The probability flow ODE is a deterministic ODE that induces the same marginal densities as the SDE at every time . By the instantaneous change of variables formula, the log-likelihood is . This enables exact likelihood computation, deterministic encoding (mapping data to latent), and efficient adaptive-step solvers.
Compare the number of function evaluations needed for the SDE vs ODE formulation with equal sample quality.
Discretizing the Reverse Process
In practice, we discretize the reverse SDE into steps. Starting from , each step computes the predicted mean using the noise predictor and adds fresh Gaussian noise scaled by . The noise scale can be set to (matching the forward process) or where (the posterior variance). At , no noise is added () since we want a clean output.
The DDPM reverse step is the Euler-Maruyama discretization of the reverse SDE. The mean comes from replacing the score with in Anderson's formula. The variance can be (upper bound) or (posterior variance, tighter). DDIM sets , recovering the probability flow ODE.
At timestep with , , and , compute the predicted mean of .
Theory Exercise
Problem:
Derive the posterior distribution for the DDPM forward process. Show that it is Gaussian with mean and variance .
Hints:
- Apply Bayes' theorem: $q(x_{t-1}|x_t, x_0) \propto q(x_t|x_{t-1}) q(x_{t-1}|x_0)$
- Both terms on the right are Gaussians; their product is Gaussian
- Complete the square in the exponent to find the posterior mean and variance
Related Problems on PixelBank
The reverse SDE tells us how to sample once we have the score, and denoising score matching tells us the score reduces to noise prediction. This topic assembles those pieces into the actual loss function that trains a diffusion model, and shows why it is astonishingly simple. Ho and colleagues in 2020 started from the principled but intimidating variational lower bound, the same ELBO that underlies variational autoencoders, which decomposes into separate KL-divergence terms, one measuring how well the model's reverse step matches the true posterior at each timestep. The remarkable result is that when the model is parameterized as noise prediction, every one of those terms collapses to the same mean-squared error , and dropping the per-timestep weights entirely produces better samples than keeping them. This topic traces that path in three concepts: the variational lower bound and its decomposition, the simplified uniform-weight loss that makes training trivial, and the practical comparison of the two that explains why the looser bound wins on sample quality.
Definition
The DDPM training objective is the simplified loss , a uniformly weighted mean-squared error on noise prediction. It arises by simplifying the variational lower bound: every per-timestep KL term reduces to this form, and discarding the theoretical weights empirically improves sample quality while making training as simple as a denoiser.
In this topic
- 1The Variational Lower Bound
- 2Simplified Training Loss
- 3VLB vs Simple Loss in Practice
The Variational Lower Bound
Like VAEs, diffusion models maximize a variational lower bound on the log-likelihood. The bound decomposes into: (reconstruction term at ), for (denoising matching terms), and (prior matching, typically negligible). The bulk of the loss comes from the terms, which measure how well the model's reverse steps match the true posterior reverse steps.
The ELBO decomposes as where . Since both distributions are Gaussian with the same variance , each . The true posterior mean uses the known ; the model mean uses the predicted .
Why is negligible and typically ignored during training?
Simplified Training Loss
Ho et al. showed that dropping the per-timestep weighting from the VLB and using a uniform weight over all timesteps produces better samples, despite being a looser bound on the likelihood. The simplified loss samples a random timestep uniformly, generates , and trains the network to predict . This is just mean squared error on noise prediction---no KL divergences, no complex derivations at training time.
The simple loss drops the per-timestep VLB weight , using uniform weighting instead. This is a looser bound on the likelihood but produces better FID scores. The reason: VLB over-weights low-noise steps (fine details) at the expense of high-noise steps (global structure). Uniform weighting forces the model to be accurate at all noise levels, improving overall sample coherence.
Write the pseudocode for one training step of DDPM.
VLB vs Simple Loss in Practice
The VLB loss weights each timestep by a factor proportional to where . This gives more weight to low-noise timesteps (where perceptual details matter) and less weight to high-noise timesteps. The simple loss uses uniform weighting, which empirically produces better FID scores. The intuition is that uniform weighting forces the model to allocate capacity across all noise levels, including the high-noise regime where global structure is determined. Training with VLB often produces sharper but less diverse samples.
The VLB weight , which is the discrete derivative of the SNR schedule. For the linear schedule, is largest at small (low noise) where SNR changes rapidly, and smallest at large . This means VLB allocates gradient signal according to the information destruction rate. The simple loss, with , allocates uniformly. Hybrid losses with balance sample quality and likelihood.
At which timesteps does the VLB loss place the most weight, and why?
Theory Exercise
Problem:
Starting from the KL divergence term where both distributions are Gaussian, derive the expression in terms of the noise prediction . Show that with a timestep-dependent weighting.
Hints:
- KL between two Gaussians: $D_{KL}(\mathcal{N}(\mu_1,\sigma^2) \| \mathcal{N}(\mu_2,\sigma^2)) = \frac{1}{2\sigma^2}\|\mu_1 - \mu_2\|^2$
- Both the true posterior mean $\tilde{\mu}_t$ and model mean $\mu_\theta$ are linear in $x_0$ and $x_t$
- The model predicts $\hat{x}_0 = (x_t - \sqrt{1-\bar{\alpha}_t}\epsilon_\theta)/\sqrt{\bar{\alpha}_t}$
The training objective of the previous topic asked the network to predict the noise . But that is only one of several mathematically equivalent choices for what the network's output should represent, and the choice turns out to matter enormously in practice. The network could predict the noise , the clean data , a velocity , or the score directly; all are related by exact algebra, yet they induce very different gradient magnitudes and learning dynamics across timesteps. The problem is that a target which is well conditioned at one noise level can be badly conditioned at another: predicting is stable at high noise but amplifies errors catastrophically at low noise, while predicting has the opposite failure. This topic examines the three main parameterizations in turn: -prediction, the original DDPM choice; -prediction, its natural mirror image; and -prediction, the velocity target from Salimans and Ho that smoothly interpolates between the two and has become the default in modern systems like Stable Diffusion.
Definition
A parameterization is the choice of what the noise-prediction network outputs, whether the noise , the clean data , or the velocity . All are algebraically equivalent but differ in gradient conditioning across noise levels; -prediction interpolates between at low noise and at high noise for stable training throughout.
In this topic
- 1Epsilon-Prediction
- 2X0-Prediction
- 3V-Prediction
Epsilon-Prediction
The network predicts the noise that was added to the clean data to produce . The clean data is then recovered by rearranging the forward equation. This is the original DDPM parameterization and is simple to implement. At high noise levels ( small), -prediction works well because the target has constant variance across timesteps. However, at very low noise levels, the recovery amplifies errors by dividing by .
In -prediction, the target has constant unit variance at all timesteps, providing a well-conditioned regression target. However, recovering requires dividing by : . At high noise (), this division amplifies errors by . The effective loss on is , naturally upweighting low-noise steps.
If the noise predictor has MSE error at , what is the error in the prediction?
X0-Prediction
Instead of predicting noise, the network directly predicts the clean data . This is naturally better at low noise levels where , but problematic at high noise where the clean data prediction must be extracted from nearly pure noise---a much harder regression target with high variance. The loss becomes . Ramesh et al. (DALL-E 2) and some image super-resolution models use -prediction for its stability at low noise.
In -prediction, the target is the clean data itself. The loss has constant magnitude with respect to the target, but the difficulty of predicting from varies dramatically: at low noise, (trivial); at high noise, (must hallucinate from noise). Converting to -prediction loss: , so -prediction implicitly upweights high-noise steps.
At (low noise), compare the difficulty of predicting vs .
V-Prediction
Salimans & Ho (2022) introduced -prediction, where the target is a velocity-like quantity that smoothly interpolates between at high noise and at low noise. At (low noise): (behaves like -prediction). At (high noise): (behaves like -prediction). This provides the best of both worlds: stable gradients at all noise levels. Recovery: and .
The velocity is a rotation of the pair by angle . The -prediction loss decomposes as , automatically interpolating between - and -prediction with weights that match the signal-noise balance at each . This provides uniform effective gradient magnitude across all noise levels.
Verify that -prediction reduces to -prediction at and -prediction at .
Theory Exercise
Problem:
Show that the -prediction loss is equivalent to a weighted combination of -prediction and -prediction losses. Specifically, prove that .
Hints:
- Write $v = \sqrt{\bar{\alpha}_t}\epsilon - \sqrt{1-\bar{\alpha}_t}x_0$ and similarly for $v_\theta$
- Compute the difference $v - v_\theta$ in terms of $\epsilon - \hat{\epsilon}$ and $x_0 - \hat{x}_0$
- Use the fact that for optimal predictions, $\epsilon$ and $x_0$ errors are orthogonal in expectation
The DDPM objective weights every timestep equally, and the previous topic showed that different parameterizations implicitly reweight the loss across noise levels. This topic confronts the weighting question head on: given that the simple uniform loss works but is not optimal, how should we distribute training effort across timesteps? The stakes are real because timesteps are not equally valuable. Very low noise teaches imperceptible fine detail, very high noise fixes only the coarsest global layout, and the perceptually decisive mid-noise range, where edges, textures, and object boundaries are set, sits in between. The signal-to-noise ratio from the forward-process chapter is the natural coordinate for reasoning about this, because it measures exactly what kind of information survives at each step. This topic surveys three strategies in increasing sophistication: raw SNR weighting, which matches the variational bound but over-concentrates on easy low-noise steps; min-SNR weighting, which clips that concentration and reliably improves sample quality; and perceptual weighting, which targets the mid-noise sweet spot that human vision cares about most.
Definition
A loss weighting strategy assigns a per-timestep weight to the noise-prediction loss, controlling how training effort is distributed across noise levels. Choices range from uniform weighting through SNR-based weighting to min-SNR clipping and perceptual weighting, each trading likelihood against sample quality by emphasizing different regions of the signal-to-noise spectrum.
In this topic
- 1SNR-Based Weighting
- 2Min-SNR Loss Weighting
- 3Perceptual Loss Weighting
SNR-Based Weighting
The signal-to-noise ratio at timestep measures the relative power of signal to noise in . SNR-based weighting multiplies the loss by , which gives higher weight to low-noise timesteps (where SNR is high) and lower weight to high-noise timesteps. This is equivalent to the VLB weighting and optimizes the likelihood bound. However, it under-weights high-noise timesteps where the model learns global composition, often producing sharper but less coherent samples.
SNR weighting corresponds to the true VLB objective when used with -prediction. In -prediction, the simple loss already implicitly applies SNR weighting to the reconstruction error. The dynamic range of SNR spans -- across timesteps, causing extreme gradient imbalance: the first 10 timesteps can contribute more gradient than the remaining 990 combined. This is why pure SNR weighting underperforms despite being theoretically motivated.
Compare SNR at and for the linear DDPM schedule.
Min-SNR Loss Weighting
Hang et al. (2023) proposed Min-SNR- weighting, which clips the SNR weight at a maximum value (typically ). This prevents the loss from being dominated by the easiest timesteps (very low noise, very high SNR) while still giving some preference to perceptually important noise levels. Min-SNR-5 consistently outperforms both uniform and pure SNR weighting on FID and IS metrics across different datasets and architectures. It achieves this by capping the maximum attention given to any single noise level.
Min-SNR- truncates the weighting: . For : timesteps with get weight 5 (capped), while timesteps with get weight (uncapped). The gradient contribution becomes , which is bounded above by per timestep. This eliminates the pathological concentration of gradient on near-clean timesteps while preserving the relative ordering for high-noise steps.
With , what fraction of timesteps have their weight clipped (for DDPM linear schedule)?
Perceptual Loss Weighting
An alternative approach weights timesteps by their perceptual importance, measured by how much perceptual quality (e.g., LPIPS) changes when the model improves at that timestep. Choi et al. (2022) showed that mid-noise timesteps (-- in DDPM) contribute most to perceptual quality: they determine textures, edges, and local structure. Very low noise (fine grain) and very high noise (global layout) contribute less to human visual perception. This motivates weighting schemes that emphasize the perceptually critical mid-range.
Perceptual importance peaks at intermediate noise levels (--) because this is where the model determines textures, edges, and mid-frequency structure---features that dominate human visual perception. Very low noise encodes imperceptible high-frequency details (PSNR improves but LPIPS is flat), while very high noise encodes class-level semantics (a face vs a landscape) that are already determined by the coarsest features. Optimal perceptual weighting concentrates capacity in the sweet spot where LPIPS improvement per gradient step is maximized.
Why are mid-noise timesteps the most perceptually important?
Theory Exercise
Problem:
Derive the relationship between the DDPM VLB weight and the SNR. Show that (the change in SNR between adjacent timesteps).
Hints:
- Start from $w_t^{VLB} = \beta_t^2 / (2\tilde{\beta}_t \alpha_t (1-\bar{\alpha}_t))$
- Express $\tilde{\beta}_t$ in terms of $\bar{\alpha}_t$ and $\bar{\alpha}_{t-1}$
- Use $\text{SNR}(t) = \bar{\alpha}_t / (1 - \bar{\alpha}_t)$