TL;DR
A diffusion transformer, or DiT, is a Diffusion Model whose denoising network is a standard transformer instead of a U-Net. The image is compressed into a small latent grid, cut into patches, and each patch becomes a token. The timestep and the class label are injected through adaptive layer normalisation, so the network can change its behaviour at each noise level without any convolutions.
Where you'll see it: as the backbone of large class-conditional and text-to-image generators, where its quality keeps improving as you add more transformer depth, width and tokens.
Intuition
Same job, different machinery
A diffusion model needs one network that looks at a noisy input and says what the noise is. For years that network was a U-Net: a stack of convolutions with skip connections, built around the assumption that nearby pixels matter most. A Vision Transformer (ViT) makes a different assumption. It cuts the picture into patches and lets every patch look at every other patch through attention.
DiT asks a simple question: if the architecture is only a sequence of tokens, does the diffusion recipe still work? The answer from Peebles and Xie is yes, and it gets better as the transformer gets bigger. The diffusion process, the loss and the sampler stay the same. Only the network that makes the prediction changes.
Why bother? A transformer uses one design everywhere. The same blocks that model language can be scaled with the same rules, and the same hardware and tooling apply. Scaling is the point of the paper: DiT reuses the recipe that already worked for language and vision transformers.
flowchart LR
Z[noisy latent z_t] --> P[patchify into tokens]
P --> B1[DiT block 1]
B1 --> B2[DiT block 2]
B2 --> BN[DiT block N]
BN --> D[linear decode and unpatchify]
D --> E[predicted noise]
C[timestep t and class y] -.->|scale, shift, gate| B1
C -.-> B2
C -.-> BN
The solid path is the data. The dashed lines are the conditioning signal, which reaches every block.
Work on a compressed image
A raw 256 by 256 colour image has 196,608 numbers. Running a transformer over it directly would be far too expensive. DiT therefore works in the latent space of a pretrained Variational Autoencoder, as in the Latent Diffusion Model. The encoder shrinks each image by a factor of 8 in each direction, so a 256 by 256 image becomes a 32 by 32 grid with 4 channels, which is 4,096 numbers. Diffusion runs on that small grid, and a decoder turns the final sample back into pixels.
The math
Setup
Let be the clean latent of an image, a tensor of shape . Diffusion adds noise over steps. Using the notation of the Diffusion Model lesson, the noisy latent at step is
Here is the running product of the noise schedule, and is standard Gaussian noise. The network is trained to predict from , the timestep , and a class label :
This is the same Mean Squared Error objective as before. DiT changes only the form of .
Patchify
The latent grid is cut into non-overlapping patches of side . Each patch is flattened into a vector of length and multiplied by a learned matrix to give a token of width . The number of tokens is
A fixed sine-cosine Positional Encoding is added to each token, so the transformer knows where each patch sat in the grid. The patch size is the main knob. Smaller patches mean more tokens, which means more computation but finer detail.
Conditioning with adaptive layer norm
The timestep is turned into a vector by a sinusoidal embedding followed by a small MLP. The class label is turned into a vector by an embedding table. The two are added to give one conditioning vector .
Inside each block, a normal Layer Normalization step is applied to the tokens with no learned scale or shift. Then is passed through a small linear layer that outputs three vectors for each block: a scale , a shift , and a gate . For a token with a sub-layer (attention or the MLP), the block computes
Here is element-wise multiplication. The gate is the key choice. The authors call the best variant adaLN-Zero: the linear layer that produces is initialised to output zeros. At the start of training every block is therefore the identity map, and the network begins as a simple pass-through. In the paper's comparison, adaLN-Zero gave lower FID than plain adaLN, cross-attention and in-context conditioning.
Output
After the last block, a final adaptive layer norm is applied, and a linear layer maps each token back to numbers. The extra factor of 2 is there because the network also predicts a per-dimension variance, following the learned-variance idea of Nichol and Dhariwal. The tokens are then rearranged back into a grid of shape , and the noise estimate is the first half.
Sampling with guidance
To generate a sample, the reverse process of Diffusion Model is run from pure noise. DiT is usually sampled with Classifier-Free Guidance. The network is also trained with the class label replaced by a null token some fraction of the time. At sampling, the two predictions are combined:
The scale above 1 pushes samples toward the class at the cost of diversity. The paper's best ImageNet 256 by 256 result, an FID of 2.27, uses a guidance scale of 1.5.
Worked examples
Take a 256 by 256 image, which gives a latent grid of with channels.
- Patch size : tokens. Each raw patch has numbers.
- Patch size : tokens. Each raw patch has numbers.
- Patch size : tokens. Each raw patch has numbers.
- Attention compares every pair of tokens, so its cost grows with . Going from to multiplies the token count by 4 and the pairwise score count by .
- Interpretation: halving the patch size is the most expensive way to add detail. The paper finds that, at a fixed model size, smaller patches (more tokens) improve quality even though the parameter count barely changes, so the extra compute is what buys the gain.
Take one feature of one token, with layer-normalised value . Suppose the conditioning gives scale , shift , and the sub-layer output is for this input. The residual input is .
- Modulated input: . Note that this is the input the sub-layer sees, before the gate.
- Case A, gate at initialisation: . The update is . The block passes the input through unchanged.
- Case B, gate after some training: . The update is .
- Interpretation: at the start, every block does nothing, so the gradient flows cleanly through all the layers. The gate then opens gradually as the network learns to use each block.
At one denoising step, suppose the unconditional prediction for a single noise value is and the class-conditional prediction is . Use guidance scale .
- Difference between the two predictions: .
- Scaled difference: .
- Guided prediction: .
- Interpretation: the guided step moves further in the direction the class label points than the plain conditional model does. Setting recovers the conditional model, and gives the unconditional one.
Tradeoffs and failure modes
DiT is a good default when you have enough compute to train a large transformer and want the architecture to scale predictably. It is a poorer fit when the data is small, when you need very cheap sampling on a phone, or when you already have a strong convolutional pipeline.
| Situation | Problem | Better choice |
|---|---|---|
| Small dataset, few GPUs | A large transformer overfits or never trains well | A U-Net with fewer parameters |
| Very high resolution | Token count grows with the square of the side length | Patchify a stronger latent, or use a hierarchical model |
| Interactive generation | Many network calls per sample, each with full attention | Fewer sampling steps through a faster sampler, or distillation |
| No class or text conditioning, only the timestep | The class half of the conditioning vector is unused | Keep adaLN driven by the timestep alone, or use a simpler conditioning path |
| Plain adaLN without zero-initialised gates | In the paper's comparison it reached a worse FID than adaLN-Zero at the same compute | adaLN-Zero, as in the paper |
Two failure modes are common. First, forgetting the patch size: the same architecture at a different is a different model, with a different cost and a different quality. Second, comparing models at different sampling steps or guidance scales. The paper's headline numbers depend on the sampler and the guidance scale, so a fair comparison fixes both.
History
Ho, Jain and Abbeel's 2020 work made diffusion models practical for images, using a U-Net as the denoiser. Rombach and colleagues then moved the diffusion into the latent space of an autoencoder, which made high-resolution generation affordable.
William Peebles and Saining Xie published the Diffusion Transformer in late 2022, and the paper appeared at ICCV in 2023. Their central claim was that the diffusion recipe is not tied to convolutions. Replacing the U-Net with a transformer that is patchified and conditioned with adaptive normalisation gave consistent gains as the model grew. Their largest model, DiT-XL/2, reached a Fréchet Inception Distance of 2.27 with classifier-free guidance on class-conditional ImageNet at 256 by 256, beating the previous best diffusion result of 3.60 from the latent diffusion model. The paper also showed that the forward-pass compute of a model, measured in Gflops, is strongly correlated with its sample quality across different sizes and token counts.
The idea caught on because it made the diffusion field use the same architecture as the rest of deep learning. Later text-to-image systems adopted transformer denoisers in the same spirit.
Check yourself
QuestionRecall: what are the three things DiT's adaLN produces from the conditioning vector for each block?Show answer
A scale and a shift , which modulate the normalised tokens before the sub-layer, and a gate , which scales the sub-layer's output before it is added back to the residual stream.
QuestionComputation: a latent grid is 64 by 64 with 4 channels. With patch size , how many tokens are there, and how many numbers does each raw patch hold?Show answer
The number of tokens is . Each raw patch holds numbers before the linear embedding projects it to width .
QuestionWhy: why is the gate initialised to zero in adaLN-Zero rather than to a random value?Show answer
With every block is the identity at the start of training, because the residual update vanishes. The whole network begins as a simple pass-through, so gradients reach every layer cleanly. A random gate would add random sub-layer outputs at every depth, which makes deep models unstable early in training. The gate opens only as the network learns that the block is useful.
QuestionApplied: you are building a DiT for 512 by 512 images with a latent grid of 64 by 64 and patch size 2. Roughly how much more attention work is this than the 256 by 256 model with patch size 2, and why?Show answer
The 512 model has tokens, and the 256 model has tokens. Attention compares every pair of tokens, so its cost scales with . The ratio is . Each attention layer does about 16 times the pairwise work, even though the image has only four times as many pixels. The cost grows faster than the image area, which is why high-resolution transformer diffusion usually relies on a larger patch size or a hierarchical design.