Skip to main content
Open In Colab

The missing vector field

The Fokker-Planck section showed that the Ornstein-Uhlenbeck process dXt=−Xt dt+2 dWtdX_t = -X_t\,dt + \sqrt{2}\,dW_t moves its density ptp_t with the probability flow velocity vt(x)=−x−st(x),st(x)=∂xlog⁡pt(x).v_t(x) = -x - s_t(x), \qquad s_t(x) = \partial_x \log p_t(x) . Generation runs the process backward. In the reverse clock u=T−tu = T - t, with Yu=XT−uY_u = X_{T-u}, time increases while you generate, and the reverse SDE and the reverse probability flow ODE are dYu=(Yu+2 sT−u(Yu)) du+2 dWu,dYudu=Yu+sT−u(Yu).\begin{aligned} dY_u &= \bigl(Y_u + 2\,s_{T-u}(Y_u)\bigr)\,du + \sqrt{2}\,dW_u , \\ \frac{dY_u}{du} &= Y_u + s_{T-u}(Y_u) . \end{aligned} The drift −x-x comes with the forward process. The score sts_t is the only unknown in all three equations. This section asks how you can learn the score from samples of the data, on an example where the exact score is known and every estimate can be checked against it. The data distribution p0p_0 is the Gaussian mixture of the probability transport chapter, with weights πk=(0.3,0.5,0.2)\pi_k = (0.3, 0.5, 0.2), means μk=(−2,1,3.5)\mu_k = (-2, 1, 3.5) and standard deviations σk=(0.4,0.6,0.3)\sigma_k = (0.4, 0.6, 0.3). At each fixed tt, XtX_t has the distribution of Xt=atX0+bt ε,at=e−t,bt=1−e−2t,X_t = a_t X_0 + b_t\,\varepsilon, \qquad a_t = e^{-t}, \quad b_t = \sqrt{1 - e^{-2t}} , with ε∼N(0,1)\varepsilon \sim \mathcal{N}(0, 1) independent of X0X_0. The horizon is T=4T = 4, as in the Fokker-Planck section. The mixture has a smooth density, so its score stays finite as t→0t \to 0, but two related quantities do not stay finite. The denoising targets used later on this page have variance 1/bt21/b_t^2, which grows without bound. The samples themselves form an empirical distribution with no density at t=0t = 0, so its score does not exist there. Training and evaluation therefore use t∈[tmin⁡,T]t \in [t_{\min}, T] with tmin⁡=10−3t_{\min} = 10^{-3}.

Four fields

Four fields appear in these equations, and they are easy to confuse. The forward drift −x-x is the mean motion of one particle of the forward SDE. The score sts_t points in the direction in which the log density increases. Particles that move with the probability flow velocity −x−st-x - s_t have density ptp_t at every tt. Particles that move with the reverse velocity x+stx + s_t in the reverse clock retrace the same densities from pTp_T back to p0p_0. The figure shows all four at t=0.05t = 0.05, 0.30.3, 11 and 33, under the density at the same time. Grid of eight panels. The top row shows the mixture density at t = 0.05, 0.3, 1 and 3, with three peaks that merge into one bell curve. The bottom row shows the forward drift, the score, the probability flow velocity and the reverse velocity at the same times; near t = 0 the score is steep and changes sign between components, and by t = 3 the score is close to minus x. Top, the density ptp_t at four times. Bottom, the four fields at the same times. Near t=0t = 0 the score is steep inside each component and changes sign sharply between them, and both velocities inherit that shape. By t=3t = 3 the score is close to −x-x, so the probability flow velocity and the reverse velocity, its negative, are both close to zero, while the drift is not. The next figure shows the density ptp_t and one of the four fields at a single diffusion time tt. In the interactive version you can set tt anywhere from 0 to 4 and choose the field. At t=0t = 0 the panels show the data density p0p_0 and its exact fields. The density ptp_t (top) and one of the four fields (bottom) at the time tt shown above the panels. The dashed line marks zero, and the vertical axis of the lower panel rescales with tt.

The Gaussian equilibrium

The limit t→∞t \to \infty makes the difference between the score and the velocity exact. For p∞=N(0,1)p_\infty = \mathcal{N}(0, 1) the score is s∞(x)=−xs_\infty(x) = -x, which is nonzero away from the origin, and v∞(x)=−x−(−x)=0.v_\infty(x) = -x - (-x) = 0 . Particles of the forward SDE keep moving, and the density stays put. The score is a property of the density at one time. It is neither the velocity of a particle nor the field that transports the density. The check evaluates both fields on N(0,1)\mathcal{N}(0, 1).

The score as a posterior average

Each component of ptp_t is Gaussian, with mean atμka_t \mu_k and variance Σk,t=at2σk2+bt2\Sigma_{k,t} = a_t^2 \sigma_k^2 + b_t^2, so its score is the straight line (atμk−x)/Σk,t(a_t \mu_k - x)/\Sigma_{k,t}. Differentiate log⁡pt=log⁡∑kπk N(x; atμk,Σk,t)\log p_t = \log \sum_k \pi_k\,\mathcal{N}(x;\, a_t \mu_k, \Sigma_{k,t}) and each component score picks up a weight: st(x)=∑krk(x,t) atμk−xΣk,t.s_t(x) = \sum_k r_k(x, t)\,\frac{a_t \mu_k - x}{\Sigma_{k,t}} . The weight of component kk is rk(x,t)=πk N(x; atμk,Σk,t)∑jπj N(x; atμj,Σj,t),r_k(x, t) = \frac{\pi_k\,\mathcal{N}(x;\, a_t \mu_k, \Sigma_{k,t})}{\sum_j \pi_j\,\mathcal{N}(x;\, a_t \mu_j, \Sigma_{j,t})} , the posterior probability that the point Xt=xX_t = x came from component kk. These are the responsibilities of the EM algorithm, evaluated on the noisy mixture ptp_t. Let ZZ be the component label. Then the formula says st(x)=E[∂xlog⁡pt(x∣Z)∣Xt=x].s_t(x) = \mathbb{E}\bigl[\partial_x \log p_t(x \mid Z) \mid X_t = x\bigr] . The score of the marginal density is the posterior average of the conditional scores. The same conditional expectation comes back in the two denoising sections below, with the clean data point as the hidden variable. The density of the three-component mixture on the line, with the component means mu 1, mu 2 and mu 3 marked on the axis. A dashed vertical line marks an observation x between mu 2 and mu 3. At x, a green arrow points left toward mu 2 and a pink arrow points right toward mu 3. The density of the three-component mixture on the line, with the component means mu 1, mu 2 and mu 3 marked on the axis. A dashed vertical line marks an observation x between mu 2 and mu 3. At x, a green arrow points left toward mu 2 and a pink arrow points right toward mu 3. At a point xx between two components, the component scores disagree. The score of component 2 points left toward μ2\mu_2, and the score of component 3 points right toward μ3\mu_3. The score of the mixture is their average weighted by the responsibilities rk(x,t)r_k(x, t), so the component that most likely produced xx dominates it. The curve is the data density p0p_0. The arrow lengths are not to scale. The responsibilities are computed from log densities with the log-sum-exp identity. The score therefore stays finite in the far tails, where ptp_t itself underflows. As a check, the formula is compared with a central finite difference of log⁡pt\log p_t on [−8,8][-8, 8] at t=0.05t = 0.05, 0.50.5 and 22.
The formula and the finite difference agree to about 10−910^{-9} at all three times, including far in the tails where the score is large. The last line uses the same responsibilities for a different purpose: averaged over samples, they give the mass that the samples put on each component. Every sampler on this page is judged by it, because a sampler can reach all three modes with the wrong weights. The figure shows the pieces of the score at t=0.3t = 0.3. Two stacked panels at t = 0.3. The top panel shows three responsibility curves that hand over from one component to the next. The bottom panel shows three straight component scores and their responsibility-weighted sum, the exact score, as a thick gray curve. Top, the responsibilities rk(x,t)r_k(x, t) at t=0.3t = 0.3. Bottom, the three component scores (thin colored lines) and their responsibility-weighted sum, the exact score (gray). Each component score is a straight line through its own mean. The weights hand the sum from one line to the next where the components overlap, and the score bends there.

Learning a score without the density

Suppose you have samples of p0p_0 and no formula for it. You cannot evaluate s0s_0, but you can still fit a model sθs_\theta to it. Start from the squared error weighted by the data density, J(θ)=12∫p0(x) (sθ(x)−s0(x))2 dx.J(\theta) = \tfrac12 \int p_0(x)\,\bigl(s_\theta(x) - s_0(x)\bigr)^2\,dx . Expand the square. The term in s02s_0^2 does not depend on θ\theta. The cross term is −∫p0 sθ s0 dx=−∫sθ ∂xp0 dx-\int p_0\,s_\theta\,s_0\,dx = -\int s_\theta\,\partial_x p_0\,dx, and one integration by parts turns it into ∫p0 ∂xsθ dx\int p_0\,\partial_x s_\theta\,dx, provided p0 sθp_0\,s_\theta vanishes at infinity. Up to a constant, J(θ)=Ep0[12 sθ(X)2+∂xsθ(X)]+const.J(\theta) = \mathbb{E}_{p_0}\bigl[\tfrac12\,s_\theta(X)^2 + \partial_x s_\theta(X)\bigr] + \text{const} . This is the score matching objective of Hyvärinen (Hyvärinen, 2005). It needs only samples of p0p_0 and the derivative of the model with respect to its input. The density of the mixture over data space, with three peaks. Shaded bands cover the two tails and the two gaps between the peaks. A label marks one gap as a poorly constrained region and the middle peak as a high-density region. The density of the mixture over data space, with three peaks. Shaded bands cover the two tails and the two gaps between the peaks. A label marks one gap as a poorly constrained region and the middle peak as a high-density region. Score matching weights the error at xx by p0(x)p_0(x). In the shaded gaps and tails the density is close to zero, so a fit can be far from the true score there and still reach a low objective. The objective is still the density-weighted error. Where p0p_0 is small, errors barely count, however large they are. To see the effect, you fit a small network to 2000 samples of p0p_0 and measure two errors. The weighted RMSE (∫pt(x) (sθ(x)−st(x))2 dx)1/2\Bigl(\int p_t(x)\,\bigl(s_\theta(x) - s_t(x)\bigr)^2\,dx\Bigr)^{1/2} measures accuracy where the data is. The grid RMSE averages the squared error uniformly over x∈[−8,8]x \in [-8, 8] and measures accuracy in the gaps and the tails.
Two panels comparing the exact score of the mixture with a score matching fit. Over the range minus 8 to 8 the fit follows the exact score where samples exist and drifts away in both tails. The zoomed panel shows close agreement across the three components. The exact score of p0p_0 (gray) and the score matching fit (orange, dashed), with the density shaded and the 2000 samples marked along the bottom. Left, the whole grid range. Right, a zoom on the components. The fit follows the exact score where the samples are. Beyond the outermost samples it keeps its last slope. The exact score bends near x=6x = 6 and x=−8x = -8, where the tail of the widest component takes over, and no sample reveals that. The weighted RMSE is 0.40, against 2.26 for the zero function. The grid RMSE is 9.9, about 25 times larger and not far from the zero function’s 15.8. The fit is accurate where the samples are. In the tails, where no sample constrains it, it drifts away from the exact score, and the weighted error does not register the difference. The network is small, and training stops after 1000 steps. A network twice as wide drives the sample objective below its population minimum by making ∂xsθ\partial_x s_\theta very negative at the samples themselves. Its weighted RMSE then rises to about 0.7 and its grid RMSE to about 43. Plain score matching has three separate weaknesses here. Regions of low density contain few samples, so the objective carries little information there. When data lie on a lower-dimensional set, as images do in pixel space, the density and its score may not exist in the ambient space at all; this mixture has a smooth density, so that issue does not arise on this page. And a sampler started far from the data passes through exactly the regions where the score is least accurate. Noise at several levels helps with all three. The noisy density ptp_t is smooth and positive everywhere, and it spreads mass into the gaps and the tails, so the training samples reach them. It improves accuracy there without guaranteeing it everywhere.

Learning from noisy observations

Fix one noise level tt. Given the clean point X0=x0X_0 = x_0, the noisy point Xt=atx0+btεX_t = a_t x_0 + b_t \varepsilon is Gaussian with mean atx0a_t x_0 and variance bt2b_t^2. Its conditional score is known in closed form: ∂xlog⁡pt(x∣x0)=−x−atx0bt2=−εbt.\partial_x \log p_t(x \mid x_0) = -\frac{x - a_t x_0}{b_t^2} = -\frac{\varepsilon}{b_t} . Each data point and each noise draw give a regression pair (xt,−ε/bt)(x_t, -\varepsilon/b_t), and forming the pair needs no density. The least squares minimizer over all functions of xtx_t is the conditional mean of the target: s⋆(x)=E[−ε/bt∣Xt=x]=E[∂xlog⁡pt(x∣X0)∣Xt=x]=∂xlog⁡pt(x).\begin{aligned} s^\star(x) &= \mathbb{E}\bigl[-\varepsilon / b_t \mid X_t = x\bigr] \\ &= \mathbb{E}\bigl[\partial_x \log p_t(x \mid X_0) \mid X_t = x\bigr] \\ &= \partial_x \log p_t(x) . \end{aligned} The last step is the identity of the previous section, with the continuous hidden variable X0X_0 in place of the label ZZ. To see it, differentiate pt(x)=∫p0(x0) pt(x∣x0) dx0p_t(x) = \int p_0(x_0)\,p_t(x \mid x_0)\,dx_0 under the integral and divide by pt(x)p_t(x). Regression on noisy pairs therefore recovers the score of the noisy marginal. This is denoising score matching (Vincent, 2011). Flow diagram. A data sample x_0 drawn from p_0 and a noise sample epsilon drawn from a standard normal feed a box that forms the noisy observation x_t = a_t x_0 + b_t epsilon. The noisy observation gives the network input x_t and the regression target minus epsilon over b_t, and both feed the least squares loss, (s_theta(x_t) + epsilon over b_t) squared. Flow diagram. A data sample x_0 drawn from p_0 and a noise sample epsilon drawn from a standard normal feed a box that forms the noisy observation x_t = a_t x_0 + b_t epsilon. The noisy observation gives the network input x_t and the regression target minus epsilon over b_t, and both feed the least squares loss, (s_theta(x_t) + epsilon over b_t) squared. One training pair of denoising score matching at a fixed noise level tt. The data sample and the noise draw give both the input xtx_t and the target −ε/bt-\varepsilon/b_t, so no density is evaluated anywhere. The individual targets are noisy, with variance 1/bt21/b_t^2, but their conditional mean is the score. The check fits a network of xx alone at t=0.3t = 0.3. Its pairs come from the same 2000 samples, with fresh noise at every step. The comparison uses the relative weighted RMSE, the weighted RMSE of the fit divided by that of the zero function.
The fit at t=0.3t = 0.3 has a relative weighted RMSE of 0.04. It uses the same 2000 samples as score matching, and its loss involves only the output of the model, where score matching also needed its derivative.

Learning a family of score fields

Sampling needs the score at every tt between tmin⁡t_{\min} and TT. One network sθ(x,t)s_\theta(x, t) with the time as a second input can learn the whole family. Its loss averages the single-level loss over noise levels, L(θ)=E λ(t) (sθ(Xt,t)+ε/bt)2,\mathcal{L}(\theta) = \mathbb{E}\,\lambda(t)\,\bigl(s_\theta(X_t, t) + \varepsilon / b_t\bigr)^2 , with X0X_0 drawn from the data, ε∼N(0,1)\varepsilon \sim \mathcal{N}(0, 1) and tt drawn from a distribution on [tmin⁡,T][t_{\min}, T]. The target has variance 1/bt21/b_t^2, which blows up as t→0t \to 0. Without a weight, the smallest noise levels would dominate the loss and its gradient. The weight λ(t)=bt2\lambda(t) = b_t^2 puts every level on the same scale. Write the network as a noise predictor, εθ(x,t)=−bt sθ(x,t)\varepsilon_\theta(x, t) = -b_t\,s_\theta(x, t). Then bt2(sθ+ε/bt)2=(bt sθ+ε)2=(ε−εθ(Xt,t))2,\begin{aligned} b_t^2 \bigl(s_\theta + \varepsilon / b_t\bigr)^2 &= \bigl(b_t\,s_\theta + \varepsilon\bigr)^2 \\ &= \bigl(\varepsilon - \varepsilon_\theta(X_t, t)\bigr)^2 , \end{aligned} so the weighted loss is E (ε−εθ(Xt,t))2\mathbb{E}\,\bigl(\varepsilon - \varepsilon_\theta(X_t, t)\bigr)^2. This is the noise prediction loss of DDPM, written in continuous time (Song et al., 2020). The two parameterizations have the same minimizer, but they can train differently, because the optimizer acts on outputs of very different scale. Internally the network predicts noise. Its last layer produces a value of unit scale, which is divided by −bt-b_t to return a score. Its time input is log⁡t\log t, mapped to [0,1][0, 1], together with three sine and cosine features of it. Training times are drawn with log⁡t\log t uniform on [log⁡tmin⁡,log⁡T][\log t_{\min}, \log T], so the small noise levels, where the score changes fastest, get as many samples as the large ones. The two forms of the loss are first evaluated on the same batch.
The two losses agree to rounding error, as the algebra says they must for any network. The training run below uses the weighted score form.
Left, log-log plot of the weighted and grid RMSE of the learned score against t, with the zero function for scale; both errors grow as t falls toward 0.001. Right, exact and learned scores at t = 0.01, 0.1, 0.5 and 2, which overlap except at the smallest t. Left, the weighted and grid RMSE of the learned score at 40 noise levels, with the weighted RMSE of the zero function for scale. Right, the exact score (color) and the learned score (gray, dashed) at four times. For t≥0.1t \ge 0.1 the relative weighted RMSE stays below 0.08, and the grid RMSE stays below 1. The error grows as tt falls: the relative weighted RMSE is 0.15 at t=0.01t = 0.01 and 0.50 at tmin⁡t_{\min}, and the grid RMSE reaches 47 at tmin⁡t_{\min}, where the exact score in the tails is steep and no noisy sample reaches far enough to fix it. The 2000 samples limit the accuracy at small tt. At a fixed tt, the exact minimizer of the denoising loss on 2000 samples is the score of a sum of narrow Gaussians, one at each scaled sample atxia_t x_i with standard deviation btb_t. As t→0t \to 0 that function points at the nearest sample, while the true score points toward higher log density. Its relative weighted RMSE is 2.8 at tmin⁡t_{\min} and 0.36 at t=0.01t = 0.01. At small tt the network does better than the minimizer of its own loss, because its smoothness keeps it from fitting each sample separately.

From density gradients to sampling

The learned score tells you in which direction the log density increases. The simplest way to use it is to follow it. Fix a noise level tt and move particles with dXdτ=st(X).\frac{dX}{d\tau} = s_t(X) . The noise level tt selects the target ptp_t and stays fixed, while the simulation time τ\tau runs. Each particle climbs to the local maximum of ptp_t whose basin of attraction contains its starting point, and stops there, so gradient ascent returns points at the modes and not samples of ptp_t. Adding noise changes that. Langevin dynamics dX=st(X) dτ+2 dWτdX = s_t(X)\,d\tau + \sqrt{2}\,dW_\tau is an SDE with drift sts_t and unit diffusion. Its Fokker-Planck equation has zero flux when st p−∂xp=0s_t\,p - \partial_x p = 0. Because ∂xpt=st pt\partial_x p_t = s_t\,p_t, the density p=ptp = p_t satisfies this, which is the equilibrium condition of the Fokker-Planck section. Langevin dynamics started from ptp_t therefore stays at ptp_t. Started anywhere else it converges to ptp_t, at a rate set by how hard it is to cross the low-density gaps between the modes. Two panels over the same two-peaked density. Left, gradient ascent: particles start spread along a row, and their paths converge onto one point under each peak. Right, Langevin dynamics: particles start from the same row and follow jagged paths that end spread out around each peak. Two panels over the same two-peaked density. Left, gradient ascent: particles start spread along a row, and their paths converge onto one point under each peak. Right, Langevin dynamics: particles start from the same row and follow jagged paths that end spread out around each peak. Left, gradient ascent dX=st(X) dτdX = s_t(X)\,d\tau moves every particle to the mode of its basin, and the spread within each component is lost. Right, Langevin dynamics dX=st(X) dτ+2 dWτdX = s_t(X)\,d\tau + \sqrt{2}\,dW_\tau adds noise that balances the pull toward the modes, so the particles stay spread around each mode. The paths are schematic. The runs below use t=0.05t = 0.05 and the exact score, so they test the dynamics and nothing else. Gradient ascent starts from samples of ptp_t. Langevin starts once from samples of ptp_t and once with every particle at the left mode. The table follows W1W_1 to ptp_t and the mass per component as τ\tau grows. A simulation advances in steps of a fixed size Δτ\Delta\tau, and an Euler-Maruyama step of finite size does not leave ptp_t exactly unchanged, so the last two lines repeat the run from ptp_t with larger steps.
Gradient ascent puts every particle within 3×10−53 \times 10^{-5} of a mode. The share of particles at each mode is close to πk\pi_k, because each basin of attraction holds about the mass of its component, but the spread within each component is gone. Langevin from ptp_t keeps the mass per component within 0.01 of πk\pi_k up to τ=10\tau = 10. Its W1W_1 stays between 0.011 and 0.029, the same size as the 0.024 of a fresh set of exact samples. Started at the left mode, the particles leave it slowly: the mass there falls from 1 to 0.92 at τ=1\tau = 1, 0.67 at τ=5\tau = 5 and 0.51 at τ=10\tau = 10, still far from 0.3. Crossing the gap between two modes is rare, because log⁡pt\log p_t drops deeply between them and the noise must carry a particle against the score across that barrier. With steps of 0.1 and 0.2 the distribution at τ=10\tau = 10 is no longer ptp_t. Its W1W_1 grows to 0.058 and 0.141, and mass shifts from the narrow outer components to the wide middle one. Song and Ermon addressed slow mixing with annealed Langevin dynamics (Song & Ermon, 2019). Their sampler runs Langevin at a sequence of decreasing noise levels and starts each level from the end of the previous one. At large noise the modes overlap and particles move between them freely, and the small noise levels then sharpen each mode. They used a variance-exploding process, Xt=X0+σt εX_t = X_0 + \sigma_t\,\varepsilon, which adds noise without shrinking the data.

Generating samples with the reverse SDE and the probability flow ODE

The reverse SDE and the reverse probability flow ODE from the first section anneal continuously, with no separate Langevin chain at each level. The Fokker-Planck section ran the probability flow ODE backward with the exact score and recovered p0p_0. The reverse SDE passes through the same marginals ptp_t in reverse order (Anderson, 1982), and both samplers work with a learned score in place of the exact one (Song et al., 2020). In the reverse clock u=T−tu = T - t the integrators below step from u=0u = 0 to u=T−tmin⁡u = T - t_{\min}, with steps evenly spaced in log⁡t\log t so that they shrink where the score changes fastest. The SDE uses Euler-Maruyama steps. The ODE uses Heun’s method, a second-order scheme. Two panels, each running from Gaussian noise at the top to the data mixture at the bottom. Left, reverse SDE: 24 rough paths that cross one another and end in three groups. Right, probability flow ODE: 24 smooth paths that never cross and keep their left-to-right order as they split into three groups. Two panels, each running from Gaussian noise at the top to the data mixture at the bottom. Left, reverse SDE: 24 rough paths that cross one another and end in three groups. Right, probability flow ODE: 24 smooth paths that never cross and keep their left-to-right order as they split into three groups. Generation runs from top to bottom, and the color of a path marks the mixture component it ends in. Left, the reverse SDE adds fresh noise at every step, so its paths are rough and cross one another. Right, the probability flow ODE is deterministic. Its paths are smooth, never cross and keep the order of their starting points. The paths are schematic. The computed ones follow below. Four runs separate the sources of error. Each one is done with both samplers. Run A measures integration error. Comparing B with A shows the prior gap, the effect of starting from N(0,1)\mathcal{N}(0, 1) in place of pTp_T. Comparing C with A shows the error of the learned score. Run D is the practical model, which needs nothing but the samples. The effects need not add up, so D is measured directly.
Top, 20 rough reverse SDE trajectories and 20 smooth, non-crossing probability flow ODE trajectories plotted against reverse time from 0 to 4. Bottom, four histograms at t = 1.99, 0.503, 0.101 and 0.001, where the SDE and ODE histograms both match the exact density as it changes from one bell curve to three peaks. Top, 20 trajectories of run A for each sampler, in the reverse clock. SDE paths are rough and wander. ODE paths are smooth, never cross, and keep their order from start to end. Bottom, histograms of all particles of both samplers at four reverse times, with the exact ptp_t. The two samplers move individual particles differently, but their histograms agree with each other and with ptp_t at every time. Run D is repeated with two more networks, trained with seeds 1 and 2, so that the spread from one training run to the next can be compared with the differences between runs.
Run A sets the baseline. The ODE reaches W1=0.007W_1 = 0.007 and the SDE 0.021, against 0.013 for a fresh set of exact samples. Halving the step size leaves the ODE value unchanged to three decimals, so for the ODE the integration error is small next to the other effects in the table. The SDE moves to 0.026. The refined run draws new noise, so this change mixes integration error with sampling noise. For the SDE, these two together are about the same size as the other effects: runs C and D give 0.028 and 0.024. The prior gap is visible for the ODE. Run B gives 0.031 for the ODE, against 0.007 for run A. The numerical checks below compute the same gap without sampling, by pushing N(0,1)\mathcal{N}(0, 1) through the exact ODE map. The result is W1=0.021W_1 = 0.021 to ptmin⁡p_{t_{\min}}, about twice W1(pT,N(0,1))=0.011W_1(p_T, \mathcal{N}(0, 1)) = 0.011 and above the sampling floor of 0.013. The ODE has no noise of its own, so the mismatch at the start is carried to the end and grows on the way. The SDE gives 0.006 for run B and 0.021 for run A. Both values sit within sampling noise of the floor of 0.013±0.0040.013 \pm 0.004 (each about two standard deviations from it), so these runs show no prior gap for the SDE. Its fresh noise at every step contracts the start mismatch below the sampling noise. The learned score has an effect of about the same size. Runs C and D give W1W_1 between 0.024 and 0.034, about twice the exact-sample value. Over three training seeds, run D gives 0.042±0.0130.042 \pm 0.013 for the ODE and 0.034±0.0090.034 \pm 0.009 for the SDE. For the ODE, runs B, C and D are level, so the prior gap and the score error are comparable there. For the SDE the score error is larger than the prior gap. C and D differ by 0.003 for the ODE and 0.004 for the SDE, less than the seed spread, so these runs cannot tell how the two effects combine. The mass per component is right in every run. Across all runs, seeds and both samplers it stays within 0.011 of πk\pi_k. The proportions are settled at large tt, where the network is accurate. The remaining W1W_1 error is in the shape of the components. It most likely comes from the last steps near tmin⁡t_{\min}, where the relative weighted RMSE of the learned score rises from 0.15 to 0.50, but these runs do not isolate that.

Further connections

Conditional generation needs the score of p(x∣y)p(x \mid y) for a condition yy such as a class label. Bayes’ rule splits it into two terms, ∇xlog⁡p(x∣y)=∇xlog⁡p(x)+∇xlog⁡p(y∣x)\nabla_x \log p(x \mid y) = \nabla_x \log p(x) + \nabla_x \log p(y \mid x). The first is the unconditional score learned on this page. The second is the gradient of a classifier that predicts yy from a noisy xx. Adding the two steers the same samplers toward samples that match yy. The network on this page predicts noise internally and returns a score, and other parameterizations are equally valid. The DDPM section collects them in one table: noise, clean data, score, v-prediction and the probability flow velocity, each computable from the others for Xt=atX0+btεX_t = a_t X_0 + b_t \varepsilon. The probability flow ODE needs only the velocity vt=−x−stv_t = -x - s_t, and the score is a step on the way to it. For the same Gaussian path, regressing onto −ε/bt-\varepsilon / b_t gives the score. Regressing onto a˙tX0+b˙tε\dot a_t X_0 + \dot b_t \varepsilon, the time derivative of XtX_t along one noisy path, gives the velocity directly, by the same conditional mean argument. If the velocity is what you need, why estimate the score first?

Numerical checks

In one dimension the probability flow ODE has an exact solution. It preserves the order of particles, so it maps each point to the point with the same CDF value: Xtmin⁡=Ftmin⁡−1(FT(XT))X_{t_{\min}} = F_{t_{\min}}^{-1}\bigl(F_T(X_T)\bigr), the monotone quantile map of the probability transport chapter. Applied to the exact starting samples of run A, it gives a reference for the ODE integrator that does not depend on it. The same map gives the prior gap of the ODE without sampling: push N(0,1)\mathcal{N}(0, 1) through it and measure W1W_1 to ptmin⁡p_{t_{\min}} from quantile functions. Ten sets of exact samples of ptmin⁡p_{t_{\min}} give the sampling floor that this gap is compared with. The last check is the cost of the small-noise cutoff: the samplers stop at ptmin⁡p_{t_{\min}}, not at p0p_0.
The integrator agrees with the quantile map to 10−310^{-3} at 500 steps and 2.4×10−42.4 \times 10^{-4} at 1000. The error falls by a factor of four when the step halves, as expected for a second-order method. The population prior gap is 0.021, above the sampling floor of 0.013±0.0040.013 \pm 0.004, so the gap between runs A and B of the ODE is not sampling noise. The distance W1(p0,ptmin⁡)=0.002W_1(p_0, p_{t_{\min}}) = 0.002 is smaller than every W1W_1 in the table, so the cutoff accounts for little of the sampling error. It is still a real difference: the samplers target ptmin⁡p_{t_{\min}}, and p0p_0 only up to this distance.

Further reading

Yang Song’s lecture covers diffusion and score-based generative models (MITCBMM, n.d.). His tutorial on score-based generative modeling trains a score network on images. It uses the variance-exploding process, Xt=X0+σt εX_t = X_0 + \sigma_t\,\varepsilon, in place of the Ornstein-Uhlenbeck process of this page, so it has no drift and its noise variance keeps growing with tt.

References

  • Anderson, B. (1982). Reverse-time diffusion equation models. Stoch. Process. Their Appl. DOI
  • Hyvärinen, A. (2005). Estimation of non-normalized statistical models by score matching. Journal of Machine Learning Research. Link
  • Song, Y., Sohl-Dickstein, J., Kingma, D., Kumar, A., Ermon, S., et al. (2020). Score-based generative modeling through stochastic differential equations. arXiv [cs.LG]. DOI
  • Song, Y., Ermon, S. (2019). Generative modeling by estimating gradients of the data distribution. arXiv [cs.LG]. DOI
  • Vincent, P. (2011). A connection between score matching and denoising autoencoders. Neural Comput. DOI
  • MITCBMM (n.d.). Diffusion and score-based generative models. Link

Found an error on this page? Report an issue.