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

What a Diffusion Transformer is

A diffusion model generates an image by removing noise. Training adds Gaussian noise to real images at random strengths and teaches a network to predict that noise; sampling starts from pure noise and takes many small steps, each subtracting part of the predicted noise. Earlier image diffusion models used a convolutional U-Net as that network. The Diffusion Transformer (DiT) replaces it with a plain transformer over patches of an image latent, the same kind of encoder the ViT tab runs over pixels.

The page records DiT-XL/2, a class-conditional model for 256 × 256 ImageNet images, generating class 207, “golden retriever”, from seed 0 with 50 DDIM steps and guidance scale 4. Diffusers stores it with 749,826,464 parameters; the paper's 675M counts the timestep and class embedders once, where the conversion keeps 28 identical copies. Block 1 is recorded in full at three steps, t = 980, 500 and 100.

Latent patches

DiT works in the latent space of Stable Diffusion's VAE, which maps a 256 × 256 image to a 4 × 32 × 32 latent, 8 times smaller per side. The Patch embedding column cuts the noisy latent into 2 × 2 patches, a 16 × 16 grid of 256 tokens. Each patch's 2 × 2 × 4 = 16 numbers are projected to width 1152, and a fixed 2-D sine–cosine position embedding is added; the first 576 coordinates encode the column and the last 576 the row:

and the same for in the second half. The “/2” in DiT-XL/2 is this patch size. The DiT paper found that smaller patches, meaning more tokens and more compute for the same parameters, give better images. Patches of 4 or 8 would leave only 64 or 16 tokens.

Conditioning on the timestep and the class

The network must know how noisy its input is and what to draw. The Conditioning c strip builds one vector per image and step. The timestep goes through a 256-value sinusoid and an MLP to width 1152; the class picks a row of a 1,001-row embedding table, the 1,000 ImageNet classes plus a null class, number 1000. The two are added:

The same conditions all 28 blocks. During training the label was replaced by the null class 10 % of the time, so the same network also predicts noise with no class at all. Classifier-free guidance needs that unconditional prediction.

adaLN-Zero

DiT injects by modulating the LayerNorms, an idea from FiLM. Each block maps through its own linear layer to six vectors of width 1152: a shift , a scale and a gate , once for attention and once for the MLP. The LayerNorms have no learned parameters of their own:

The “Zero” is the initialisation: starts at zero, so every starts at 0 and every block starts as the identity. The DiT paper compared this with feeding as extra tokens and with cross-attention to it, and adaLN-Zero gave the best images. The heatmap in the strip shows the size (RMS) of each of the six vectors in each of the 28 blocks.

Between the modulations the block is a ViT block. Bidirectional Self Attention has 16 heads of 72 dimensions over all 256 tokens, and the MLP is 1152 → 4608 → 1152 with tanh-approximated GELU. In block 1 attention is spread almost evenly: the strongest weight in head 1's row for the selected patch at t = 500 is 0.016, against 1/256 ≈ 0.004 for a uniform row.

Noise, guidance and the DDIM step

The Final layer applies one more modulated LayerNorm and a linear map, 1152 → 32 per patch: 2 × 2 × 8, four channels of predicted noise and four of a predicted variance , which this sampler does not use. Unpatchify reassembles them into 4 × 32 × 32 maps.

Each step runs the model twice, once with class 207 and once with the null class, and classifier-free guidance pushes the prediction away from the unconditional one:

The Sampling loop then takes a deterministic DDIM step (). It estimates the clean latent from the guided noise and moves to the next noise level along the same direction:

comes from DDPM's linear schedule, from 0.0001 to 0.02 over 1,000 timesteps; the 50 steps skip 20 timesteps at a time. At t = 500, , so the latent is still mostly noise. After the last step the VAE decodes the latent, divided by 0.18215, into the 256 × 256 image.

Where it came from

DDPM (Ho et al., 2020) trained a U-Net to predict the added noise. Improved DDPM also learned the variance, the that DiT still outputs, and DDIM gave a deterministic sampler that needs far fewer steps. Latent diffusion (Rombach et al.) moved the whole process into a VAE's latent space, and classifier-free guidance traded diversity for fidelity without a separate classifier.

Peebles and Xie (2022) replaced the U-Net with a transformer. They measured that DiTs with more Gflops, from depth, width or more tokens, consistently reach lower FID; DiT-XL/2 reached a state-of-the-art FID of 2.27 on ImageNet 256 × 256. Many later image and video generators are transformers too, among them PixArt-α, SD 3.5 and FLUX in the Diffusion explainer.

Papers

  1. Scalable Diffusion Models with Transformers William Peebles, Saining Xie · ICCV 2023 DiT, the model this page records: a transformer over latent patches with adaLN-Zero conditioning, and its scaling study.
  2. Denoising Diffusion Probabilistic Models Jonathan Ho, Ajay Jain, Pieter Abbeel · NeurIPS 2020 DDPM: noise prediction, the training objective and the linear noise schedule this run uses.
  3. High-Resolution Image Synthesis with Latent Diffusion Models Robin Rombach et al. · CVPR 2022 Latent diffusion and the Stable Diffusion VAE, whose latent DiT denoises.
  4. Classifier-Free Diffusion Guidance Jonathan Ho, Tim Salimans · arXiv 2022 Guidance from a conditional and an unconditional prediction of one network, trained by dropping the label.
  5. Denoising Diffusion Implicit Models Jiaming Song, Chenlin Meng, Stefano Ermon · ICLR 2021 DDIM, the deterministic sampler of the sampling loop.
  6. Improved Denoising Diffusion Probabilistic Models Alex Nichol, Prafulla Dhariwal · ICML 2021 Learned variances, the Σ output DiT is trained with.
  7. 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 from a conditioning input, the idea behind adaptive LayerNorm.

See also