↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Layer 1 of 12 λ = λinit = 0.8 − 0.6·e−0.3·0 = 0.200 Formula demo · GPT-2’s real Q, K, V · 12 heads, Q and K split 32 + 32, V 64-D · scale 1/√32 · causal · named choices: λ vectors = 0, RMSNorm gain = 1
Loading recorded attention…

What differential attention is

A softmax never gives a key exactly zero weight, so every head spreads some attention over tokens that do not matter; Ye et al. call this attention noise, and observe that a Transformer tends to over-allocate attention to irrelevant context. Differential attention computes two attention maps in each head and subtracts one from the other. Noise common to both cancels, as in a differential amplifier, and what is left is sparser and more focused on the relevant tokens.

This page is a formula demo. It takes GPT-2 small's real queries, keys and values, recorded on the MHA tab's three prompts, and applies the Diff Transformer formula to them in 6 of the 12 layers. GPT-2 was not trained this way, and two quantities a trained Diff Transformer learns are set to named values here: the λ vectors to 0 and the RMSNorm gain to 1. The page shows what the formula computes, not what a trained differential model would attend to.

Two maps from one head

Each head's query and key are split into two halves; the value is not. With GPT-2's 64-dimensional heads that gives two 32-dimensional query–key pairs and one 64-dimensional value:

with the causal mask in both softmaxes. The Q₁|Q₂ and K₁|K₂ boxes on the head card mark the split. The Two softmax maps panel draws and for the selected head, and the head card draws their difference, , as a signed matrix.

λ

In the paper is learned through four vectors per layer, around a starting value that grows with depth:

with the layer index counted from 0. With the four vectors at 0, the two exponentials are both 1 and cancel, so : 0.200 in layer 1, 0.666 in layer 6 and 0.778 in layer 12, as the toolbar shows.

Because each softmax row sums to 1, a row of the difference sums to , and some of its weights are negative wherever outweighs . The panel under the maps counts them: in layer 6, head 1 of the Coreference prompt, 40 of the 78 weights are negative, down to −0.367. That is far from the sparse pattern a trained model learns; GPT-2 learned one 64-dimensional query and key per head, not two halves meant to cancel.

The head output

The difference makes the scale of a head's output depend on , so each head is normalised on its own, with an RMSNorm, and then multiplied by a fixed , which the paper uses to keep gradients on the same scale as a standard Transformer's:

The Head output strips show this result per head. The heads are then concatenated and projected as in multi-head attention; this demo stops before that projection, since GPT-2's was trained for a different input.

What the paper reports

Ye et al. trained Diff Transformers from scratch and report that they outperform Transformers across their settings of model size and training tokens, with clear advantages in long-context modelling, retrieving key information, reducing hallucination in question answering and summarisation, in-context learning, and smaller activation outliers. The subtraction lets a head give near-zero weight to what it ignores, which a single softmax can only approach by pushing other scores very high. That is the same pressure that produces attention sinks (the Sinks tab), where heads park unused weight on the first token.

Where it came from

Differential attention was introduced by Ye et al. in 2024 and presented at ICLR 2025. It modifies the scaled dot-product attention of Vaswani et al. (the MHA tab) and borrows its normalisation from RMSNorm (Zhang and Sennrich, 2019). The Gated tab shows another recent change aimed at the same problem: a learned gate on each head's output, so that a head can switch itself off instead of attending to a sink.

Papers

  1. Differential Transformer Tianzhu Ye, Li Dong, Yuqing Xia, Yutao Sun, Yi Zhu, Gao Huang, Furu Wei · ICLR 2025 Introduces differential attention: two softmax maps per head, subtracted with a learned λ, then a per-head norm.
  2. Attention Is All You Need Ashish Vaswani et al. · NeurIPS 2017 Scaled dot-product attention, the single map differential attention replaces.
  3. Language Models are Unsupervised Multitask Learners Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, Ilya Sutskever · 2019 GPT-2, whose recorded queries, keys and values this demo uses.
  4. Root Mean Square Layer Normalization Biao Zhang, Rico Sennrich · NeurIPS 2019 RMSNorm, the per-head normalisation after the subtraction.
  5. Efficient Streaming Language Models with Attention Sinks Guangxuan Xiao, Yuandong Tian, Beidi Chen, Song Han, Mike Lewis · ICLR 2024 Attention sinks, the weight a single softmax parks on uninformative tokens (the Sinks tab).

See also