Modern Image/Video Gen: Straight-Line Flow Matching & Diffusion Transformers (DiT)
What replaced U-Net DDPM in Flux, Stable Diffusion 3, Sora, and Veo: Rectified Flow Matching's straight-line velocity ODE (v_θ ≈ x₁ − x₀) for 8–20 step generation, Diffusion Transformers (DiT + adaLN-Zero), and 3D spacetime video patches.
Rectified Flow Matching trains a Diffusion Transformer (DiT) to predict straight-line velocity vectors directly from Gaussian noise to real data latents.
Classic DDPM follows curved, noisy trajectories requiring 50–1,000 denoising steps; straight-line Flow Matching + scalable DiT backbones generate sharper images and video in 8–20 steps.
Every 2024–2026 frontier image & video model (Flux.1, SD3.5, Sora, Veo, Wan) runs Flow Matching + Diffusion Transformers (DiT) — leaving classic U-Net DDPM behind!
DiT unifies visual generation with the exact same Transformer scaling laws, FlashAttention, and RoPE infrastructure you already mastered in Modules 1–2!
Understanding x_t = (1 − t)x_0 + t·x_1 and velocity v = x_1 − x_0 reveals how remarkably clean modern generative math has become compared to 2020 DDPM variance schedules.
Cutting-edge generative interview question: 'Why did Flux, SD3, and Sora switch from U-Net DDPM to DiT + Rectified Flow Matching?'
In Rectified Flow Matching, given noise x_0 ~ N(0, I) and clean latent x_1, what is the constant target velocity along the straight path x_t = (1 − t)x_0 + t·x_1?
- Derive Rectified Flow Matching: linear interpolation x_t = (1−t)x_0 + t·x_1 and velocity regression loss ‖v_θ(x_t, t) − (x_1 − x_0)‖²
- Explain why straight-line ODE trajectories need far fewer sampling steps (8–20) than curved DDPM schedules
- Contrast classic Convolutional U-Nets with Diffusion Transformers (DiT) using patchification and adaLN-Zero conditioning
- Explain how Video Generation models (Sora / Veo) generalize DiT to 3D spacetime patches via a 3D Causal VAE
Classic DDPM is like driving from New York to Boston along a winding mountain road (you must steer every 50 feet → 100 steps!). Rectified Flow Matching builds a straight laser highway (x_1 − x_0) so you can cruise smoothly in just 10–20 giant Euler steps. Meanwhile, DiT replaces the old CNN U-Net with a pure scalable Transformer that handles arbitrary image aspect ratios AND 3D video cubes seamlessly!
1. Rectified Flow Matching: Straight-Line Velocity ODE
Drag the Steps slider in the mini-lab below to see how Straight Flow Matching reaches crisp fidelity in just 8–16 steps where curved DDPM is still blurry!
The 2-Line Flow Matching Objective
At inference, simply march from in Euler steps: !
Inference Step Budget: DDPM vs. Rectified Flow
2. Diffusion Transformers (DiT) & MM-DiT Architecture
Peebles & Xie (2023) proved that replacing the U-Net inductive bias with a plain Transformer unlocks LLM-style scaling laws for image & video quality!
Why DiT + adaLN-Zero Beat U-Nets
- Patchify: Slices the
(64 × 64 × 4)latent into(2 × 2)patches → a clean sequence of1,024tokens! - adaLN-Zero Conditioning: Predicts LayerNorm shift/scale and residual gate from timestep , initializing so every DiT block starts as an exact identity function (rock-solid deep training!).
- MM-DiT (Flux / SD3): Concatenates text tokens and image patches into bidirectional joint self-attention — letting text attend back to image patches and enabling crisp typography inside generated images!
3. Generalizing to Video: 3D Spacetime Patches (Sora / Veo)
How do you turn a 2D image DiT into a 1080p physics-consistent video generator?
Spacetime Cubes + 3D RoPE
Compress raw video frames through a 3D Causal VAE into a compact spacetime latent grid, slice it into 3D spacetime patches, attach 3D RoPE (time + height + width), and run a giant DiT — enabling native variable resolution, aspect ratio, and duration in ONE architecture!
Worked Example: One Euler Sampling Step of Flow Matching
Suppose at (pure noise) , velocity network predicts , and we use steps ().
.
In Rectified Flow Matching (x_t = (1 − t)x_0 + t·x_1), what is the target that the neural network v_θ(x_t, t) is trained to predict?
Why does MM-DiT (Flux / SD3) spell text inside images (e.g., neon signs reading 'AIMLCode') dramatically better than older SD 1.5 U-Nets?
The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.
Because (pure noise) and (almost clean) are easy to predict; the hardest semantic decisions happen in the middle ()! Logit-Normal weighting focuses training compute right on the middle timesteps.
Curved DDPM SDE vs. Straight Rectified Flow Matching Racer
See why Rectified Flow Matching (Flux, SD3, Sora) needs only 8–20 ODE steps along a straight line instead of 50+ tiny curved steps.
Flux.1, Stable Diffusion 3.5, Sora & Veo
Flow Matching + DiT is the unified backbone of modern photorealistic image and video synthesis.
import torch
import torch.nn as nn
# Rectified Flow Matching: Straight-Line Interpolation x_t = (1-t)*x_0 + t*x_1
# Target velocity is constant: v* = x_1 - x_0
def flow_matching_loss(velocity_net: nn.Module, x1_data: torch.Tensor) -> torch.Tensor:
B = x1_data.size(0)
x0_noise = torch.randn_like(x1_data)
t = torch.rand(B, 1) # uniform t in [0, 1]
x_t = (1.0 - t) * x0_noise + t * x1_data # linear OT path
target_v = x1_data - x0_noise
pred_v = velocity_net(torch.cat([x_t, t], dim=-1))
return nn.functional.mse_loss(pred_v, target_v)
net = nn.Sequential(nn.Linear(17, 64), nn.SiLU(), nn.Linear(64, 16))
loss = flow_matching_loss(net, torch.randn(8, 16))
print(f"Rectified Flow velocity MSE loss: {loss.item():.4f}")