TL;DR
Adaptive layer normalization, usually written adaLN, is a way to feed a condition into a Transformer block. The block first normalizes each token with Layer Normalization, which removes the token's own average and spread. Then a small linear layer reads a conditioning vector, such as a diffusion timestep or a class label, and outputs the scale and shift applied to the normalized token. The same weights therefore act differently for each condition, without adding extra tokens to the sequence.
Builds on: Layer Normalization, Feature-Wise Linear Modulation (FiLM) · Leads to: Diffusion Transformer (DiT), Diffusion Model
Where it's used
Diffusion transformers for image generation. The DiT family of image generators runs a Diffusion Model's denoising network as a plain transformer over patches of a compressed image, in the style of the vision transformer. The patch tokens carry positional encodings as usual, and adaLN leaves those alone. Each block needs to know the noise level and the class it is denoising, and adaLN is how those two numbers reach every block. The DiT paper compared several ways to inject the condition and reported that the adaLN-Zero variant gave the best image quality (the lowest FID score) among the options it compared.
Other transformer generators. Any transformer that must be steered by one global signal, such as a diffusion step or a clip-level embedding, can use the same mechanism. A single condition vector per example is cheap to inject and touches every token in the same way.
Style control in image networks. The older idea behind it, adaptive instance normalization, built on instance normalization and was used in style transfer and in the style-based generator architecture, where a style vector sets the scale and shift of feature maps at each layer. The transformer version applies the same pattern to token vectors.
How it works
The block takes a sequence of tokens and one conditioning vector c for the whole example. Here is one pass for a toy token with two features, x = [2, -2]. The condition c has already been turned into a gamma, beta and alpha, and the sub-layer f simply doubles its input.
- Normalize. Compute the mean and spread of the two features: the mean is 0 and the spread is 2, so the normalized token is [1, -1]. Check: the result has mean 0, whatever the original scale was.
- Read the condition. A linear layer maps c to a scale gamma = [3, 1], a shift beta = [0, -1], and a gate alpha = [0.5, 0.5], one number per feature. Check: these depend only on c, not on the token, so every token in this example gets the same modulation.
- Modulate. Multiply each normalized feature by its scale and add its shift: 3 times 1 plus 0 = 3, and 1 times (-1) plus (-1) = -2. The result is [3, -2]. Check: a scale of 0 erases a feature, a scale of 2 doubles it, and the shift moves it up or down.
- Apply the sub-layer. Feed the modulated token into attention or an MLP. Here f doubles it: [6, -4].
- Gate and add back. Multiply the sub-layer output by the gate and add it to the original token, as a residual connection does: 0.5 times [6, -4] = [3, -2], and [2, -2] + [3, -2] = [5, -4]. Check: a gate of 0 switches the whole sub-layer off, and the output is just the original token [2, -2].
The result is that one set of network weights handles every noise level and every class. Only the vectors that the linear layer produces change with c.
flowchart LR X[token x] --> N[normalize] C[condition c] --> L[linear layer] L --> G[scale gamma, shift beta, gate alpha] N --> M[gamma times normalized x, plus beta] G --> M M --> F[attention or MLP f] F --> A[alpha times output] X --> R[add to x] A --> R
The math
Step 1 in symbols: normalization
For a token x with d features, the layer-normalized value is
Here mu is the mean of the token's features, sigma is their spread, and epsilon is a tiny constant that prevents division by zero. The statistics come from the token itself, never from other examples in the batch, which is the key difference from batch normalization.
Steps 2 and 3 in symbols: the modulation
The condition c is turned into three vectors by linear maps W and biases b:
The modulated input and the block output are then
Here the symbol odot is element-wise multiplication. Compare this with the FiLM layer, which also predicts a scale and shift from a second input, but applies them to feature maps after a convolution. adaLN does the same thing to token vectors after a Layer Normalization step, and adds the gate.
Many implementations write the scale as 1 + gamma instead of gamma. The two forms are the same family, but with the second, a zero output from the linear layer means "leave the features unchanged", which makes training start from a stable point.
Parameter count
The linear layer that produces the modulation is the cost of adaLN. For a block of width d with a condition of width d, a version that produces shift, scale and gate for two sub-layers needs six vectors of length d, so 6d outputs, and a weight matrix of d by 6d. The realistic worked example below uses this count.
Worked examples
Take a token with two features, x = [1, -1].
- The mean is 0 and the spread is 1, so LN(x) = [1, -1]. (Ignore epsilon for this check.)
- Suppose the condition gives gamma = [2, 0.5] and beta = [0, 1].
- The first feature: 2 times 1 plus 0 = 2.
- The second feature: 0.5 times (-1) plus 1 = 0.5.
- The modulated token is [2, 0.5]. Both features moved, but in different ways, because the condition set a different scale and shift for each feature.
Take a token x = [3, 1, -1, -3] and a condition that gives every feature the same scale 0.5 and shift 0.1.
- The mean is (3 + 1 - 1 - 3) / 4 = 0.
- The variance is (9 + 1 + 1 + 9) / 4 = 5, so sigma is about 2.236.
- The normalized token is [3, 1, -1, -3] divided by 2.236, which is about [1.342, 0.447, -0.447, -1.342].
- Multiply by the scale 0.5: [0.671, 0.224, -0.224, -0.671].
- Add the shift 0.1: [0.771, 0.324, -0.124, -0.571].
- Interpretation: the normalization removed the original scale of 3, and the condition then chose a new, smaller scale and a small upward shift.
A diffusion transformer block with width d = 1152, the width of the largest DiT model, uses a condition of the same width and produces six vectors of length d per block, for shift, scale and gate in two sub-layers.
- Outputs per block: 6 times 1152 = 6,912 numbers for each example.
- Weights in the modulation layer: 1152 times 6,912 = 7,962,624, about 8.0 million parameters per block.
- Compare with the block's attention and MLP, which have on the order of 12 times d squared, about 16 million weights at this width. The modulation layer is therefore a sizeable share of the block.
- Interpretation: adaLN is not free. Its cost is mostly one linear layer per block, and it is paid once per example, not once per token.
Try it: A block with width d = 768 uses the same six-vector scheme. How many numbers does its modulation layer produce for one example, and how many weights does it have? Answer: 6 times 768 = 4,608 numbers; the weight matrix is 768 times 4,608 = 3,538,944 weights.
Common mistakes and tradeoffs
It is tempting to think adaLN is just layer normalization with a learned scale and shift. In fact the scale and shift in adaLN are computed from the condition, so they change with every example, while a plain layer norm has one fixed scale and shift learned for the whole dataset.
It is tempting to think the condition must be added to the tokens as extra tokens, or joined to them by cross-attention. In fact adaLN injects it as a modulation of every token, which is cheaper and was reported to work better than in-context conditioning and cross-attention in the DiT comparison.
It is tempting to think that a gate of zero destroys the token. In fact the residual path still carries x through unchanged; the gate only switches off the sub-layer's contribution. The gate is set to zero at the start of training so every block begins as an identity map, and the network learns how much of each sub-layer to switch on. This is the adaLN-Zero initialization.
It is tempting to think that the normalization uses the batch, as batch normalization does. In fact layer normalization uses only the features of one token, so the behaviour is the same whatever the batch size.
When to use it: one condition per example that should affect every token in the same way, such as a noise level or a class label.
When not to use it: conditions that differ from token to token, such as a text prompt that must be matched to image regions. Use cross-attention for those, because a single shared scale and shift cannot express per-token relations.
Alternatives: cross-attention to a set of condition tokens, in-context conditioning by adding condition tokens to the sequence, and plain FiLM on convolutional feature maps.
History
Layer normalization was introduced in 2016 to stabilize training of recurrent and feed-forward networks without depending on batch statistics. In 2017 the FiLM layer showed that a network could be steered by predicting a scale and shift from a second input, and adaptive instance normalization applied the same idea to image style. Transformers used layer normalization throughout, but conditioning them on a timestep or class was less settled. The DiT paper in 2022 tested several ways to inject a condition into a transformer for diffusion and found that predicting scale, shift and gate with a linear layer, initialized to the identity, gave the best image quality among the options it tried. That variant, adaLN-Zero, became a common choice in later diffusion transformers.
Recap
- Adaptive layer normalization normalizes each token with its own statistics, then applies a scale and shift predicted from a condition vector.
- The condition changes the modulation for every example, while the network weights stay the same.
- Many versions add a gate on each sub-layer output, and initializing the gate to zero makes every block start as the identity.
- The cost is one linear layer per block, which is paid per example, not per token.
- Read next: Diffusion Transformer (DiT) for the full architecture that uses this block, and Diffusion Model for the process that supplies the timestep.
Check yourself
QuestionWhat does adaLN compute the scale and shift from, and why does that make it different from an ordinary layer norm with learned parameters?Show answer
It computes them from the conditioning vector, which is different for each example, so the same block behaves differently for each condition. An ordinary layer norm learns one fixed scale and shift for the whole dataset.
QuestionA token has features x = [4, -4] and the condition gives gamma = [2, 1] and beta = [1, 0]. Ignoring epsilon, what is the output?Show answer
LN(x) = [1, -1] because the mean is 0 and the spread is 4. The output is [2 times 1 plus 1, 1 times (-1) plus 0] = [3, -1].
QuestionWhy is adaLN-Zero initialized so that the gate starts at zero?Show answer
At the start of training every block is then an identity map, so the network begins as a simple pass-through and the sub-layers are switched on gradually as they learn to help. This was reported to train better than plain adaLN.
QuestionA model must match each word of a prompt to a region of the image. Is adaLN the right tool on its own, and what would you use instead?Show answer
No. adaLN applies one scale and shift to every token from a single condition, so it cannot express a different relation for each image region. Cross-attention to the prompt tokens, which lets each image token pick the words it needs, is the better fit for that task.
Sources
- Ba, Kiros, Hinton. "Layer Normalization" (2016): https://arxiv.org/abs/1607.06450
- Perez et al. "FiLM: Visual Reasoning with a General Conditioning Layer" (2017): https://arxiv.org/abs/1709.07871
- Peebles and Xie. "Scalable Diffusion Models with Transformers" (2022): https://arxiv.org/abs/2212.09748
- "Layer normalization" (Wikipedia): https://en.wikipedia.org/wiki/Layer_normalization