Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Treat the picture as a sentence of patches
Transformers became the workhorse of language models because they scale predictably: make them bigger and they get better. DiT applies the same recipe to diffusion. The compressed image is chopped into small squares, each square becomes a ‘word’, and a transformer reads them all at once to predict the noise. The noise level and the requested class do not enter as extra words; instead they adjust every layer’s normalisation, and each layer starts switched off and learns how much to contribute. The demo shows how tokens and compute grow with image size and patch size.
Choosing the same architecture for text, images, video and actions lets one team reuse scaling laws, kernels and infrastructure; this is why video world models and robot policies increasingly use diffusion transformers.
- 1. DiT replaces the U-Net with…
- 2. In DiT the noise level and class enter through…
- 3. Smaller patches give…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Architecture and scaling
- Patchify: a latent of shape (C, H, W), for example 4×32×32 for 256×256 images, is split into p×p patches; N = (H/p)(W/p) tokens of size p²C, linearly embedded, plus fixed 2-D sinusoidal positions.
- Conditioning: timestep t through a sinusoidal embedding and an MLP; the class through a learned embedding (with a null class for CFG); their sum c drives every block.
- adaLN-Zero: from c an MLP regresses (γ₁, β₁, α₁, γ₂, β₂, α₂) per block; x ← x + α₁ · Attn(LN(x)(1 + γ₁) + β₁) and x ← x + α₂ · MLP(LN(x)(1 + γ₂) + β₂). The α are initialised to zero, as is the final linear layer, so every block starts as the identity.
- Alternatives compared in the paper: in-context tokens (append c as tokens), cross-attention to c, and adaLN without zero gates; adaLN-Zero had the best FID and the least extra compute.
- Configurations: S, B, L, XL (depth 12, 12, 24, 28; width 384, 768, 1024, 1152) with p = 2, 4, 8; forward Gflops ≈ depth · (12 N d² + 2 N² d) / 1e9, for example 118.6 for DiT-XL/2 at 256×256.
- Scaling: FID fell steadily with Gflops, regardless of whether they came from depth, width or patch size; parameter count alone did not predict quality.
- Descendants: U-ViT (Bao et al., 2023), PixArt-α, SD3’s MMDiT with joint text–image attention (Esser et al., 2024), FLUX, Sora-style video transformers on spacetime patches, and SiT (DiT trained with flow matching).
- 1. adaLN-Zero initialises…
- 2. DiT-XL/2 at 256×256 uses about…
- 3. Quality in DiT tracked…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Building and using DiTs
Exercise 1.
- Patchify and unpatchify.
- The sinusoidal timestep embedding.
- One adaLN-Zero sub-block.
- The Gflops formula.
Practice.
- Use the official DiT or SiT code, or diffusers’
DiTPipeline(facebook/DiT-XL-2-256) for class-conditional ImageNet sampling. - Train in a pretrained VAE latent; patch size 2 is the default, larger patches trade quality for speed.
- Initialise adaLN gates and the output layer to zero; use EMA weights for sampling, AdamW with constant learning rate 1e-4 as in the paper.
- For text conditioning use MMDiT-style joint attention or cross-attention; add QK-normalisation for stability at scale.
- Budget by Gflops per forward pass times sampling steps; attention cost grows with N², so high resolutions need larger patches, token merging or windowed attention.
import torch
from diffusers import DiTPipeline, DPMSolverMultistepScheduler
pipe = DiTPipeline.from_pretrained("facebook/DiT-XL-2-256", torch_dtype=torch.float16).to("cuda")
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
ids = pipe.get_label_ids(["airliner", "space shuttle"])
images = pipe(class_labels=ids, num_inference_steps=25, guidance_scale=4.0).images- 1. The default DiT patch size:
- 2. Attention cost grows with tokens as…
- 3. Sampling uses which weights?
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Identity at initialisation. With α = 0 each residual branch contributes nothing, so the network is the identity map from patch embedding to output, and with a zero output layer it predicts ε̂ = 0, whose loss is exactly E‖ε‖² (2 in 2-D). Residual nets that start as the identity train stably (Goyal et al., 2017; Fixup), and the gates let the conditioning decide how much each block contributes at each noise level.
Why modulation conditions well. Concatenating c to the input lets it influence only the first layer’s pre-activations; its effect must survive through every later layer. adaLN injects c into every block as a per-channel scale and shift, so the same weights can behave differently at high and low noise, which is what a denoiser needs.
Compute. Per block, the projections cost 4Nd² (Q, K, V, output) and the MLP 8Nd² multiply-adds; attention scores and weighted sums cost 2N²d. Halving p quadruples N; at 256 tokens the N²d term is small, but at thousands of tokens it dominates.
- 1. At initialisation adaLN-Zero predicts…
- 2. Concatenating the condition to the input affects…
- 3. Halving the patch size multiplies tokens by…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Does adaLN-Zero condition a denoiser better than concatenation or ungated adaLN, and does the Gflops formula match the paper?
History.
- W. Peebles and S. Xie, “Scalable diffusion models with transformers” (ICCV 2023).
- A. Dosovitskiy et al., “An image is worth 16×16 words” (ViT, 2021); E. Perez et al., “FiLM” (2018): feature-wise modulation.
- P. Esser et al., “Scaling rectified flow transformers” (SD3, 2024); N. Ma et al., “SiT” (2024).
Exercise 2. Eight Gaussian modes (std 0.2) on a circle of radius 2; class = mode index mod 4, so each of 4 classes owns two opposite modes. The conditioning vector is a 16-dimensional sinusoidal timestep embedding plus a one-hot class. The denoiser is a residual network with two blocks of LayerNorm and an MLP (width 24, hidden 48). On a single 2-D point there is only one token, so attention would be trivial; we test only the conditioning mechanism. Three variants: concat (condition joined to the input), adaLN (per-block scale and shift, ungated) and adaLN-Zero (scale, shift and gate, zero-initialised, plus a zero output layer). Each was trained for 250 Adam steps (batch 128); then 500 class-conditional DDIM samples (25 steps).
| conditioning | initial loss | final loss | right class | on the data |
|---|---|---|---|---|
| concat | 6.466 | 0.391 | 0.886 | 0.782 |
| adaLN | 3.789 | 0.424 | 0.846 | 0.724 |
| adaLN-Zero | 2.053 | 0.362 | 0.984 | 0.846 |
| Gflops (formula) | patch 2 | patch 4 | patch 8 |
|---|---|---|---|
| DiT-S | 6.04 | 1.4 | 0.34 |
| DiT-B | 22.95 | 5.51 | 1.36 |
| DiT-L | 80.53 | 19.53 | 4.84 |
| DiT-XL | 118.38 | 28.8 | 7.15 |
- adaLN-Zero won on every seed: right class 0.984, 0.992 and 0.98 on seeds 0–2, against 0.886, 0.778, 0.878 for concat and 0.846, 0.892, 0.932 for adaLN; on the data 0.846, 0.93, 0.86.
- Starting as the identity: its initial loss was 2.05, the loss of predicting zero; the other variants started worse than that (3.8 and 6.5).
- Ungated adaLN was not reliably better than concat (worse on seed 0, better on seeds 1 and 2): in this toy the gating and zero initialisation, not the modulation alone, made the difference.
- Gflops: the formula gave 118.4 for DiT-XL/2 at 256×256 and 524.3 at 512×512; the paper reports 118.6 and 524.6 (embedders and the final layer account for the rest).
- Caveat: tiny networks, short training, one token; DiT’s scaling results need real images and thousands of GPU hours.
Diffusion transformers in AI, robotics and aerospace
- Video and world models: Sora-style models and robot world models are diffusion transformers over spacetime patches; their compute is set by the token count.
- Robot policies: diffusion-transformer policies (for example RDT-1B) denoise action chunks conditioned on images and language through adaLN-style modulation or cross-attention.
- Earth and weather: transformer denoisers over gridded fields patchify the globe or a region, as in generative weather models built on ViT-style backbones.
References
- W. Peebles and S. Xie (2023). “Scalable diffusion models with transformers.” ICCV.
- A. Dosovitskiy et al. (2021). “An image is worth 16x16 words: transformers for image recognition at scale.” ICLR.
- E. Perez, F. Strub, H. de Vries, V. Dumoulin and A. Courville (2018). “FiLM: visual reasoning with a general conditioning layer.” AAAI.
- F. Bao et al. (2023). “All are worth words: a ViT backbone for diffusion models.” CVPR.
- P. Esser et al. (2024). “Scaling rectified flow transformers for high-resolution image synthesis.” ICML.
- N. Ma et al. (2024). “SiT: exploring flow and diffusion-based generative models with scalable interpolant transformers.” ECCV.