Diffusion models are a class of probabilistic generative models that synthesize high-dimensional data—images, video, 3D geometry, audio, and molecular structures—by learning to reverse a gradual thermodynamic corruption process. During training, a fixed forward schedule progressively destroys clean training examples with Gaussian noise until only isotropic static remains; a neural network (a U-Net or Diffusion Transformer) learns the score function that points noisy samples back toward the natural data manifold. Unlike generative adversarial networks (GANs), which pit a generator against a discriminator in an unstable min–max game prone to mode collapse, diffusion models optimize a convex-like per-timestep regression loss with full distribution coverage—making them the backbone of Stable Diffusion, FLUX, DALL-E 3, Midjourney, and Sora.
In modern latent diffusion systems, pixel compression, text conditioning, and iterative ordinary or stochastic differential equation (ODE/SDE) solving work together as a unified pipeline:
The forward diffusion process is a fixed Markov chain with an exact closed-form jump to any noise level. Given a clean data sample $x_0 \sim q(x_0)$ and a variance schedule $\{\beta_t\}_{t=1}^T$ (for instance, $T = 1{,}000$ steps ramping from $\beta_1 = 10^{-4}$ to $\beta_T = 0.02$), each forward step scales down the previous signal and injects independent Gaussian noise:
Defining $\alpha_t = 1 - \beta_t$ and the cumulative signal retention product $\bar{\alpha}_t = \prod_{s=1}^t \alpha_s$, the sum of independent Gaussians collapses the entire $t$-step chain into a single closed-form marginal distribution:
That reparameterization is what makes diffusion training computationally tractable: instead of stepping sequentially through hundreds of Markov transitions per training batch, an optimizer draws a random integer $t \sim \text{Uniform}(\{1, \dots, T\})$, jumps directly to $x_t$ in one fused multiply-add, and computes gradients at arbitrary signal-to-noise ratios $\text{SNR}(t) = \bar{\alpha}_t / (1 - \bar{\alpha}_t)$.
Training minimizes a variational bound that simplifies to denoising score matching. By maximizing the evidence lower bound (ELBO) on $\log p_\theta(x_0)$ across all reverse transitions $p_\theta(x_{t-1} \mid x_t) = \mathcal{N}(x_{t-1}; \mu_\theta(x_t, t), \sigma_t^2 I)$, Ho et al. (DDPM, 2020) showed that parameterizing the network $\epsilon_\theta(x_t, t, c)$ to predict the injected unit-variance noise $\epsilon$ reduces the KL-divergence sum to a remarkably clean mean-squared-error objective:
By Tweedie's formula, predicting the added Gaussian noise $\epsilon$ is mathematically equivalent—up to a known variance scalar—to estimating the Stein score $\nabla_{x_t}\log q(x_t)$ (the gradient of log-probability density pointing uphill toward high-density regions of the data distribution):
That identity unifies discrete DDPM, Song et al.'s continuous-time Score-Based SDEs, and modern Rectified Flow / Flow Matching (SD3, FLUX), which replace curved variance-preserving schedules with straight linear interpolation paths $x_t = (1 - t)x_0 + t\epsilon$ and train a velocity field $v_\theta(x_t, t) \approx \epsilon - x_0$ so an Euler ODE solver can march from noise to data in far fewer steps.
Deterministic ODE samplers and Classifier-Free Guidance (CFG) control speed and prompt adherence at inference. Walking the full $1{,}000$-step stochastic DDPM reverse chain requires $1{,}000$ full forward passes of a billion-parameter network per image. Denoising Diffusion Implicit Models (DDIM) share the exact same trained weights $\epsilon_\theta$ as DDPM while setting per-step stochasticity $\sigma_t \ge 0$ in the generalized reverse update:
Setting $\sigma_t = 0$ turns generation into a deterministic probability-flow ODE, allowing higher-order numerical integrators (DPM-Solver++, Heun) to generate crisp samples in 15–30 steps, while consistency distillation and adversarial diffusion distillation compress sampling further to 1–4 steps. To steer outputs tightly toward a text prompt $c$ without an external classifier, Classifier-Free Guidance drops the conditioning vector $c \to \varnothing$ on 10–20\% of training steps and extrapolates away from the unconditional score at inference using guidance weight $w$ (typically 3.5–7.5):
import torch
import torch.nn.functional as F
def ddpm_train_step(model, x_0, cond, alpha_bar, p_uncond=0.1):
b = x_0.shape[0]
t = torch.randint(0, len(alpha_bar), (b,), device=x_0.device)
eps = torch.randn_like(x_0)
ab_t = alpha_bar[t].view(b, 1, 1, 1)
# Closed-form jump to noisy latent x_t
x_t = torch.sqrt(ab_t) * x_0 + torch.sqrt(1.0 - ab_t) * eps
# Randomly drop conditioning for Classifier-Free Guidance training
use_cond = (torch.rand(b, 1, 1, device=x_0.device) >= p_uncond)
c_in = torch.where(use_cond, cond, torch.zeros_like(cond))
eps_pred = model(x_t, t, c_in)
return F.mse_loss(eps_pred, eps)
@torch.no_grad()
def ddim_cfg_sample(model, shape, cond, null_cond, alpha_bar, steps, w=7.0):
x = torch.randn(shape, device=cond.device)
for i in range(len(steps) - 1):
t, t_prev = steps[i], steps[i + 1]
t_batch = torch.full((shape[0],), t, device=x.device, dtype=torch.long)
eps_c = model(x, t_batch, cond)
eps_u = model(x, t_batch, null_cond)
eps = eps_u + w * (eps_c - eps_u)
ab, ab_prev = alpha_bar[t], alpha_bar[t_prev]
x0_hat = (x - torch.sqrt(1.0 - ab) * eps) / torch.sqrt(ab)
x = torch.sqrt(ab_prev) * x0_hat + torch.sqrt(1.0 - ab_prev) * eps
return xLatent Diffusion and Diffusion Transformers (DiT) unlock megapixel images and multi-second video on GPU clusters. Running diffusion directly on a $1024 \times 1024 \times 3$ RGB image ($3{,}145{,}728$ floats) wastes vast compute predicting imperceptible high-frequency pixel noise. Rombach et al.'s Latent Diffusion Model (LDM) first trains a perceptual variational autoencoder (VAE) with spatial downsampling factor $f = 8$ that maps pixels into a compact $128 \times 128 \times 4$ (or $16$-channel) latent tensor ($65{,}536$ values at $4$ channels—a $48\times$ dimensionality reduction). Early models (SD 1.5, SDXL) denoised latents using convolutional U-Nets with residual skip connections and CLIP cross-attention. Modern frontier systems (DiT by Peebles & Xie, SD3, FLUX.1, Sora) group the $128 \times 128$ latent grid into $2 \times 2$ patches ($N = 64 \times 64 = 4{,}096$ tokens per frame) and process image/video tokens jointly alongside T5-XXL text tokens inside Multimodal Diffusion Transformer (MM-DiT) blocks with adaptive LayerNorm (`adaLN-Zero`) timestep modulation—exhibiting clean power-law compute scaling across tens of billions of parameters.
| Model Architecture / Family | Space & Schedule | Backbone & Text Conditioning | Typical Sampling Steps | Defining Engineering Contribution |
|---|---|---|---|---|
| DDPM / Guided Diffusion | Pixel space, discrete Markov $\beta_t$ | Convolutional U-Net + AdaGN | 250–1{,}000 SDE steps | Established $\mathcal{L}_{\text{simple}}$ noise-prediction MSE & beat GAN FID |
| Stable Diffusion 1.5 / SDXL | $8\times$ VAE latent (4-ch), scaled linear | U-Net (0.9B–2.6B) + CLIP ViT-L/bigG | 20–50 DDIM / DPM++ | $48\times$ latent compression brought megapixel synthesis to single GPUs |
| SD3 / FLUX.1 | $8\times$ VAE latent (16-ch), Rectified Flow | MM-DiT (2B–12B) + CLIP + T5-XXL | 4–28 Euler ODE steps | Straight flow-matching trajectories + joint image/text self-attention |
| Sora / Video DiTs | 3D spatiotemporal causal VAE | Spacetime Patch DiT + captioner | 20–50 flow steps | Unified variable-duration, variable-aspect-ratio video physics |
| Consistency / ADD / LCM | Latent trajectory distillation | Distilled U-Net or DiT student | 1–4 steps (<50\ ms) | Maps any point on the probability-flow ODE directly to clean $z_0$ |
Think of generative diffusion as coarse-to-fine physical annealing driven by a learned vector field. By splitting an impossible single-shot jump from white noise to photorealism into a smooth differential equation—where early steps sculpt global composition, middle steps lock semantic geometry, and final steps polish high-frequency texture—diffusion turns unstructured entropy into controllable, full-distribution synthesis.