Part XIII — Generative Models: VAEs, Flow Matching, Score Models & Diffusion Transformers · Chapter 10

Build a flow-matching & DiT image synthesizer

Hook

Chapter 3 computed one training pair's exact velocity by hand — a fine warm-up, but not a generative model. A real sampler has to work on noise it's never seen. Can training on a handful of pairs produce a velocity field that generalizes to a brand-new starting point?

Intuition
step 0/10: x = -2.000 (trained v̄ = 8.25)

Pick a starting noise value and take Euler steps. None of these four starting points were in the training set — the field being applied was fit once, on four completely different pairs, and now generates from anywhere.

Formalize

Fitting a constant velocity field vθvˉv_\theta \equiv \bar v by least squares against training pairs' velocities has a closed form — the mean:

vˉ=1Ni=1N(x1(i)x0(i))\bar v = \frac{1}{N}\sum_{i=1}^N (x_1^{(i)} - x_0^{(i)})
  • vˉ\bar v — the single constant velocity value being fit, applied identically at every point and every time.
  • NN — the number of training pairs.
  • x0(i)x_0^{(i)} — the noise sample from the ii-th training pair.
  • x1(i)x_1^{(i)} — the data sample from the ii-th training pair.
  1. The smallest possible flow-matching model

    This has no dependence on xx or tt at all — just one number.

  2. Real networks condition on x and t, same objective

    Real flow-matching networks condition on both, so different starting points and different times along the path get genuinely different corrections — but the training objective being minimized is the exact same squared error between a predicted velocity and x1x0x_1-x_0, just with a far more expressive model fitting it.

Play

The trained field doesn't equal any single training pair's velocity — it's their average. Every pair pulled the fit a little differently, and the least-squares solution is the one number that minimizes total squared disagreement across all four, not the best match to any one of them.

Worked example

Four training pairs: (3,6)({-}3,6), (1,4)({-}1,4), (4,8)({-}4,8), (2,5)({-}2,5):

  1. Each pair's velocity

    Computed exactly as in Chapter 3, one subtraction each (x1x0x_1-x_0):

    • (3,6)(-3,6): 6(3)=96-(-3)=9
    • (1,4)(-1,4): 4(1)=54-(-1)=5
    • (4,8)(-4,8): 8(4)=128-(-4)=12
    • (2,5)(-2,5): 5(2)=75-(-2)=7
  2. Train: average them

    vˉ=(9+5+12+7)/4=8.25\bar v = (9+5+12+7)/4 = 8.25. This is the entire training procedure for this model.

  3. Generate from noise the model never trained on

    x0=2x_0 = -2 (not one of the four training points): x1=2+8.25(1)=6.25x_1 = -2 + 8.25(1) = 6.25 — one Euler step, exact, since the trained field is constant.

Checkpoint

Find the noise point, among the four candidates, whose generated sample lands closest to the target value of 7.

Pick a noise point to try it
Summary
vˉ=1Ni(x1(i)x0(i)),x1=x0+vˉ\bar v = \frac{1}{N}\sum_i (x_1^{(i)} - x_0^{(i)}), \qquad x_1 = x_0 + \bar v

This sampler generalizes in the most limited way possible — it applies the exact same shift to every starting point, so it can never do more than translate the noise distribution. A real flow-matching network's velocity depends on xx and tt, which is what lets different starting points end up in different parts of a genuinely multi-modal data distribution instead of all landing exactly vˉ\bar v apart. This closes Part XVI. The mechanisms covered — exact densities via invertible maps, score fields, straight-line training targets, single-step distillation, and discrete codebooks — are the building blocks behind essentially every modern image, audio, and video generator shipped today. The next part turns from generating a single output to a model that takes actions: calling tools, planning multi-step tasks, and orchestrating other models to get something done.