SDE Formulation of Diffusion Models¶
This directory contains comprehensive documentation on the Stochastic Differential Equation (SDE) perspective on diffusion models, providing a continuous-time view that unifies DDPM, DDIM, and other variants.
The SDE formulation reveals diffusion models as continuous stochastic processes, enabling flexible sampling, theoretical analysis, and connections to classical stochastic calculus.
Core Documentation Series¶
This series mirrors the structure of DDPM and flow matching documentation, separating theory, training, and sampling.
| Document | Description |
|---|---|
| 00_sde_overview.md | Overview: High-level introduction, why SDE view matters, key concepts |
| 01_diffusion_sde_view.md | Foundations: Detailed SDE formulation, forward/reverse processes |
| 02_sde_training.md | Training: How training works — NO SDE solvers needed! |
| 03_sde_sampling.md | Sampling: How to generate samples — SDE/ODE solvers used here |
Supplementary Documents¶
| Document | Description |
|---|---|
| 01a_diffusion_sde_view_QA.md | Design principles Q&A |
| 02a_taylor_expansion.md | Taylor expansions in diffusion |
| 02b_fokker_plank_eq.md | Fokker-Planck equation derivation |
| 02c_ddpm_to_vpsde.md | From DDPM to VP-SDE (reverse direction) |
| 03b_ddim_update_coeff.md | DDIM coefficients from theory |
Quick Navigation¶
For Beginners¶
- Start with SDE Overview for high-level understanding
- Read SDE Foundations for detailed formulation
- See DDPM from SDE for discrete-continuous connection
- Understand Solving VP-SDE for exact solutions
For Implementation¶
- DDPM Connection — How DDPM emerges from VP-SDE
- DDIM Coefficients — Exact formulas for code
- Reverse SDE & ODE — Sampling methods
For Theory Deep Dive¶
- Fokker-Planck Equation — Probability evolution PDE
- Taylor Expansions — Mathematical foundations
- VP-SDE from DDPM — Continuous limit derivation
Key Concepts¶
The SDE Formulation¶
Forward SDE (data → noise):
Reverse SDE (noise → data):
$$
dx = \left[f(x, t) - g(t)^2 \nabla_x \log p_t(x)\right]dt + g(t)\,d\bar{w} $$
Key insight: Only the score function \(\nabla_x \log p_t(x)\) needs to be learned.
Variance-Preserving SDE (VP-SDE)¶
The most common formulation, corresponding to DDPM:
Properties:
- Preserves variance over time
- Discretizes to DDPM forward process
- Closed-form marginals: \(q(x_t | x_0) = \mathcal{N}(\sqrt{\bar{\alpha}_t} x_0, (1-\bar{\alpha}_t)I)\)
Probability Flow ODE¶
Deterministic alternative to reverse SDE with same marginals:
Key property: DDIM is the discretization of this ODE.
Comparison: Discrete vs Continuous¶
| Aspect | DDPM (Discrete) | SDE (Continuous) |
|---|---|---|
| Time | Steps \(t = 0, 1, \ldots, T\) | Continuous \(t \in [0, T]\) |
| Forward | Markov chain | Stochastic process |
| Notation | \(\alpha_t\), \(\bar{\alpha}_t\) (products) | \(\beta(t)\), integrals |
| Sampling | Fixed schedule | Flexible steps |
| Theory | Discrete probability | Stochastic calculus |
| Flexibility | Limited | High |
Key connection: DDPM is the Euler-Maruyama discretization of VP-SDE.
Learning Path¶
Conceptual Understanding¶
- SDE Overview — Why SDE view matters
- Unified framework for diffusion variants
- Flexible sampling strategies
-
Theoretical foundations
-
SDE Foundations — Detailed formulation
- Forward and reverse SDEs
- Score functions
- Brownian motion
Practical Connection¶
- DDPM from SDE — Discretization
- Euler-Maruyama method
- Why DDPM predicts noise
-
Forward and reverse processes
-
Solving VP-SDE — Exact solutions
- Closed-form marginals
- Connection to \(\bar{\alpha}_t\)
- Products → integrals
Advanced Topics¶
- Reverse SDE & Probability Flow ODE — Sampling
- Stochastic vs deterministic
- DDPM vs DDIM
-
The \(\eta\) parameter
-
DDIM Coefficients — Theory to code
- Exact update formulas
- Fast sampling
-
Implementation details
-
Fokker-Planck Equation — Advanced theory
- Probability density evolution
- PDE perspective
- Weak vs strong solutions
Interactive Resources¶
For hands-on learning with code:
- Location:
notebooks/diffusion/02_sde_formulation/ - Contents:
README.md— Comprehensive theory document02_sde_formulation.ipynb— Interactive notebook with visualizationssde_QA.md— Common questions answered
8 Focused Supplements: 1. Forward SDE Design Choices (VP/VE/sub-VP) 2. Brownian Motion Dimensionality 3. Equivalent Parameterizations (score ↔ noise ↔ \(x_0\)) 4. Training Loss and Denoising 5. Reverse SDE and Probability Flow ODE 6. Fokker-Planck and Effective Drift 7. Fokker-Planck Equation (detailed derivation) 8. Dimensional Analysis
What's Here¶
This docs/SDE/ directory contains tutorial-style mathematical derivations that complement the interactive notebooks. These documents provide:
- Detailed line-by-line derivations
- Mathematical foundations and proofs
- Historical context and development
- Advanced theoretical connections
Documents in This Directory¶
Core SDE Theory¶
- 01_diffusion_sde_view.md — SDE Formulation Overview
- Forward and reverse SDEs
- Score functions and their role
- Brownian motion fundamentals
-
Connection to diffusion models
-
01a_diffusion_sde_view_QA.md — Design Principles Q&A
- Why specific drift functions?
- Score vs. noise prediction
- High-dimensional intuition
- Practical design choices
DDPM ↔ SDE Connections¶
- 02_sde_and_ddpm.md — Deriving DDPM from VP-SDE
- Euler–Maruyama discretization
- Variance-preserving structure
- Why DDPM predicts noise
-
Forward and reverse processes
-
02c_ddpm_to_vpsde.md — From DDPM to VP-SDE (Continuous Limit)
- Moment matching approach
- Taylor expansion of discrete steps
- Recovering the continuous SDE
- Identity check derivation
Mathematical Foundations¶
- 02a_taylor_expansion.md — Taylor Expansions in Diffusion
- Role in Euler–Maruyama
- Square root approximation in DDPM
- Fokker–Planck equation derivation
-
Continuous vs. discrete connections
-
02b_fokker_plank_eq.md — Fokker–Planck Equation Derivation ⭐
- Line-by-line derivation from SDEs
- Test function approach
- Integration by parts
- Weak vs. strong solutions
- Examples and intuition
Solving and Sampling¶
- 03_solving_vpsde.md — Solving the VP-SDE ⭐ NEW
- Exact solution via integrating factor
- Closed-form marginal distribution
- Connection: \(\bar{\alpha}(t) = \exp(-\int_0^t \beta(s)\,ds)\)
-
Discrete products → continuous integrals
-
03a_reverse_time_sde_and_proba_flow_ode.md — Reverse SDE and Probability Flow ODE ⭐ NEW
- Reverse-time SDE (Anderson, 1982)
- Probability flow ODE (Song et al., 2021)
- DDPM as SDE discretization
- DDIM as ODE discretization
-
The \(\eta\) parameter
-
03b_ddim_update_coeff.md — DDIM Update Coefficients ⭐ NEW
- Exact DDIM update formula derivation
- From \(\bar{\alpha}(t)\) to
alphas_cumprodarray - Why \(\sqrt{\bar{\alpha}_t}\) coefficients appear
- Fast sampling (skipping steps)
- Complete theory-to-code connection
Current status: These documents provide rigorous mathematical foundations that complement the code-focused notebooks.
Quick Links¶
Notebooks (Interactive + Code)¶
- SDE Tutorial (Theory):
notebooks/diffusion/02_sde_formulation/README.md - SDE Tutorial (Code):
notebooks/diffusion/02_sde_formulation/02_sde_formulation.ipynb - DDPM Basics:
notebooks/diffusion/01_ddpm/01_ddpm_basics.ipynb
Docs (Mathematical Derivations)¶
- SDE View Overview
- DDPM from VP-SDE
- VP-SDE from DDPM
- Solving VP-SDE ⭐ NEW
- Reverse SDE & Probability Flow ODE ⭐ NEW
- DDIM Update Coefficients ⭐ NEW
- Fokker–Planck Equation
- Taylor Expansions
Learning Path¶
For Beginners¶
- Start with SDE View Overview for conceptual understanding
- Read DDPM from VP-SDE to see discrete-continuous connection
- Understand Solving VP-SDE for the forward solution
- See DDIM Update Coefficients for exact code formulas
- Work through the interactive notebook:
notebooks/diffusion/02_sde_formulation/02_sde_formulation.ipynb
For Deep Dive¶
- Study Taylor Expansions for mathematical foundations
- Work through Fokker–Planck derivation for PDE theory
- Complete the identity check with VP-SDE from DDPM
- Master Solving VP-SDE for closed-form solutions
- Understand sampling with Reverse SDE & Probability Flow ODE
- Connect theory to code with DDIM Update Coefficients
- Explore Design Principles Q&A for practical insights
Topics Covered¶
- Brownian Motion: Properties, scaling, and dimensionality
- Forward SDE: Data corruption as a stochastic process
- Score Functions: Gradient of log density and its role
- Reverse SDE: Time-reversal and sampling
- VP-SDE: Variance-preserving formulation (DDPM connection)
- Fokker–Planck Equation: Probability density evolution
- Discretization: Euler–Maruyama and variance preservation
- Moment Matching: Connecting discrete and continuous views
Archive¶
Note: Original draft files have been moved to dev/diffusion/sde/ (private development area).
These drafts have been superseded by comprehensive tutorials in notebooks/diffusion/02_sde_formulation/supplements/:
- Supplement 07: Fokker-Planck Equation (replaces div_and_laplace content)
- Supplement 08: Dimensional Analysis (replaces unit_analysis content)
- Main sde_QA.md: Canonical Q&A version