advanced36 min studyLesson 58 in Engineering

Diffusion and score models

Connect a known noising process to learned denoising, scores, and iterative generation costs.

On this page

What you’ll understand

  • Sample a noised training example at a selected time without simulating every prior step.
  • Relate noise prediction to a score under Gaussian perturbations.
  • Separate training objectives, reverse samplers, and generation budgets.

Diffusion models learn to reverse a carefully specified corruption process. Training pairs can be created by taking a real example, selecting a noise level, and adding known Gaussian noise. Generation begins from a simple distribution and repeatedly applies a learned correction. The architecture predicts a quantity such as noise or score, while a sampler decides how those predictions move a sample. Keeping those roles separate prevents confusing a neural network forward pass with the entire generative procedure.

The forward process gives exact training pairs

Let beta_t define a variance schedule, alpha_t equal one minus beta_t, and alpha-bar_t be the product of alphas up to time t. The Gaussian forward process has a closed-form marginal at any selected time. This lets training draw a clean example and independent noise, then construct one noisy example directly. It need not simulate every previous corruption step. The schedule changes signal-to-noise ratios across time and therefore which denoising problems the model sees.

A neural network receives the noisy input and a time or noise-level embedding; conditional models also receive text, labels, or another conditioning signal. A common simplified objective regresses the sampled noise with squared error. Alternative parameterizations predict clean data or velocity-like combinations. These can be transformed under a known schedule but differ in numerical behavior and loss weighting. Record the exact target and weighting rather than describing every system simply as predicting the image.

xt=αˉtx0+1−αˉt ϵ,ϵ∼N(0,I)x_t=\sqrt{\bar\alpha_t}x_0+\sqrt{1-\bar\alpha_t}\,\epsilon,\qquad \epsilon\sim\mathcal N(0,I)
This is the marginal sampling formula for the variance-preserving Gaussian forward chain. Coordinates of epsilon are independent standard normals, and alpha-bar is fixed by the chosen schedule.↔ Scroll wide equations horizontally.

Scores describe a probability density's slope

The score is the gradient of log density with respect to the noisy input. For a Gaussian perturbation of a fixed clean example, its conditional score is a scaled negative noise residual. The marginal score averages the appropriate conditional behavior over possible clean examples given the noisy observation. A trained noise predictor estimates that conditional expectation under its loss assumptions; it is not handed the original clean example at generation time.

For a matching variance-preserving parameterization, an estimated score can be obtained by scaling a noise prediction by minus one over the noise standard deviation. Reverse stochastic differential equations and probability-flow ordinary differential equations then provide different sampling descriptions. They require appropriate coefficients and numerical integration. A score arrow is a direction in data space, not a guarantee that one unrestricted step reaches a high-quality example or increases likelihood monotonically.

sθ(xt,t)≈−ϵθ(xt,t)1−αˉts_\theta(x_t,t)\approx-\frac{\epsilon_\theta(x_t,t)}{\sqrt{1-\bar\alpha_t}}
This relation uses the stated variance-preserving noise-prediction convention and an appropriately trained predictor. Other perturbation processes or output parameterizations require corresponding conversion formulas.↔ Scroll wide equations horizontally.

Generation is a quality-cost tradeoff

Each sampler step may require one or more network evaluations. Conditional guidance can require additional conditional and unconditional evaluations unless combined or otherwise optimized. A model with fewer parameters can therefore be slower to sample than a larger one using fewer steps. Report number of function evaluations, batch size, resolution, precision, guidance settings, and measured latency. Latent diffusion moves the denoising process into a learned compressed space and adds encoder-decoder assumptions and costs.

Evaluate fidelity, diversity, conditioning adherence, and failure cases separately. Aggressive guidance may improve one metric while reducing variety or introducing artifacts. Changing a noise schedule or using an accelerated sampler is a method change that needs validation. Neither a low denoising loss nor visually attractive selected samples alone establishes coverage of the target distribution. Keep prompts, seeds, sample selection, and evaluation sets available so a comparison can be reproduced without cherry-picking.

Construct and invert one noisy coordinate

Take clean scalar x_0=2, alpha-bar_t=0.64, and a sampled noise epsilon=−1. Suppose the network predicts epsilon_hat=−0.5 at that point.

  1. The signal coefficient is √0.64=0.8 and noise coefficient is √0.36=0.6, so x_t=0.8×2+0.6×(−1)=1.

  2. Using the true sampled noise recovers the clean value: (1−0.6×(−1))/0.8=2.

  3. Using the predicted noise instead gives a clean estimate (1−0.6×(−0.5))/0.8=1.625. The corresponding estimated score is −(−0.5)/0.6≈0.8333.

The result

Imperfect noise prediction produces an imperfect clean estimate. This algebraic estimate is not a complete reverse-process sampler.

Explore the model

Interactive lab

Interactive lab · fields

Inspect a vector field with stated limits

The lab plots a softened two-dimensional source q r/(r²+epsilon) plus rotational field Ω(−y,x). Change source strength and rotation to inspect local directions. It is not a learned score, diffusion trajectory, or reverse-SDE solver; the rotational component also illustrates why an arbitrary vector field need not be a log-density gradient.

Inspect a vector field with stated limitsThe softened illustration is q·r/(r² + 0.2) + Ω(−y, x). Moving markers indicate local direction, not integrated particle paths or a Maxwell solution. Current readings: Fx at (1, 0): 0.833; Fy at (1, 0): 0.5; Field magnitude there: 0.972. All parameters are adjustable with the labeled controls below.−3.2−1.601.63.2−1.5−0.7500.751.5xyq = 1
Local field directionSource strength
Fx at (1, 0)
0.833
Fy at (1, 0)
0.5
Field magnitude there
0.972
t = 0 s

The softened illustration is q·r/(r² + 0.2) + Ω(−y, x). Moving markers indicate local direction, not integrated particle paths or a Maxwell solution. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA score has mathematical structure beyond a collection of arrows; a general vector field is not automatically a valid probability-density score.

Check your understanding

Why can a diffusion training example at time t be created without simulating all earlier forward steps?

Try it yourself

For alpha-bar=0.25, clean coordinate 4, and sampled noise 0, compute the noisy coordinate. If a predictor outputs noise 1, compute its clean estimate.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Use signal coefficient 0.5 and noise coefficient √0.75, then solve the forward formula for the clean coordinate.

Compare with the solution

The noisy coordinate is 0.5×4+√0.75×0=2. The predicted clean estimate is (2−√0.75×1)/0.5≈2.2679. The difference from 4 comes entirely from noise-prediction error in this example. It does not imply that the network can identify the exact sampled noise for every ambiguous noisy observation.

Take it with you

  • A known corruption marginal makes denoising targets inexpensive to construct.
  • Noise prediction and score prediction are related under a specified perturbation convention.
  • Sampling evaluations, guidance, and numerical integration determine generation cost.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.