↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Loading recorded inference…

A transformer instead of a U-Net

The DDPM and Stable Diffusion tabs denoise with a U-Net: convolutions at several resolutions, with attention added at some of them. The Diffusion Transformer (DiT, Peebles and Xie) asks whether the convolutional backbone matters. It keeps latent diffusion, SD's VAE and the noise-prediction loss, and replaces the U-Net with a plain Vision Transformer over patches of the latent. Peebles and Xie found that sample quality improved steadily with the transformer's compute, by depth, width or number of patches, and their largest model, DiT-XL/2, reached an FID of 2.27 on class-conditional ImageNet 256 × 256.

This tab records DiT-XL/2 drawing ImageNet class 207, golden retriever, from seed 0 with 50 DDIM steps and guidance scale 4: 28 blocks of width 1152, 16 heads of 72. It is the same page as the Transformer Explainer's DiT tab, laid out as a transformer: patches, block 1 in full, the final layer, and the conditioning and sampling cards below.

Patches as tokens

The VAE turns the 256 × 256 image into a 4 × 32 × 32 latent. The Patch embedding cuts it into 2 × 2 patches, each numbers, and maps each with one Linear layer to 1152, then adds a fixed 2D sine–cosine position embedding. That gives tokens for patch size , the “/2” in the name. Halving quadruples the tokens and at least quadruples the compute, with almost no change in parameter count, which is one of the axes along which Peebles and Xie saw quality improve.

From here the tokens pass through 28 standard transformer blocks: bidirectional self-attention with 16 heads of 72 over all 256 patches, then an MLP 1152 → 4608 → 1152 with the tanh form of GELU, each wrapped in a residual connection.

adaLN-Zero conditioning

A text-free class-conditional model has two inputs besides the latent: the timestep and the class. The Conditioning c card builds one vector per image and step from them: as a 256-value sinusoid through an MLP, plus a row of a 1001 × 1152 class table (1000 ImageNet classes and a null class used for guidance). Each block's own Linear maps to six 1152-wide vectors, a shift , a scale and a gate for each half of the block:

The LayerNorms have no learned scale and shift of their own; the conditioning supplies them, as in FiLM and StyleGAN's adaptive instance norm. Training starts with every block's projection at zero, so all gates are zero and each block is the identity: the Zero in adaLN-Zero, an idea from zero-initialising the last layer of residual blocks. Peebles and Xie compared it with putting in as extra tokens and with cross-attention to it, and adaLN-Zero gave the best FID at the lowest cost. The card's heat map shows the size of each of the six vectors in all 28 blocks at the current step.

In this diffusers conversion each block keeps its own copy of the timestep and class embedders, which is why the page counts 750 M parameters where the paper counts 675 M.

What block 1 attends to

Block 1 is recorded in full at , 500 and 100. Its attention is close to uniform: the recorder measured a mean row entropy of about 5.5 nats, against for perfectly even weights, and largest weights of 0.035, 0.067 and 0.08 at the three steps, against . So the matrix drawn on a 0–1 scale looks almost white, and the map under the patch picker is scaled to each row's maximum instead. The first block mostly averages over the whole image at all three noise levels; only block 1 is recorded, so the page cannot show how sharply the later 27 attend.

Noise and variance out

The Final layer applies one more adaLN, with a shift and scale but no gate, and a Linear 1152 → 32 for each patch: numbers. Unpatchify puts them back on the 32 × 32 grid as 8 channels, 4 for the predicted noise and 4 for the variance of each reverse step, which DiT learns as Nichol and Dhariwal proposed for improved DDPM. DDIM does not use the variance channels.

Guidance and the sampling loop

Every step runs the model twice, on class 207 and on the null class 1000, and the Sampling loop mixes the noise predictions with classifier-free guidance:

then takes a deterministic DDIM step, , 50 times. The strip decodes and at every step.

Where DiT led

DiT brought the Vision Transformer's patches into diffusion and showed that the transformer's scaling carried over. Its successors replace the class with text. PixArt-α (the PixArt tab) adds cross-attention to a T5 encoder and shares one adaLN projection across blocks; Sana (the Sana tab) swaps softmax attention for linear attention; SD 3.5 and FLUX put text and image tokens into one joint attention; and the video models on the Wan, CogVideoX and LTX tabs are DiTs over space–time patches.

Papers

  1. Scalable Diffusion Models with Transformers William Peebles, Saining Xie · ICCV 2023 DiT: latent patches, adaLN-Zero and the scaling study; DiT-XL/2 is the checkpoint this tab records.
  2. An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale Alexey Dosovitskiy et al. · ICLR 2021 The Vision Transformer: an image cut into patches and read as a sequence of tokens.
  3. High-Resolution Image Synthesis with Latent Diffusion Models Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Björn Ommer · CVPR 2022 Latent diffusion and the VAE whose 4 × 32 × 32 latents DiT denoises.
  4. FiLM: Visual Reasoning with a General Conditioning Layer Ethan Perez, Florian Strub, Harm de Vries, Vincent Dumoulin, Aaron Courville · AAAI 2018 Feature-wise scale and shift computed from a conditioning input, the idea adaLN applies to layer norms.
  5. Improved Denoising Diffusion Probabilistic Models Alex Nichol, Prafulla Dhariwal · ICML 2021 Learned reverse-process variances, the four Σ channels of DiT's output.
  6. Classifier-Free Diffusion Guidance Jonathan Ho, Tim Salimans · arXiv 2022 Guidance from a null-class prediction, the mix in the sampling loop.
  7. Accurate, Large Minibatch SGD: Training ImageNet in 1 Hour Priya Goyal et al. · arXiv 2017 Zero-initialising the last scale of each residual block so it starts as the identity, the trick adaLN-Zero follows.

See also