Diffusion models
扩散模型
Learn the reverse of gradual noising and distinguish noise prediction, sampling, and conditional generation.
diffusion-modelsIntuition: why can denoising produce new samples?
Repeatedly add noise to a real sample until its structure is largely overwhelmed. Train a model to denoise at different noise levels. Starting with random noise and repeatedly applying a learned reverse process can then produce samples resembling the training distribution. The aim is to learn a distributional reverse process, not recover one unique original image from arbitrary noise.
Early diffusion modeling organized generation around gradual perturbation and reverse-process learning. DDPM connected this approach with an effective denoising objective. Interpret results in the context of the dataset, sampler, and metrics rather than treating one paper as evidence for every diffusion model. 2015 paper, DDPM
Forward noising and the training objective
Define and . Training steps use , so ; denotes the unnoised starting point. The Gaussian forward process permits direct sampling at time :
Training need not simulate every preceding step. Sample a time and noise, construct , and ask a network to predict the noise. A common simplified objective is:
Time conditioning matters because denoising strength depends on the noise level. Noise prediction, clean-sample prediction, and velocity prediction are different parameterizations; their formulas cannot be mixed arbitrarily. Sampling additionally requires a reverse mean, variance, and schedule.
One can convert predicted noise to a clean-sample estimate: . This is a conditional estimate. Information is lost at high noise levels, so exact recovery of each original sample is not guaranteed.
The direct formula also follows from a one-step Gaussian transition: , with independent standard Gaussian . The mean gains a factor , while the noise variance becomes . Accumulated noise can therefore still be expressed as a scaled standard Gaussian.
DDPM’s simplified loss samples uniformly from , with a data sample and independently drawn fresh noise. It drops time-dependent weights from the variational objective; it is not term-by-term identical to the full negative log-likelihood bound. DDPM, Section 3.4, Equation 14
Generation needs a further step: turn a prediction into a conditional distribution from to . One DDPM noise-parameterized mean is:
In the corresponding sampler, advance using , where is the chosen reverse transition’s standard deviation; Algorithm 2 sets at the final step. This reverse mean differs from the clean-sample estimate above: the latter points to time zero, whereas the former usually moves back one step. The forward posterior conditioned on a known is also not the true marginal reverse distribution available at generation time. DDPM, Section 3.2, Equation 11 and Algorithm 2
A complete check of the forward formula
This example checks noising and algebraic reconstruction when the true noise is known. It trains no denoiser and is not a generator.
import math
import random
def validate_vectors(a, b):
if not a or len(a) != len(b):
raise ValueError("nonempty equal-length vectors required")
if not all(math.isfinite(v) for v in [*a, *b]):
raise ValueError("finite vector entries required")
def noising(x0, noise, alpha_bar):
validate_vectors(x0, noise)
if not math.isfinite(alpha_bar) or not 0 <= alpha_bar <= 1:
raise ValueError("0 <= alpha_bar <= 1 required")
return [math.sqrt(alpha_bar)*x + math.sqrt(1-alpha_bar)*e
for x, e in zip(x0, noise)]
def clean_estimate(xt, predicted_noise, alpha_bar):
validate_vectors(xt, predicted_noise)
if not math.isfinite(alpha_bar) or not 0 < alpha_bar <= 1:
raise ValueError("0 < alpha_bar <= 1 required for inversion")
result = [(z-math.sqrt(1-alpha_bar)*e)/math.sqrt(alpha_bar)
for z, e in zip(xt, predicted_noise)]
if not all(math.isfinite(v) for v in result):
raise ValueError("reconstruction overflow")
return result
rng = random.Random(7)
x0 = [2.0, -1.0]
noise = [rng.gauss(0, 1) for _ in x0]
for alpha_bar in (1.0, 0.6, 0.01):
xt = noising(x0, noise, alpha_bar)
oracle = clean_estimate(xt, noise, alpha_bar)
assert max(abs(a-b) for a, b in zip(x0, oracle)) < 1e-12
assert noising(x0, noise, 1) == x0
assert noising(x0, noise, 0) == noise
for invalid in (0, -0.1, 1.1, float("nan")):
try:
clean_estimate(x0, noise, invalid)
except ValueError:
pass
else:
raise AssertionError("invalid inversion accepted")
The interactive lab computes exact conditional means for an analytically known two-dimensional Gaussian mixture. This separates a mathematically known denoiser from a learned neural denoiser. Real training also needs independent data splits, a network, an optimizer, and generative evaluation. More sampling steps increase inference cost.
Limitations and misconceptions
A lower noise-regression loss does not automatically improve every measure of sample quality, coverage, or condition following. A sampler must be compatible with its model. Classifier-free guidance can strengthen conditioning while changing diversity and the sample distribution.
Training data can introduce bias, memorized reproduction, and authorization issues. Attractive images do not establish truthfulness. The known distribution and low-dimensional geometry of this experiment also do not capture every challenge in high-dimensional image generation.
Experiments and exercises
- What is when ? Answer: , with no added noise.
- Which term dominates as approaches zero? Answer: noise; direct clean-sample estimation becomes unstable.
- Why supply time information to the network? Answer: it identifies the signal-to-noise level and corresponding denoising task.
- Are knowing the generated noise and predicting noise from a noisy image equivalent? Answer: no. The former is this algebraic check; the latter is a learned inference problem.
Research connections
Score matching connects denoising to density gradients. DDIM changes sampling, latent diffusion moves much of the computation into compressed representations, and flow matching learns transport between distributions using another objective. Compare methods under fixed data, resolution, and evaluation conditions, and report model size, training cost, and sampling budget. Additional resources should not be mistaken for a purely algorithmic improvement.
Make a prediction, then check
What does the code prove when it reconstructs a sample using the true noise?
Learning objectives
- Calculate forward corruption and reconstruction with known noise.
- Distinguish a denoising training objective from multistep generation.
Prerequisites & connections
Explore related knowledge →References
- Denoising Diffusion Probabilistic Models
Jonathan Ho; Ajay Jain; Pieter Abbeel · 2020 - Deep Unsupervised Learning using Nonequilibrium Thermodynamics
Jascha Sohl-Dickstein and coauthors · 2015
Version2 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: cited-source comparison, re-derivation and recalculation, bilingual argument comparison, and executed Python assertions; no independent human peer review.
- Re-derived forward noise variance and checked oracle reconstruction, amplification of noise-prediction error, and the zero-signal boundary.
- Distinguished simplified loss from the full variational bound and clean estimates from one-step reverse means; identified the code as a formula check rather than a full trainer or generator.
- Compared the main claims, assumptions, examples, exercises, and citations across languages; structural checks additionally compare display equations, code, and source IDs. This is an AI technical check, not independent human peer review.
Source locations checked:
- Denoising Diffusion Probabilistic Models · v2 HTML §§3.2–3.4, Eqs.11–14 and Algorithms 1–2
- Deep Unsupervised Learning using Nonequilibrium Thermodynamics · PMLR proceedings and PDF §§2.1–2.2, forward/reverse trajectory distinction
Related topics