Diffusion Transformer (DiT)
A Diffusion Transformer (DiT) swaps the U-Net in a diffusion model for a transformer over latent patches, the design behind SD3, FLUX.1, and Sora.
A Diffusion Transformer (DiT) is a diffusion model whose denoising network is a transformer instead of a convolutional U-Net. It cuts a noisy image latent into patches, processes them as a sequence of tokens with self-attention, the way a Vision Transformer (ViT) processes an image, and predicts the noise to remove at each denoising step. William Peebles and Saining Xie introduced it in Scalable Diffusion Models with Transformers (ICCV 2023), where DiT-XL/2 reached a Fréchet Inception Distance (FID) of 2.27 on class-conditional ImageNet 256×256, beating the previous best of 3.60 from latent diffusion. The paper showed that image quality improves steadily as a DiT's compute grows, and transformer denoisers have since replaced U-Nets in most large image and video generators, including Stable Diffusion 3, FLUX.1, and OpenAI's Sora.
How a Diffusion Transformer Works#
A DiT runs in the latent space of the pretrained variational autoencoder (VAE) used by Stable Diffusion, whose encoder downsamples by 8, so a 256×256×3 image becomes a 32×32×4 latent. A patchify layer splits the noisy latent into p×p patches and linearly embeds each one as a token; patch sizes of 2, 4, and 8 give 256, 64, and 16 tokens. Sine-cosine position embeddings mark where each token came from, a stack of transformer blocks processes the sequence, and a final linear layer turns every token back into a patch of predicted noise and variance, which is reassembled into the shape of the latent. The diffusion timestep and the class label, or the text prompt in a text-to-image model, condition every block. Generation repeats this prediction from pure noise until the last step, and the VAE decoder turns the clean latent into pixels:
The paper compared four ways of feeding the condition into each block: extra tokens in the sequence, cross-attention, adaptive layer norm (adaLN), and adaLN-Zero. adaLN-Zero gave the lowest FID and was also the most compute-efficient. A small network reads the summed timestep and class embeddings and regresses a shift and scale applied after each layer norm, plus a gate that scales each residual branch. The gates start at zero, so every block begins training as the identity function. This PyTorch code patchifies a latent and applies the attention branch of one block:
import torch
from torch import nn
torch.manual_seed(0)
# A 256x256 image becomes a 4x32x32 latent; 2x2 patches turn it into 256 tokens of width 384 (DiT-S/2)
latent = torch.randn(1, 4, 32, 32)
tokens = nn.Conv2d(4, 384, kernel_size=2, stride=2)(latent).flatten(2).transpose(1, 2)
# adaLN-Zero: the timestep and class embedding regresses a shift, scale, and gate for the attention branch
condition = torch.randn(1, 384)
modulation = nn.Linear(384, 3 * 384)
nn.init.zeros_(modulation.weight)
nn.init.zeros_(modulation.bias)
shift, scale, gate = modulation(condition).unsqueeze(1).chunk(3, dim=-1)
# Self-attention branch of a DiT block, modulated by the condition and scaled by the gate
attention = nn.MultiheadAttention(384, num_heads=6, batch_first=True)
h = nn.functional.layer_norm(tokens, (384,)) * (1 + scale) + shift
out = tokens + gate * attention(h, h, h)[0]
print(f"tokens {tuple(tokens.shape)}, block is identity at initialization: {torch.equal(out, tokens)}")It prints tokens (1, 256, 384), block is identity at initialization: True. The 256 tokens of width 384 match the smallest model, DiT-S/2, and the zero gate passes the input through unchanged until training moves it. A full DiT block regresses a second shift, scale, and gate for its MLP branch.
Scaling with Tokens and Compute#
The paper trained four model sizes, from DiT-S (12 layers, width 384) to DiT-XL (28 layers, width 1,152), each with patch sizes 8, 4, and 2. Across all 12 models, FID tracked forward-pass compute in Gflops, whether the compute came from a deeper or wider network or from more tokens. Halving the patch size quadruples the token count and the compute while adding almost no parameters. DiT-XL/2 has 675 million parameters, excluding the 84-million-parameter VAE, and uses 119 Gflops per forward pass at 256×256. At 512×512 it processes 1,024 tokens from a 64×64×4 latent at 525 Gflops and reaches an FID of 3.04. Because self-attention compares every token with every other, higher resolutions and longer videos raise its cost quadratically. Ultralytics YOLO26 avoids this cost by placing attention only at its 1/32-scale stage, which has 400 positions for a 640×640 image, and keeping convolutions everywhere else for real-time detection.
DiT vs. U-Net and ViT#
- U-Net denoisers: The U-Nets in DDPM and Stable Diffusion 1.x and 2.x are convolutional encoder-decoders that work at several resolutions, with skip connections between matching levels and attention added at lower resolutions. A DiT keeps one token resolution, attends globally in every block, and has fewer image-specific design choices, so it scales the way transformers do in large language models.
- Vision Transformer: ViT encodes an image for tasks such as classification. DiT reuses its patch embedding and transformer blocks, adds timestep conditioning through adaLN-Zero, and outputs a prediction for every patch.
- Latent diffusion and flow matching: A latent diffusion model is the overall framework of denoising in a VAE's latent space, and diffusion or flow matching is the training objective. DiT is the denoising network inside that framework, and current generators pair DiT backbones with flow matching objectives.
Text-to-Image and Video DiTs#
- Multimodal DiT (MMDiT): Stable Diffusion 3 feeds image tokens and text tokens through separate weights for each modality and joins them in a single attention operation, so information flows both ways between the prompt and the image. This improved typography and prompt following, and Stable Diffusion 3.5 Large scales the design to about 8 billion parameters.
- FLUX.1: Black Forest Labs' FLUX.1 is a 12-billion-parameter rectified flow transformer for text-to-image generation.
- Video: OpenAI's Sora technical report describes a diffusion transformer that compresses videos into a latent space and splits them into spacetime patches, so clips of different durations, resolutions, and aspect ratios become token sequences of different lengths. For video generation, Meta's largest Movie Gen model is a 30-billion-parameter transformer whose context of 73,000 video tokens corresponds to 16 seconds of video at 16 frames per second.










