# 01 · Continuous diffusion, score models and flow matching

**Scope:** forward corruption and reverse generation, network design, conditioning, and step counts. The [source inventory](./inventory.json) records specific versions. Equations here are re-derived in a consistent notation; figure/table claims are author-reported unless marked synthetic.

## Start with one scalar

Use \(x_0=2,\ \epsilon=-1,\ \bar\alpha_t=0.64\). The signal and noise scales are \(0.8,0.6\), so \(x_t=0.8(2)+0.6(-1)=1\). A perfect noise prediction recovers \(\hat x_0=(x_t-\sigma_t\hat\epsilon)/\alpha_t=2\); predicting \(-0.5\) instead recovers \(1.625\). At lower signal the error is amplified by \(\sigma_t/\alpha_t\). In a real model the noise is not given at inference: the network estimates it from the noisy input and conditioning. In training it is known because the trainer sampled it.

| Quantity | Definition | Read it as |
|---|---|---|
| Single-step noise | \(\beta_t\), with \(a_t=1-\beta_t\) | Incremental variance, **not** total variance |
| Total clock | \(\bar a_t=\prod_{j=1}^t a_j,\ \alpha_t=\sqrt{\bar a_t},\ \sigma_t=\sqrt{1-\bar a_t}\) | Signal and noise coefficients |
| Corrupt | \(q(x_t\mid x_{t-1})=\mathcal N(\sqrt{a_t}x_{t-1},\beta_t I)\), so \(x_t=\alpha_t x_0+\sigma_t\epsilon\) | Training samples a timestep and jumps there directly |
| Noise fit | \(\mathbb E\|\epsilon-\epsilon_\theta(x_t,t,c)\|^2\) | DDPM's simple objective, a reweighted alternative to the original variational objective, **not** an exact unweighted ELBO |
| DDPM reverse | \(\mu_\theta=(x_t-\beta_t\epsilon_\theta/\sigma_t)/\sqrt{a_t}\); sample a Gaussian with chosen reverse variance | The network estimates a reverse distribution; setting variance to zero in the DDPM update is not automatically DDIM |
| Deterministic DDIM | \(x_s=\alpha_s\hat x_0+\sigma_s\hat\epsilon,\ s<t,\ \eta=0\) | Change the solver/trajectory without retraining that noise predictor; exact equivalence of output quality for finite step counts is not promised |
| Score | \(s_t(x_t)=\nabla_{x_t}\log p_t(x_t)=-\mathbb E[\epsilon\mid x_t]/\sigma_t\) under Gaussian perturbation | An expectation over possible noise realizations, not access to the realized noise |
| VP velocity | \(v=\alpha_t\epsilon-\sigma_t x_0;\ x_0=\alpha_t x_t-\sigma_t v;\ \epsilon=\sigma_t x_t+\alpha_t v\) | A change of coordinates when \(\alpha_t^2+\sigma_t^2=1\); not the same symbol as a general flow-matching vector field |
| SNR | \(\alpha_t^2/\sigma_t^2\) | Larger means more signal; avoid dividing by zero at endpoints |

Sources: [Ho et al., DDPM §§2–3 / Algorithms 1–2](https://arxiv.org/abs/2006.11239v2), [Song et al., DDIM §§3–4](https://arxiv.org/abs/2010.02502), [Salimans & Ho, progressive distillation §4 for v-prediction](https://arxiv.org/abs/2202.00512).

### Worked pixel trajectory and code architecture

The [pixel lab](../index.html#pixel-lab) extends the scalar calculation to an actual 64-value tensor. During the training example, the trainer knows `x₀` and `ε`; the predictor sees only `xₜ,t`. In the generation view, there is no held-out image to recover: start from a seeded approximate Gaussian prior and repeat the reverse update. The two-prototype toy uses equal priors and \(P(z\mid x_t)\propto\exp[-\|x_t-\sqrt{\bar a_t}z\|^2/(2(1-\bar a_t))]\), then \(\hat x_0=\sum_z zP(z\mid x_t)\). This yields the mean noise estimate under the known toy prior, not learned weights or the exact reverse law of that mixture. For each adjacent step, use \(\beta_t=1-\bar a_t/\bar a_{t-1}\), \(\tilde\beta_t=\beta_t(1-\bar a_{t-1})/(1-\bar a_t)\), and draw the next state from the predicted Gaussian. The [Python fixture](./toy_checks.py) cross-checks this using the clean-plus-noisy posterior mean coefficients instead of the browser’s noise-parameterized mean.

The [paper inspector](../index.html#paper-flows) separates DDPM's pixel U-Net, CompVis latent U-Net, and class-conditional DiT. In the [CompVis code flow map](../latent-diffusion-flow-diagram.html), use **Training**, **Generation**, and **Conditioning** to see where the first-stage autoencoder, time-conditioned U-Net, and text K/V actually connect. Its `1p4B` evaluation blueprint, not a generic Stable Diffusion configuration, has latent `[1,4,32,32]`, a 77-position text context of width 1280 and an example 320-channel full-resolution attention block (8 × 40). DiT-XL/2 uses class conditioning via time + label embeddings and modulates each block; the 256-pixel example uses `[1,256,1152]` patch hidden states and an eight-channel latent head. These are configuration/shape readouts, not performance or model-weight measurements.

### Three models can predict the same coordinates and still train differently

At fixed t, \(x_0,\epsilon,v\) parameterizations can be converted. Training losses are not automatically equal: \(\|\delta x_0\|^2=(\sigma_t/\alpha_t)^2\|\delta\epsilon\|^2\) when they are computed from the corresponding converted predictions. Thus the parameterization, distribution of sampled times, loss weighting, and sampler grid are distinct decisions. Original DDPM used 1,000 diffusion steps and a roughly linear beta schedule in its setup; a deployed sampler's number of **neural function evaluations (NFE)** depends on the solver, the number of stages per step, and the guidance implementation.

## SDE, EDM and the flow view

- **Score SDE.** Forward \(dX=f(X,t)dt+g(t)dW\), reverse drift \(f-g^2s_t\) when integrating from high to low time with reverse Brownian increments; probability-flow ODE drift \(f-\tfrac12g^2s_t\). Derive the factor of one half from the Fokker–Planck equation: the diffusion term is \(\tfrac12g^2\Delta p_t\), and \(\Delta p_t=\nabla\cdot(p_t s_t)\). The exact score gives the same one-time marginals in the SDE and ODE, not identical paths. Finite numerical integration and a learned score do not give exact likelihoods for the data distribution. [Song et al., §§3–4 and App. D](https://arxiv.org/abs/2011.13456).
- **EDM.** The denoiser \(D_\theta(x;\sigma)=c_{\rm skip}(\sigma)x+c_{\rm out}(\sigma)F_\theta(c_{\rm in}(\sigma)x,c_{\rm noise}(\sigma))\) isolates input/output scaling, a skip, and noise conditioning. For the variance-exploding coordinate \(x=x_0+\sigma\epsilon\), Euler uses \(d=(x-D_\theta)/\sigma\); Heun estimates a corrected slope (an extra evaluation away from a terminal zero-noise endpoint), and churn adds optional stochasticity. The [released `generate.py`](https://github.com/NVlabs/edm/blob/008a4e5316c8e3bfe61a62f874bddba254295afb/generate.py) separates these switches. See [Karras et al., §§3–5](https://arxiv.org/abs/2206.00364).
- **Flow matching.** Choose a family of conditional paths rather than a Gaussian Markov chain. With the data-to-noise convention \(x_t=(1-t)x_0+t\epsilon\), the conditional velocity target is \(\epsilon-x_0\). Fit \(v_\theta(x_t,t)\) by squared regression; an ODE integrates this learned field back from noise. Flipping the time convention changes the velocity sign. Linear interpolation of one paired example is straight; the marginal learned field, whose velocity is a conditional expectation, need not trace every pair's straight line. Diffusion SDE and flow matching share useful constructions, not identical objectives or universally Gaussian paths. Rectified flow changes the coupling/straightness strategy; stochastic interpolants are a broader formalism. [Lipman et al., §§3–4](https://arxiv.org/abs/2210.02747) · [Liu et al.](https://arxiv.org/abs/2209.03003) · [Albergo & Vanden-Eijnden](https://arxiv.org/abs/2209.15571).

## From pixels to latents to token grids

Use `B=1` as a teaching batch, not a throughput measurement. Intermediate sizes follow the declared example, not a claim that all checkpoints use the same shapes.

| Stage | Mechanism / equation | Concrete shape walkthrough |
|---|---|---|
| U-Net | Denoise in a spatial grid. Downsample for wider context; carry high-resolution skip features through matching levels; upsample and combine. Condition blocks on the diffusion/noise time. | Start `x_t [B,C,H,W]`; levels might halve `H,W`; return a prediction aligned with the noisy input. Channels across blocks are specific to the checkpoint. |
| LDM | Encoder \(z=E(x)\); train diffusion on \(z_t\); decode \(D(\hat z)\) after reverse sampling. For text, cross-attention uses spatial/latent query tokens and text-context keys/values. | An explicitly assumed ×8 spatial compression turns `[1,3,256,256]` into `[1,4,32,32]`. Pixel axes and latent channels are different features; diffusion noise is added to the latent being modeled. |
| DiT | Patchify the noisy latent; transformer blocks, position information, timestep/class-conditioned adaptive normalization; unpatchify the output. | For a factor-8 VAE and `/2` patches, a 256² image uses 32² latent sites and 16² = 256 tokens. A `[1,4,32,32]` latent with a learned-variance head can return `[1,8,32,32]`; not every DiT has a variance head. |
| SD3/MMDiT | Joint attention between text and image streams with modality-specific weights; flow prediction over image latent tokens. | `[B,N_img,D]` + `[B,N_txt,D]` for attention; distinguish joint attention from a standard latent U-Net's one-way cross-attention. |

Sources: [Rombach et al., LDM Fig. 3 and §3.3](https://arxiv.org/abs/2112.10752), [Peebles & Xie, DiT Fig. 3 and Tab. 1](https://arxiv.org/abs/2212.09748v2), [DiT code](https://github.com/facebookresearch/DiT/blob/ed81ce2229091fd4ecc9a223645f95cf379d582b/models.py), [Esser et al., SD3 §4](https://arxiv.org/abs/2403.03206). See raw extracts for per-model dataset/details. Keep image resolution, compression, patch size and head channels in a single labeled example rather than transferring them across variants.

### Guidance, conditioning, training scale and applications

- **Classifier-free guidance (CFG).** Train with condition dropout to learn conditional and unconditional outputs. In the common library convention \(\epsilon_g=\epsilon_u+s(\epsilon_c-\epsilon_u)\), `s=0` gives unconditional and `s=1` gives ordinary conditional; the paper's extrapolation convention \((1+w)\epsilon_c-w\epsilon_u\) means \(s=1+w\). Calls can be batched but guidance is not free. Larger guidance tends to trade distribution diversity for prompt adherence; a curve/table on one dataset is not universal. [Ho & Salimans §3](https://arxiv.org/abs/2207.12598).
- **Control choices.** Cross-attention supplies context; adaptive normalization modulates activations; ControlNet connects learned spatial-control residuals to an image model; LoRA changes selected linear projections rather than the reverse-process law. These differ from altering the sampler. Read [ControlNet](https://arxiv.org/abs/2302.05543) as an additional source, not a new algorithm measured in this work.
- **Step reduction.** DDIM, EDM solvers and DPM-Solver++ can change integration while reusing a compatible trained prediction function. Progressive distillation, consistency models, DMD and MeanFlow instead change training targets/requirements. A two-step result can still need more than two evaluations; never compare different resolutions, conditioning, CFG, NFE, datasets or quality estimators without saying so. [DPM-Solver++](https://arxiv.org/abs/2211.01095) · [Consistency Models](https://arxiv.org/abs/2303.01469) · [MeanFlow](https://arxiv.org/abs/2505.13447).
- **2024–26 extensions, not a universal ranking.** [REPA](https://arxiv.org/abs/2410.06940) guides intermediate representations with an external representation target during training; [RAE](https://arxiv.org/abs/2510.11690) changes what latent object is modeled; [JiT](https://arxiv.org/abs/2511.13720) studies direct clean prediction in pixels. Treat exact FID values in the supplied report as leads unless reproduced from each paper's named protocol. Diffusion also models trajectory actions ([π0 uses flow matching](https://arxiv.org/abs/2410.24164)), weather ensembles ([GenCast](https://www.nature.com/articles/s41586-024-08252-9)) and atom coordinates ([AlphaFold 3](https://www.nature.com/articles/s41586-024-07487-w)); these are different denoisers, state spaces and objectives, not copies of a text LM. No biomolecular design procedure or model run is part of this lesson.

**Open evidence:** benchmarking a particular package/kernel, training a denoiser, running a checkpoint, and comparing frontier FIDs are out of this local calculation. The raw extracted references include broader applications; this note will not promote their claims to comparable runs.
