Score-Based Generative Modeling via Stochastic Differential Equations: How Continuous SDEs and Score Matching Unify Diffusion Models

Diffusion and score-based models represent one of the foundational paradigms of modern generative artificial intelligence, underpinning systems across image synthesis, video generation, audio modeling, and continuous multimodal representations. For years, generative diffusion was approached from two distinct perspectives: discrete-step denoising diffusion probabilistic models (DDPM) pioneered by Sohl-Dickstein et al. and Ho et al., and score matching with Langevin dynamics (SMLD / NCSN) introduc

8 min
Score-Based Generative Modeling via Stochastic Differential Equations: How Continuous SDEs and Score Matching Unify Diffusion Models

Diffusion and score-based models represent one of the foundational paradigms of modern generative artificial intelligence, underpinning systems across image synthesis, video generation, audio modeling, and continuous multimodal representations. For years, generative diffusion was approached from two distinct perspectives: discrete-step denoising diffusion probabilistic models (DDPM) pioneered by Sohl-Dickstein et al. and Ho et al., and score matching with Langevin dynamics (SMLD / NCSN) introduced by Song and Ermon.

In 2020, Song et al. unified both frameworks under the continuous-time mathematical theory of Stochastic Differential Equations (SDEs). By treating the noise corruption and generative reconstruction processes as continuous paths governed by forward and reverse-time Itô SDEs, the framework revealed that discrete diffusion models are numerical discretizations of underlying continuous processes.

This continuous formulation unlocked several practical capabilities: exact likelihood computation via continuous normalizing flows, deterministic sampling via the Probability Flow ODE, predictor-corrector sampling architectures, and flexible controllable generation.


1. The Core Formulation: Forward and Reverse-Time SDEs

Traditional diffusion models define a discrete Markov chain over TT distinct time steps {x0,x1,,xT}\{x_0, x_1, \dots, x_T\}. In the continuous limit as TT \to \infty and the step size Δt0\Delta t \to 0, the forward corruption process evolves according to an Itô Stochastic Differential Equation:

dx=f(x,t)dt+g(t)dwdx = f(x, t) dt + g(t) dw

In this equation:

  • x(t)Rdx(t) \in \mathbb{R}^d represents the continuous state vector indexed by continuous time t[0,T]t \in [0, T].
  • f(x,t):Rd×[0,T]Rdf(x, t): \mathbb{R}^d \times [0, T] \to \mathbb{R}^d is the drift coefficient, governing deterministic state shifts over time.
  • g(t):[0,T]Rg(t): [0, T] \to \mathbb{R} is the diffusion coefficient, modulating the scale of injected stochastic noise.
  • wRdw \in \mathbb{R}^d denotes standard Brownian motion (a Wiener process), with infinitesimal increment dwN(0,Idt)dw \sim \mathcal{N}(0, I dt).

As tt evolves from 00 to TT, the data distribution p0(x)p_0(x) is smoothly transformed into a tractable prior distribution pT(x)p_T(x), typically an isotropic standard Gaussian distribution N(0,σmax2I)\mathcal{N}(0, \sigma_{\max}^2 I) or N(0,I)\mathcal{N}(0, I).

Continuous-time forward SDE diffusion, reverse-time score-guided generation, and deterministic Probability Flow ODE trajectories

The Reverse-Time SDE

To generate new samples, one must reverse the continuous diffusion process from t=Tt = T back to t=0t = 0. Using classical results in stochastic calculus established by Brian D. O. Anderson (1982)90051-5), the reverse of an Itô diffusion process is itself an Itô diffusion running backward in time:

dx=[f(x,t)g(t)2xlogpt(x)]dt+g(t)dwˉdx = \left[ f(x, t) - g(t)^2 \nabla_x \log p_t(x) \right] dt + g(t) d\bar{w}

Here, dtdt represents an infinitesimal negative time increment (marching backward from TT to 00), dwˉd\bar{w} denotes a reverse-time standard Brownian motion, and xlogpt(x)\nabla_x \log p_t(x) is the score function: the spatial gradient of the log-probability density of the marginal distribution pt(x)p_t(x) at time tt.

The critical insight of score-based modeling is that the drift f(x,t)f(x, t) and diffusion g(t)g(t) are predetermined analytical design choices. The only unknown quantity required to simulate the reverse process is the time-dependent score function xlogpt(x)\nabla_x \log p_t(x).


2. Unifying DDPM and SMLD in Continuous Time

The continuous SDE framework demonstrates that discrete diffusion algorithms are simply specific parameterizations of drift and diffusion coefficients:

Variance Exploding (VE) SDE (Continuous SMLD)

Score Matching with Langevin Dynamics (SMLD / NCSN) perturbs data with a sequence of growing Gaussian noise variances σ1<σ2<<σN\sigma_1 < \sigma_2 < \dots < \sigma_N. In continuous time, this corresponds to a process where the drift is zero and the variance grows monotonically:

f(x,t)=0,g(t)=d[σ2(t)]dtf(x, t) = 0, \quad g(t) = \sqrt{\frac{d[\sigma^2(t)]}{dt}}

The resulting VE-SDE is:

dx=d[σ2(t)]dtdwdx = \sqrt{\frac{d[\sigma^2(t)]}{dt}} dw

The perturbation kernel from 00 to tt is Gaussian:

p0t(x(t)x(0))=N(x(t);x(0),(σ2(t)σ2(0))I)p_{0t}(x(t) \mid x(0)) = \mathcal{N}\left(x(t); x(0), \left(\sigma^2(t) - \sigma^2(0)\right) I\right)

Because the state variance diverges as tTt \to T, this formulation is termed Variance Exploding.

Variance Preserving (VP) SDE (Continuous DDPM)

Denoising Diffusion Probabilistic Models (DDPM) scale down the input vector at each step while adding scaled noise to keep the total variance bounded:

xi=1βixi1+βizi1x_i = \sqrt{1 - \beta_i} x_{i-1} + \sqrt{\beta_i} z_{i-1}

Taking the continuous limit where βi=β(t)Δt\beta_i = \beta(t) \Delta t, the drift and diffusion become:

f(x,t)=12β(t)x,g(t)=β(t)f(x, t) = -\frac{1}{2} \beta(t) x, \quad g(t) = \sqrt{\beta(t)}

The resulting VP-SDE is:

dx=12β(t)xdt+β(t)dwdx = -\frac{1}{2} \beta(t) x dt + \sqrt{\beta(t)} dw

The transition kernel satisfies:

p0t(x(t)x(0))=N(x(t);x(0)e120tβ(s)ds,(1e0tβ(s)ds)I)p_{0t}(x(t) \mid x(0)) = \mathcal{N}\left(x(t); x(0) e^{-\frac{1}{2}\int_0^t \beta(s)ds}, \left(1 - e^{-\int_0^t \beta(s)ds}\right) I\right)

If the initial data variance is normalized to 1, the total variance remains exactly 1 across all tt, hence Variance Preserving.

Sub-VP SDE

Song et al. introduced the sub-VP SDE, which modifies the diffusion coefficient:

g(t)=β(t)(1e20tβ(s)ds)g(t) = \sqrt{\beta(t) \left(1 - e^{-2\int_0^t \beta(s)ds}\right)}

This ensures that the variance at any intermediate time tt is strictly upper-bounded by the VP-SDE variance, yielding empirically superior negative log-likelihood (NLL) bounds.


3. Training the Score Network via Denoising Score Matching

Direct computation of xlogpt(x)\nabla_x \log p_t(x) is impossible because the true marginal data density pt(x)=p0(x0)p0t(xx0)dx0p_t(x) = \int p_0(x_0) p_{0t}(x \mid x_0) dx_0 is intractable.

However, by extending Vincent's (2011) denoising score matching to continuous time, we train a neural network sθ(x,t)s_\theta(x, t) to approximate the score of the tractable transition kernel p0t(x(t)x(0))p_{0t}(x(t) \mid x(0)).

The continuous denoising score matching loss objective is:

L(θ)=EtU(ϵ,T)Ex(0)p0Ex(t)p0t(x(t)x(0))[λ(t)sθ(x(t),t)x(t)logp0t(x(t)x(0))22]\mathcal{L}(\theta) = \mathbb{E}_{t \sim \mathcal{U}(\epsilon, T)} \mathbb{E}_{x(0) \sim p_0} \mathbb{E}_{x(t) \sim p_{0t}(x(t) \mid x(0))} \left[ \lambda(t) \left\| s_\theta(x(t), t) - \nabla_{x(t)} \log p_{0t}(x(t) \mid x(0)) \right\|_2^2 \right]

where λ(t):[0,T]R+\lambda(t): [0, T] \to \mathbb{R}^+ is a positive weighting function, typically chosen as $\lambda(t) \propto \frac{1}{\mathbb{E}\left[\|\nabla_{x(t)} \log p_{0t}(x(t) \mid x(0))\|_2^2\right]}$ to balance loss magnitudes across different noise scales.

Equivalence to Noise Prediction

Because p0t(x(t)x(0))p_{0t}(x(t) \mid x(0)) is Gaussian with mean μ(x(0),t)\mu(x(0), t) and variance σ2(t)I\sigma^2(t) I, its ground-truth score has a simple analytical form:

x(t)logp0t(x(t)x(0))=x(t)μ(x(0),t)σ2(t)=ϵσ(t)\nabla_{x(t)} \log p_{0t}(x(t) \mid x(0)) = -\frac{x(t) - \mu(x(0), t)}{\sigma^2(t)} = -\frac{\epsilon}{\sigma(t)}

where ϵN(0,I)\epsilon \sim \mathcal{N}(0, I) is the standard Gaussian noise vector used to generate x(t)x(t).

Thus, predicting the score function sθ(x(t),t)s_\theta(x(t), t) is mathematically equivalent to predicting the injected noise ϵθ(x(t),t)=σ(t)sθ(x(t),t)\epsilon_\theta(x(t), t) = -\sigma(t) s_\theta(x(t), t), establishing an exact identity between score matching and DDPM objective formulations.


4. The Probability Flow ODE and Exact Likelihoods

Every Itô SDE of the form dx=f(x,t)dt+g(t)dwdx = f(x, t)dt + g(t)dw possesses an associated deterministic Ordinary Differential Equation (ODE), termed the Probability Flow ODE:

dxdt=f(x,t)12g(t)2xlogpt(x)\frac{dx}{dt} = f(x, t) - \frac{1}{2} g(t)^2 \nabla_x \log p_t(x)

The Probability Flow ODE shares the exact same marginal probability densities pt(x)p_t(x) as the stochastic SDE for all t[0,T]t \in [0, T].

+-------------------------------------------------------------+
|                     Forward SDE                             |
|           dx = f(x, t)dt + g(t)dw (adds noise)              |
+------------------------------+------------------------------+
                               |
                               v
+-------------------------------------------------------------+
|                  Learned Score Function                     |
|                 s_theta(x, t) ~= grad_x log p_t(x)          |
+------------------------------+------------------------------+
                               |
               +---------------+---------------+
               |                               |
               v                               v
+-----------------------------+ +-----------------------------+
|      Reverse-Time SDE       | |    Probability Flow ODE     |
| dx = [f - g^2 s_theta]dt    | | dx/dt = f - 0.5 g^2 s_theta |
|         + g d_w_bar         | |                             |
|  (Stochastic generation)    | |  (Deterministic trajectory) |
+-----------------------------+ +-----------------------------+
                                               |
                               +---------------+---------------+
                               |                               |
                               v                               v
                +-----------------------------+ +-------------+
                | Continuous Normalizing Flow | |  Fast ODE   |
                |   Exact Log-Likelihood      | |   Solvers   |
                | Hutchinson Trace Estimator  | | (Dopri5/RK4)|
                +-----------------------------+ +-------------+

Exact Log-Likelihood via Continuous Normalizing Flows

Because the Probability Flow ODE defines a deterministic, invertible mapping between data space x(0)x(0) and latent space x(T)x(T), it can be treated as a Continuous Normalizing Flow (CNF).

Using the instantaneous change of variables formula, the exact log-likelihood of any data point x(0)x(0) can be computed by integrating the divergence of the drift field over time:

logp0(x(0))=logpT(x(T))+0Tf~θ(x(t),t)dt\log p_0(x(0)) = \log p_T(x(T)) + \int_0^T \nabla \cdot \tilde{f}_\theta(x(t), t) dt

where f~θ(x,t)=f(x,t)12g(t)2sθ(x,t)\tilde{f}_\theta(x, t) = f(x, t) - \frac{1}{2} g(t)^2 s_\theta(x, t).

The divergence f~θ\nabla \cdot \tilde{f}_\theta involves computing the trace of the Jacobian matrix Tr(f~θx)\text{Tr}\left(\frac{\partial \tilde{f}_\theta}{\partial x}\right), which is computed efficiently using the Skilling-Hutchinson trace estimator:

f~θ(x,t)=EvN(0,I)[vT(xf~θ(x,t))v]\nabla \cdot \tilde{f}_\theta(x, t) = \mathbb{E}_{v \sim \mathcal{N}(0, I)} \left[ v^T \left( \nabla_x \tilde{f}_\theta(x, t) \right) v \right]

This requires only a single vector-Jacobian product (VJP) per step via automatic differentiation, turning score models into exact density estimators without partition function intractability.


5. Sampling Architectures: Predictor-Corrector Framework

The continuous framework allows decoupling model training from the choice of numerical solvers. During inference, one can use standard high-order numerical ODE solvers (such as Dormand-Prince / Dopri5 or Runge-Kutta 4) or hybrid Predictor-Corrector (PC) samplers.

A Predictor-Corrector sampler alternates between two complementary operations at each discrete time step tit_i:

  1. Predictor Step: Uses a numerical SDE solver (such as Euler-Maruyama or Reverse Diffusion) to advance the state from tit_i to ti1t_{i-1}, predicting the coarse evolution of the sample.
  2. Corrector Step: Runs several steps of score-based Markov Chain Monte Carlo (MCMC), such as annealed Langevin dynamics, at fixed time ti1t_{i-1}:

xx+ϵk2sθ(x,ti1)+ϵkz,zN(0,I)x \leftarrow x + \frac{\epsilon_k}{2} s_\theta(x, t_{i-1}) + \sqrt{\epsilon_k} z, \quad z \sim \mathcal{N}(0, I)

The corrector step acts as an error-correction mechanism, pulling the trajectory back toward the high-density regions of the intermediate marginal distribution pti1(x)p_{t_{i-1}}(x) whenever numerical discretization error accumulates.

import torch

def euler_maruyama_predictor_step(x, t, dt, f_fn, g_fn, score_fn):
    """Executes a single reverse-time Euler-Maruyama SDE step."""
    drift = f_fn(x, t) - (g_fn(t) ** 2) * score_fn(x, t)
    diffusion = g_fn(t)
    z = torch.randn_like(x) if t > 0 else torch.zeros_like(x)
    # Note: dt is negative when stepping backwards from T to 0
    x_prev = x + drift * dt + diffusion * torch.sqrt(torch.abs(dt)) * z
    return x_prev

def langevin_corrector_step(x, t, score_fn, r=0.16, snr=0.16):
    """Executes a single Langevin dynamics corrector step at fixed time t."""
    grad = score_fn(x, t)
    noise = torch.randn_like(x)
    
    # Calculate step size based on Signal-to-Noise Ratio (SNR)
    grad_norm = torch.norm(grad.reshape(grad.shape[0], -1), dim=-1).mean()
    noise_norm = torch.norm(noise.reshape(noise.shape[0], -1), dim=-1).mean()
    step_size = 2 * (snr * noise_norm / grad_norm) ** 2
    
    x = x + step_size * grad + torch.sqrt(2 * step_size) * noise
    return x

6. Structural Trade-Offs and Architectural Impact

The transition to continuous score SDEs reshaped generative modeling research across several axes:

| Feature | Discrete Diffusion (DDPM / SMLD) | Continuous Score SDEs | | :--- | :--- | :--- | | Time Representation | Discrete index t{1,,N}t \in \{1, \dots, N\} | Continuous variable t[0,T]t \in [0, T] | | Sampling Mechanism | Fixed step-by-step Markov reverse chain | Flexible SDE, ODE, or Predictor-Corrector solvers | | Sample Trajectory | Purely stochastic | Choice between stochastic (SDE) and deterministic (ODE) | | Likelihood Evaluation | Variational Lower Bound (ELBO) | Exact log-likelihood via Probability Flow ODE | | Latent Inversion | Approximate or heuristic (DDIM) | Exact bidirectional encoding via ODE flow | | Step-Count Flexibility | Requires fixed retraining or resampling schedule | Arbitrary number of function evaluations (NFEs) at inference |

Descendants and Modern Offshoots

The mathematical rigor established by continuous score SDEs provided the direct theoretical foundation for several subsequent breakthroughs:

  • Flow Matching and Continuous Normalizing Flows: Lipman et al. (2022) generalized score SDEs by formulating generative modeling as regressing arbitrary continuous velocity vector fields along optimal transport paths, removing the restriction to isotropic Gaussian diffusion.
  • Consistency Models: Song et al. (2023) used the trajectories of the Probability Flow ODE to enforce a self-consistency mapping from any point on the ODE path directly to its origin x(0)x(0), enabling single-step and few-step generation.
  • Diffusion Transformers (DiT): Peebles and Xie (2022) scaled the underlying score network from standard U-Nets to vision transformers, operating on tokenized patch representations conditioned on continuous time embeddings tt.

By recasting diffusion from discrete heuristic noise steps into continuous stochastic calculus, score-based SDEs established a unified theoretical foundation that continues to govern modern generative architectures.


Sources

Written by

More to read

  • Retrieval-Augmented Fine-Tuning (RAFT) in Production: Architecture, Synthetic Distractor Pipelines, and Evaluation

    Standard approaches to enterprise domain adaptation typically force a choice between two paradigms: Supervised Fine-Tuning (SFT) or Retrieval-Augmented Generation (RAG). SFT bakes domain knowledge directly into model weights, functioning like a closed-book exam. When facts change or precise source attribution is required, SFT models often hallucinate or fail to incorporate updated context. Conversely, standard RAG operates like an open-book exam without prior preparation. The base model reads re

    1 min
  • The Information Bottleneck in Deep Learning: How Mutual Information Compression Shapes Generalization and Neural Representations

    The Information Bottleneck in Deep Learning: How Mutual Information Compression Shapes Generalization and Neural Representations Classical statistical learning theory struggles to explain why overparameterized deep neural networks generalize well to unseen test data. Traditional complexity measures such as Vapnik-Chervonenkis (VC) dimension and Rademacher complexity scale with the raw count of tunable weights, predicting severe overfitting when parameter counts exceed dataset sample sizes. Yet

    1 min
  • Fine-Tuning vs. RAG in Production: Knowledge Injection, Task Adaptation, Latency Economics, and Hybrid Architecture Trade-Offs

    Fine-Tuning vs. RAG in Production: Knowledge Injection, Task Adaptation, Latency Economics, and Hybrid Architecture Trade-Offs When adapting large language models to domain-specific enterprise workloads, engineering teams face a fundamental architectural choice: modify the model's parametric weights via fine-tuning, or supply dynamic context at inference time via Retrieval-Augmented Generation (RAG). While early discussions often framed this decision as a binary trade-off, empirical evaluation

    1 min