A hands-on tutorial on Flow Matching for generative modeling. Learn to build, train, and understand flow-based generative models through progressive Jupyter notebooks.
Flow matching learns to transport samples from a simple source distribution (e.g., Gaussian noise) to a complex target distribution by following learned velocity fields. It provides a simple and efficient framework for generative modeling with strong connections to optimal transport theory.
If you prefer to code along and implement some small parts yourself, start here:
| Notebook | Description | Colab |
|---|---|---|
| Flow Matching Basics | Introduction to flow matching with straight-line interpolation | |
| Optimal Transport Pairing | Improve training efficiency with optimal transport couplings | |
| Latent Distribution Choice | Explore componentwise noise adaptation to target geometry | |
| Conditional Sampling | Learn conditional generation with conditional optimal transport |
Notebook 05 (continuous flows for discrete data, see below) is inference-only and has no exercises variant.
If you prefer to explore the concepts directly, use these:
| Notebook | Description | Colab |
|---|---|---|
| Flow Matching Basics | Introduction to flow matching with straight-line interpolation | |
| Optimal Transport Pairing | Improve training efficiency with optimal transport couplings | |
| Latent Distribution Choice | Explore componentwise noise adaptation to target geometry | |
| Conditional Sampling | Learn conditional generation with conditional optimal transport | |
| Flows for Discrete Data (Sudoku) | Inference with pretrained models vMF (spherical) and masked diffusion, solving Sudoku-Extreme puzzles |
Click the badge above or open individual notebooks directly in Colab. Each notebook includes setup cells that install dependencies automatically.
git clone https://github.com/JChemseddine/fm_tutorial.git
cd fm_tutorial
pip install -r requirements.txt
jupyter notebookThe tutorial is accompanies a series of lectures by Prof. Dr. Gabriele Steidl (https://page.math.tu-berlin.de/~steidl/):
| Lecture | Topic | |
|---|---|---|
| Lecture 1 | Optimal Transport | 1_HS_AMSTERDAM_OT.pdf |
| Lecture 2 | Flow Matching | 2_HS_AMSTERDAM_FM.pdf |
| Lecture 3 | 1D Processes and Noise Adaptation | 3_HS_AMSTERDAM_1D.pdf |
| Lecture 4 | Bayesian Inference and Conditional Flow Matching | 4_HS_AMSTERDAM_Bayesian.pdf |
These lectures provide the mathematical background and theory for the hands-on notebooks.
- Flow Matching: Markov Kernels, Stochastic Processes and Transport Plans — Christian Wald, Gabriele Steidl, 2025 | arXiv:2501.16839
- Used throughout the flow matching basics and optimal transport notebooks.
- Adapting Noise to Data: Generative Flows from 1D Processes — Jannis Chemseddine, Gregor Kornhardt, Richard Duong, Gabriele Steidl, 2025 | arXiv:2510.12636
- Used in the latent choice notebook.
- Conditional Wasserstein Distances with Applications in Bayesian OT Flow Matching — Jannis Chemseddine, Paul Hagemann, Gabriele Steidl, Christian Wald, 2024 |arXiv:2403.18705
- Used in the conditional sampling notebook.
- Spherical Flows for Sampling Categorical Data — 2026 | arXiv:2605.05629
- Used in notebook 05. Pretrained checkpoints are hosted on Hugging Face Hub at Jugc/fm-tutorial; 100 held-out Sudoku-Extreme puzzles ship with the repo at
data/sudoku_extreme_100.npz. The inference code inflows_categorical/is copied (with attribution) from the paper's source repo.
- Used in notebook 05. Pretrained checkpoints are hosted on Hugging Face Hub at Jugc/fm-tutorial; 100 held-out Sudoku-Extreme puzzles ship with the repo at
- Flow Matching for Generative Modeling — Lipman et al., ICLR 2023 | arXiv:2210.02747
- Building Normalizing Flows with Stochastic Interpolants — Albergo et al., ICLR 2023 | arXiv:2209.15571
- Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow — Liu et al., ICLR 2023 | arXiv:2209.03003
- Continuous Diffusion for Categorical Data (CDCD) — Dieleman et al., 2022 | arXiv:2211.15089
- Continuous diffusion on unit-norm token embeddings; the setup notebook 05 builds on. -Improving and generalizing flow-based generative models with minibatch optimal transport - Tong et al., 2023 | arXiv:2302.00482
- Basis for the minibatch OT notebook.
- Heavy-Tailed Diffusion Models — Pandey et al., 2024 | arXiv:2410.14171
- Inspired notebook latent_choice.
- POT: Python Optimal Transport — Flamary et al., JMLR 2021 | pythonot.github.io
- GeomLoss: Geometric Losses for Deep Learning — Feydy et al. | kernel-operations.io/geomloss
Questions or suggestions? Write me an email: [email protected]