Diffusion models
How diffusion models learn to remove noise step by step, generating high-quality images, audio, molecules and scientific fields by reversing a gradual noising process.
What it is
A diffusion model is a generative model that creates data by starting from pure random noise and removing the noise gradually, step by step, until a clean sample emerges. During training, the model sees real data that have been corrupted with different amounts of Gaussian noise and learns to undo the corruption. The idea originated in nonequilibrium thermodynamics (Sohl-Dickstein et al., 2015) and became practical with Denoising Diffusion Probabilistic Models (DDPM, Ho et al., 2020) and score-based models (Song and Ermon). Diffusion models power image generators such as Stable Diffusion, DALL·E 2 and Imagen, along with video and audio generators, and they are used in protein and molecule design, medical image reconstruction, weather and climate downscaling, and materials generation.
It answers questions such as: How can high-quality, diverse samples be generated with stable training? How can generation be guided by a text prompt, a class label or a physical constraint? How can missing or noisy data be filled in (inpainting, super-resolution, inverse problems)? How can new molecules or structures be proposed? Compared with GANs (see generative adversarial networks), training is more stable and coverage of the data is better, but sampling is slower.
Fundamentals
The forward (noising) process
The forward process gradually adds Gaussian noise to a data sample x0 over T steps (typically T = 1000): q(xt | xt−1) = N(√(1 − βt) xt−1, βt I), where βt is a small variance from a noise schedule (linear, cosine). A useful closed form lets one jump directly to any step: xt = √ᾱt x0 + √(1 − ᾱt) ε, with ε ∼ N(0, I), αt = 1 − βt and ᾱt = Πs≤t αs. As t grows, ᾱt → 0 and xT becomes nearly pure Gaussian noise. This process has no learnable parameters. The signal-to-noise ratio ᾱt/(1 − ᾱt) falls monotonically, and the schedule design affects quality, particularly at high resolution.
The reverse (denoising) process and training
Generation reverses the chain: a neural network learns pθ(xt−1 | xt), a Gaussian whose mean is computed from the network’s output. In the simplest and most common parameterization, the network εθ(xt, t) predicts the noise ε that was added. Training is simple: pick a random data point x0, a random step t and noise ε, form xt, and minimize the squared error L = E‖ε − εθ(√ᾱt x0 + √(1 − ᾱt) ε, t)‖2. This is a simplified form of the variational bound on likelihood. The network is typically a U-Net (convolutions with attention and time embeddings) or a transformer (Diffusion Transformer, DiT; see transformers). To generate, start from xT ∼ N(0, I) and iterate xt−1 = (1/√αt)(xt − (βt/√(1 − ᾱt)) εθ(xt, t)) + σt z, with fresh noise z for each step except the last. Equivalent views: score matching (the network estimates ∇x log p(xt), the direction toward higher data density) and the stochastic differential equation (SDE) framework of Song et al., in which sampling solves a reverse-time SDE or the deterministic probability-flow ODE.
Faster sampling and guidance
Plain DDPM sampling needs hundreds to a thousand network evaluations per sample, which is slow. DDIM and ODE solvers (DPM-Solver, Heun) take deterministic paths and produce good samples in 20–50 steps, and distillation and consistency models reduce this to 1–4 steps. Latent diffusion (the basis of Stable Diffusion) runs diffusion in the compressed latent space of a pretrained autoencoder (see autoencoders), which makes training and sampling much cheaper than working in pixel space. Conditioning steers generation: the network receives a class label, a text embedding (from a language model such as CLIP or T5), an image, or physical parameters, often via cross-attention. Classifier-free guidance trains the network with and without the condition and extrapolates at sampling time: ε̃ = εθ(x, ∅) + w (εθ(x, c) − εθ(x, ∅)), where a guidance scale w > 1 (for example 5–10) increases fidelity to the prompt at the cost of diversity. Flow matching and rectified flows are closely related approaches that learn straight probability paths.
Scientific uses and evaluation
In science, diffusion models generate 3D molecular conformations and crystal structures, design proteins (RFdiffusion, which builds backbones that are then sequence-designed), model weather ensembles and downscale climate fields, accelerate MRI reconstruction, and solve inverse problems by combining a learned prior with measurement consistency (posterior sampling for deblurring, tomography or seismic imaging). Equivariant architectures respect rotations and translations for molecular data (see graph neural networks). Quality is measured with FID, precision and recall, CLIP score for text alignment, and, for scientific data, with physical consistency checks, statistics, spectra and downstream task performance. Models can memorize and reproduce training images, which raises privacy and copyright concerns that should be tested.
Typical applications and limits
Applications: image, video and audio synthesis, editing, inpainting, super-resolution, molecule and protein design, and surrogate generation of fields. Limits: slow iterative sampling relative to GANs, large compute for training, limited exact control, possible generation of physically invalid samples, bias inherited from data, and misuse for misleading synthetic media. Libraries: Hugging Face Diffusers, PyTorch, JAX.
Basic operation
- Prepare the data. Collect and normalize a large, clean training set.
- Define the noise schedule. Choose T and the β schedule, such as cosine.
- Build the denoiser. Use a U-Net or transformer with time and condition inputs.
- Train. Sample random steps and noise, and minimize the noise-prediction error.
- Sample. Start from noise and denoise with a fast solver such as DDIM.
- Apply guidance. Tune the guidance scale for the desired fidelity and diversity.
- Evaluate. Use FID and task-specific checks, and test for memorization.
- Collect the output. You obtain generated samples; noise schedules and guidance are covered in the video.
Good practice
- Use pretrained models where possible. Training from scratch is costly.
- Use fast samplers. Start with 20–50 step solvers.
- Tune guidance. Balance prompt fidelity and diversity.
- Check physical validity. Test generated scientific data against constraints.
- Test for memorization. Compare outputs with training examples.
- Disclose and label synthetic outputs. Follow licensing terms for training data and avoid creating misleading media, impersonations or fabricated research data.
Key terms
- Forward process — gradually adding noise to data until it becomes pure noise.
- Reverse process — the learned step-by-step removal of noise to generate data.
- Noise schedule — the plan that sets how much noise is added at each step.
- Score function — the gradient of the log data density, pointing toward likely data.
- Classifier-free guidance — a technique to strengthen conditioning at sampling time.
- Latent diffusion — running diffusion in a compressed latent space.
- DDIM — a faster, deterministic sampling method.
Video coming soon
About five minutes on Diffusion models: how it works in detail, how the data is acquired, and how it is analyzed.
More in 4.3 AI and Machine Learning
- Regularized linear models
- Decision trees and random forests
- Gradient boosting (XGBoost)
- Support vector machines
- k-NN
- k-means
- Gaussian processes
- Neural networks
- CNNs
- RNN/LSTM
- Transformers
- Autoencoders
- GANs
- Diffusion models
- Graph neural networks
- Reinforcement learning
- Transfer learning
- Federated learning
- Explainable AI (SHAP, LIME)
- Physics-informed neural networks
- Bayesian optimization
- Active learning
- Symbolic regression
- Genetic algorithms and particle swarm optimization
- Dimensionality reduction (t-SNE, UMAP)
- NLP and large language models
- Retrieval-augmented generation
- Computer vision (detection, segmentation)
- Anomaly detection
- Machine-learned interatomic potentials
- AutoML
