Note Wisdom
These annotated notes unpack Stanford CME296’s flow‑matching lecture, covering core definitions, conditional loss functions, training/inference workflows, Reflow retraining, plus links to diffusion and score‑matching, while noting confusing concepts and practical limits.
Institution: Stanford
Original Course: Stanford CME296 Diffusion & Large Vision Models | Spring 2026 | Lecture 3 - Flow matching
Instructor Bio: This session is co-taught by **Afshine Amidi** and **Shervine Amidi**, adjunct faculty at Stanford University’s Institute for Computational and Mathematical Engineering (ICME). Afshine Amidi received his engineering degree from École Centrale Paris and a Master of Science in Operations Research from the Massachusetts Institute of Technology, where he studied under Prof. Dimitris Bertsimas and was awarded the Jean Gaillard Scholarship and MIT Dean’s Fellowship. He has held roles at Amazon and McKinsey & Company, leading AI and business strategy projects, and co-authors widely used technical learning guides on machine learning and algorithms. Shervine Amidi holds B.S. and M.S. degrees in engineering from École Centrale Paris, as well as an M.S. in Computational and Mathematical Engineering from Stanford University. He has conducted computer vision research at the Stanford Vision Lab and the École Centrale Paris Visual Computing Center. Currently a Senior Machine Learning Engineer at Netflix, he previously worked at Google DeepMind on the Gemini team, Google Assistant, and Uber Data Science. He has served as a teaching assistant for Stanford’s core CS courses and has been an adjunct lecturer at the university since 2021.
Course Description: This lecture presents flow-based generative modeling as a distinct and increasingly prominent paradigm. It covers the historical development of flow models, the design rationale behind flow matching objectives, conditional flow matching for controlled generation, end-to-end training and inference workflows for flow models, rectified flow formulations, and a systematic comparative analysis of flow matching, diffusion models, and score matching in terms of training stability, sampling speed, and sample quality.
These annotated notes summarize Stanford’s CME296 Lecture 3 on flow‑matching. The session builds on the prior two lectures covering DDPM diffusion and score‑matching for generative modeling. It walks through foundational definitions, the mathematical links between vector fields and probability distributions, the conditional flow‑matching loss, practical training‑and‑inference hurdles, and the Reflow optimization technique. I have marked sections where arguments moved quickly or concepts felt unintuitive, just as I would note them having watched the live lecture.
The lecture opens with a quick recap of material from Lectures 1 and 2. Lecture 1 introduced DDPM diffusion: you take clean images from the training dataset and gradually corrupt them through a predefined forward process Q. You then learn a reverse model P_θ that undoes noise step‑by‑step. Training leverages the evidence lower bound, which simplifies down to an L2 loss tasked with predicting the noise added to each image.
Lecture 2 offered an alternative viewpoint with score‑matching. Rather than centering the discussion on noise injection, you treat samples as points within a high‑dimensional image space. The score function is the gradient of the log‑probability density; it acts like a compass pointing toward regions of high data density. With Langevin sampling you can travel from a simple noise distribution toward genuine data samples. Training also relies on an L2 regression loss. The instructor emphasized how score‑matching and DDPM are deeply interconnected: the score for a noisy distribution has a direct relation to the noise used to corrupt clean inputs.
Both paradigms can be unified under continuous stochastic differential equations (SDEs). An SDE contains a deterministic drift term and a stochastic diffusion term that injects randomness. The forward SDE corresponds to adding noise to images. Recovering clean images via the reverse SDE requires access to the score function.
This brings up a critical notation shift specific to flow‑matching that tripped me up at first. Under DDPM and score‑matching conventions, t = 0 represents clean data, and large T represents fully noisy data. Flow‑matching reverses this setup. Here, P₀ stands for the easy‑to‑sample starting distribution — almost always Gaussian noise at t = 0 — while P₁ is our target real‑world data distribution at t = 1. The instructor sticks to this widely‑adopted convention from flow‑matching papers, while acknowledging that a small subset of publications flip these definitions. Keeping this time‑index convention straight is essential for following all subsequent equations.
The core premise behind flow‑matching is distribution transport. You want to move probability mass in its entirety from your simple starting distribution P₀ over to your complex target distribution P₁. Probability density must always be conserved, so total probability sums to one across the whole space.
This section lays out the fundamental vocabulary for flow‑matching. A trajectory \(x_t\) is the path an individual particle follows between t = 0 and t = 1. The flow \(\psi_t(x_0)\) maps an initial starting particle \(x_0\) to its spatial position at time t. A flow can be interpreted as the full collection of trajectories originating from every possible starting point. Our ultimate goal is for \(\psi_1(x_0)\) to generate samples indistinguishable from our target distribution P₁.
Next comes the probability path \(p_t(x)\). This is the probability distribution of particles at timestamp t. \(p_0(x)\) corresponds to our initial noise distribution and \(p_1(x)\) corresponds to our target real‑world data. Infinitely many distinct probability paths can interpolate between \(p_0\) and \(p_1\); there is no single “correct” path by default.
The most central construct is the time‑dependent vector field \(u_t(x)\). Given a spatial coordinate x and timestamp t, it outputs a vector that encodes both the direction and speed a particle should travel. The instructor used a useful self‑driving‑car analogy. A vector field gives concrete driving instructions for every location‑time combination. By contrast, the score function from Lecture 2 works more like a compass that merely points toward higher probability density. Though both produce vector outputs, their underlying purposes differ significantly.
Particle motion for individual samples follows an ordinary differential equation (ODE): \(\frac{dx}{dt}=u_t(x)\). One key technical condition receives attention: Lipschitz continuity. When a vector field satisfies Lipschitz continuity, every initial condition maps to exactly one unique trajectory. The instructor provided a counterexample with \(\sqrt{x}\): starting from \(x=0\), multiple separate trajectories satisfy the ODE, meaning trajectories lose uniqueness. Neural networks built with matrix multiplications and smooth activation functions naturally produce Lipschitz‑continuous vector fields. This detail becomes relevant later when explaining why matching velocity inherently means matching the flow itself.
We then shift from the microscopic view of individual particles to the macroscopic perspective of entire distributions, introducing the continuity equation, which enforces mass conservation: probability is only relocated, never created or destroyed. The time derivative of probability density equals the negative divergence of probability flux. Probability flux is defined as \(p_t(x) u_t(x)\), which multiplies density by the vector field. Divergence is a scalar operator obtained by summing partial derivatives across dimensions. Positive divergence signals net outward flow of density; negative divergence signals net inflow. A vector field \(u_t\) is said to generate a probability path \(p_t\) when the pair satisfies this continuity equation.
With all these components established, the high‑level objective becomes concrete. We train a neural‑network‑parameterised vector field \(u_t^\theta(x)\). At generation time, we sample \(x_0\) from P₀ and numerically solve the ODE forward from t = 0 to t = 1 to obtain our generated sample \(x_1\).
Before diving into flow‑matching proper, the instructor briefly covers continuous normalizing flows (CNF). CNF also learn vector fields for distribution transformation by optimizing maximum‑likelihood objectives. However, likelihood computation requires repeated numerical ODE solves during training. This computational burden makes CNF impractical for large‑scale real‑world usage.
Flow‑matching bypasses this costly maximum‑likelihood training pipeline. Instead, we aim to directly learn the required vector field. One major obstacle is that we do not possess ground‑truth target vector‑field values to fit against.
To resolve this, the instructor breaks down the overall problem into a simpler sub‑problem. Instead of transporting Gaussian noise to a complex real‑world data distribution, we first solve the task of transporting Gaussian noise to a single fixed target point represented by a Dirac‑delta distribution. A Dirac‑delta concentrates all probability mass onto exactly one point \(x_1\).
For this conditional scenario, we can analytically write down a conditional probability path \(p_t(x \mid x_1)\). This is a Gaussian distribution whose mean linearly drifts toward \(x_1\) while its variance shrinks over time: mean \(t x_1\), variance \((1‑t)^2 I\). At t = 0 we recover standard Gaussian noise. At t = 1 the variance collapses to zero, yielding a Dirac‑delta centered on \(x_1\).
We also obtain an exact conditional vector field for this probability path: \(u_t(x \mid x_1) = \frac{x_1 - x}{1-t}\). When we sample \(x_t\) from this conditional Gaussian path using the sampling formula \(x_t = t x_1 + (1‑t) x_0\), substituting this expression simplifies the conditional vector field all the way down to \(x_1‑x_0\). This gives us an extremely simple regression target.
We then generalise from one isolated target point to our full real‑world target distribution P₁. We marginalise across all training‑set target points \(x_1\) to construct a marginal probability path \(p_t(x)\) that interpolates between P₀ and P₁. There exists a corresponding marginal vector field, calculated as a weighted average over all conditional vector fields. The weighting follows Bayes‑rule‑style posterior probabilities: given current position x, how probable each \(x_1\) is as our destination.
A key mathematical result from the lecture: optimizing the original flow‑matching loss, which regresses toward this intractable marginal vector field, yields identical parameter‑update gradients as optimizing the conditional flow‑matching loss. The instructor demonstrated this by expanding expectations and rearranging integrals.
The conditional flow‑matching loss uses our easily‑computed regression target \(x_1‑x_0\). The training workflow is straightforward: sample noise \(x_0\), sample real‑data target \(x_1\) from the training dataset, sample a timestamp t, construct intermediate sample \(x_t\), feed \(x_t\) and t into the neural network to predict velocity, compute MSE loss between network output and \(x_1‑x_0\), then back‑propagate gradients.
The instructor also addresses the naming question: why call it flow‑matching when we are matching velocity vector fields rather than flows? Under Lipschitz continuity, vector fields and flows share a one‑to‑one correspondence. Matching velocity therefore implicitly matches the corresponding flow.
This section covers real‑world limitations of vanilla conditional flow‑matching and introduces Reflow as a mitigation strategy. Some parts of this section felt conceptually ambiguous as I followed along.
Even though we train against straight‑line velocities between sampled \((x_0, x_1)\) pairs, learned trajectories end up curved at inference time. Multiple distinct target destinations can demand conflicting velocity vectors at the same \((x, t)\) location. Since a neural network can only produce one vector output, it averages these competing signals.
Crucially, this averaging still preserves aggregate distribution properties. If you sample \(x_0\) from P₀ and integrate the ODE, your final samples will still follow the target data distribution. Even so, individual trajectories no longer follow the straight paths we used during training. Curved trajectories create practical inference challenges. Simple ODE solvers such as Euler need many function evaluations (NFE) to accurately trace curved paths. Unlike certain diffusion solvers such as DPM‑solver, flow‑matching’s learned ODE is fully nonlinear, and we lack convenient closed‑form shortcuts. Single‑step generation is not feasible.
Reflow is a retraining or fine‑tuning procedure designed to straighten trajectories. The workflow operates as follows. Start with an already‑trained flow‑matching model. Sample noise \(x_0\), run ODE inference to generate sample \(\tilde{x}_1\). Treat this new \((x_0, \tilde{x}_1)\) pair as fresh training data, and retrain a new flow‑matching model on these pairs. You can repeat this cycle multiple times.
In theory, repeated Reflow iterations make trajectories progressively straighter. Straighter trajectories allow ODE solvers to produce decent‑quality samples with far fewer inference steps.
The instructor warns that Reflow is not a silver‑bullet solution. Theoretical reasoning suggests Reflow preserves the target data distribution given perfectly accurate vector‑field knowledge and exact ODE integration. Real‑world implementations suffer from two sources of error. First is discretisation error stemming from numerical ODE solvers. Second comes from neural‑network approximation error for the vector field. These errors compound across Reflow cycles and degrade sample quality. In common practice, practitioners run only a single Reflow iteration, balancing faster inference against sample fidelity.
One notable limitation the instructor pointed out: even though idealised theory guarantees distribution preservation, numerical solver imperfections and network approximation error in real deployments mean we cannot take this property for granted. Empirical validation remains necessary.
Towards the lecture’s end, the instructor draws connections across diffusion, score‑matching, and flow‑matching. All three generative paradigms transform a simple noise distribution into complex real‑world data, yet they operate from distinct mathematical viewpoints. Diffusion works with SDEs and focuses on noise prediction. Score‑matching learns log‑probability gradients. Flow‑matching learns deterministic ODE vector fields. A referenced paper on stochastic interpolants establishes a unified mathematical framework. Within this framework, given any two among noise, score, and velocity quantities, you can derive the third.
Content Disclaimer: This article is for general reference only and does not constitute professional R&D guidance, production process advice or quality certification. All material performance data has specific test premises; readers should verify parameters against actual equipment and working conditions.
All contents below are exclusive to the paid Word file, NOT available on this web page

