Skip to main content
Open In Colab

The target distribution

The same 2D Mixture of Gaussians used by the DDPM, DDIM, and Brownian motion tutorials: three anisotropic Gaussians, seed 42, 300 points total. To DDPM you trained a noise predictor ϵθ\epsilon_\theta. Here you train a score predictor sθ(x,σ)s_\theta(x, \sigma) that approximates xlogpσ(x)\nabla_x \log p_\sigma(x), the gradient of the log-density of the data after Gaussian smoothing at scale σ\sigma.
Output from cell 2

Denoising score matching

We perturb data with Gaussian noise at scale σ\sigma: x~=x+σϵ,ϵN(0,I)\tilde x = x + \sigma\, \epsilon, \qquad \epsilon \sim \mathcal{N}(0, I) The score of the smoothed density satisfies x~logpσ(x~x)=x~xσ2=ϵσ\nabla_{\tilde x} \log p_\sigma(\tilde x \mid x) = -\frac{\tilde x - x}{\sigma^2} = -\frac{\epsilon}{\sigma} so the denoising score-matching objective L=Ex,σ,ϵ ⁣[σ2sθ(x~,σ)+ϵ/σ2]L = \mathbb{E}_{x, \sigma, \epsilon}\!\left[\,\sigma^2 \big\| s_\theta(\tilde x, \sigma) + \epsilon / \sigma \big\|^2\,\right] trains sθ(x~,σ)s_\theta(\tilde x, \sigma) to estimate logpσ(x~)\nabla \log p_\sigma(\tilde x) across a range of noise scales. The σ2\sigma^2 weighting makes the loss balanced across scales, Song & Ermon 2019. We use a logarithmic noise schedule σ[σmin,σmax]\sigma \in [\sigma_{\min}, \sigma_{\max}] with σmin=0.05\sigma_{\min} = 0.05, σmax=5.0\sigma_{\max} = 5.0.

Training

Standard DSM loop: sample a batch, sample a per-example σ\sigma, perturb, predict the score, minimize the noise-conditional loss.
Output from cell 5

The learned score field

Evaluate sθs_\theta on a grid at low noise (σ=0.3\sigma = 0.3), at this scale the score points toward the data manifold, so the field should converge into the three MoG modes.
Output from cell 7 Above: the analytical score field logp(x)\nabla \log p(x) for this MoG, manimgl-rendered. Compare with the matplotlib quiver of the learned sθs_\theta, both should pull mass toward the three component centers.

Annealed Langevin sampling

Generate samples by running Langevin dynamics at decreasing noise levels: xk+1=xk+αksθ(xk,σk)+2αkzk,zkN(0,I)x_{k+1} = x_k + \alpha_k\, s_\theta(x_k, \sigma_k) + \sqrt{2\alpha_k}\, z_k, \quad z_k \sim \mathcal{N}(0, I) with step size αk=ϵσk2/σmin2\alpha_k = \epsilon \cdot \sigma_k^2 / \sigma_{\min}^2, Song & Ermon’s recipe. Larger σ\sigma steps cover broad regions of space; smaller σ\sigma steps refine onto the data manifold.
Above: 80 particles released uniformly, then annealed-Langevin-stepped through a geometric noise schedule from σ=2.5\sigma = 2.5 down to σ=0.15\sigma = 0.15. The cloud condenses into the three MoG components. Output from cell 9

Reverse-time SDE

The variance-exploding (VE) SDE has forward dxt=d[σt2]dtdWtdx_t = \sqrt{\frac{d[\sigma_t^2]}{dt}}\, dW_t and reverse-time form dxt=d[σt2]dtsθ(xt,σt)dt+d[σt2]dtdWˉtdx_t = -\frac{d[\sigma_t^2]}{dt}\, s_\theta(x_t, \sigma_t)\, dt + \sqrt{\frac{d[\sigma_t^2]}{dt}}\, d\bar W_t Discretize with Euler-Maruyama from t=1t = 1 down to t=0t = 0. This is the same chain as DDIM at η=1\eta = 1 in the score-SDE framework.
Above: 60 particles seeded broadly, evolving under the reverse-time SDE driven by the analytical MoG score. Trails show each particle’s path as it condenses into one of the three modes. Output from cell 11

Connections to other concepts

  • Score-matching is the unifying view. DDPM’s noise predictor ϵθ\epsilon_\theta is, up to the scaling 1/σ-1/\sigma, a score predictor; DDIM’s deterministic sampler is the probability-flow ODE limit of the same score-SDE. The framework above subsumes both.
  • Sampler decoupling. Once you have sθs_\theta, you can swap samplers: annealed Langevin, reverse SDE, probability-flow ODE, predictor-corrector. The trained network is unchanged.
  • The information-theoretic angle. sθ(x,t)s_\theta(x, t) is the local geometry of logpt(x)\log p_t(x), the same quantity that, integrated through Fisher-information identities, gives mutual information bounds. See AURA-672 for the score → Fisher → MI thread.

References

  1. Song, Ermon. Generative Modeling by Estimating Gradients of the Data Distribution. NeurIPS 2019. arxiv.org/abs/1907.05600
  2. Song, Sohl-Dickstein, Kingma, Kumar, Ermon, Poole. Score-Based Generative Modeling through Stochastic Differential Equations. ICLR 2021. arxiv.org/abs/2011.13456
  3. Vincent. A Connection Between Score Matching and Denoising Autoencoders. Neural Computation 2011.

PyTorch reference