Skip to main content
issue 2026-08-11AI Research45 minarXiv 2024interactive

Differential Transformer

This research paper explains why Transformers over-attend to irrelevant context, and how DiffAttn’s dual Softmax subtraction sharpens signal the way noise-canceling headphones cancel shared noise.

Differential attention subtracts two Softmax maps to cancel noiseLeft map A1 carries signal plus noise. Middle map A2 carries shared noise. Right: A1 minus lambda A2 cancels common-mode distractors and leaves a sparse peak toward V.ENTER · A₁SOFTMAX · SIGNAL+NOISEANSPEAKN1NOISEN2RUN · A₂SOFTMAX · NOISE MICN1SHAREDN2SHAREDA₁−λA₂CANCELLEAVE · SPARSEPEAK → VANSKEPTN1/N2 ≈ 0TWO SOFTMAX MAPS · SUBTRACT · CANCEL COMMON-MODE NOISEDiffAttn noise-cancel stackStacked flow: A1 enters with signal and noise, A2 captures shared noise, subtractor cancels distractors, sparse answer peak leaves toward V.ENTER · CANCEL · LEAVEA₁ · SIGNAL + NOISEfirst Softmax mapA₂ · NOISE MICROPHONEsecond Softmax mapRUN · A₁ − λ A₂shared distractors cancelLEAVE · SPARSE PEAK → Vanswer mass survivesNOISE-CANCELING ATTENTION

Transformer attention is a Softmax over every past key. That Softmax is great at ranking — and equally great at leaking mass onto tokens that do not matter. When the haystack is long, irrelevant context is not a rounding error; it is a chronic distractor for retrieval, in-context learning, and grounded generation.

Differential Transformer’s punchline is almost acoustic: treat attention noise like common-mode interference. Compute two Softmax attention maps from paired query/key projections, then take their difference. Shared noise cancels; sparse peaks on the relevant span survive.

What this paper explains

Ye et al. replace the usual attention operator inside an otherwise LLaMA-style stack (RMSNorm, SwiGLU, RoPE) with differential attention:

  1. Project XX into paired queries/keys [Q1;Q2][Q_1; Q_2], [K1;K2][K_1; K_2] and a shared value VV.
  2. Form two Softmax maps A1A_1 and A2A_2.
  3. Subtract with a scalar λ\lambda: attention becomes (A1λA2)V(A_1 - \lambda A_2) V.
  4. Multi-head DiffAttn applies GroupNorm per head and a (1λinit)(1-\lambda_{\mathrm{init}}) multiplier so early training stays stable.

They then show the architecture is not a curiosity: on matched LLaMA-style training it improves language-modeling efficiency, long-context NLL, multi-needle retrieval, in-context learning robustness, and contextual hallucination metrics — while also shrinking activation outliers in attention logits.

Differential attention from two Softmax mapsQ1 K1 and Q2 K2 each form a Softmax map. Subtract with lambda, then multiply by V.Softmax A₁Q₁K₁ᵀSoftmax A₂Q₂K₂ᵀ− λA₁ − λ A₂sparse peak× Vcommon-mode noise shrinks; answer coordinate stays large

Prior limits

  • Single Softmax. One map must both elevate the answer and suppress distractors. Softmax never goes negative, so “canceling” noise means hoping competing scores stay small — not subtracting them.
  • Long distractors. Needle-in-a-haystack and multi-needle setups expose the failure mode: accuracy falls as more distracting needles appear, even when the answer span is present.
  • Downstream symptoms. The paper ties diffuse attention to contextual hallucination (summarization / QA) and to brittle in-context learning under example-order permutations.
  • Activation outliers. Large attention-logit spikes complicate low-bit kernels; a mechanism that reduces outliers is operationally useful beyond accuracy tables.

The mechanism

Differential attention. Split the usual QQ and KK projections into two halves (same total projection width as a baseline head budget). With head dimension dd:

[Q1;Q2]=XWQ,[K1;K2]=XWK,V=XWV[Q_1; Q_2] = X W^{Q},\quad [K_1; K_2] = X W^{K},\quad V = X W^{V}
DiffAttn(X)=(softmax(Q1K1d)λsoftmax(Q2K2d))V\operatorname{DiffAttn}(X)=\Big(\mathrm{softmax}\Big(\frac{Q_1 K_1^{\top}}{\sqrt{d}}\Big)-\lambda\,\mathrm{softmax}\Big(\frac{Q_2 K_2^{\top}}{\sqrt{d}}\Big)\Big)V

The scalar λ\lambda is learned, parameterized so it stays near a layer-wise initialization:

λ=exp(λq1λk1)exp(λq2λk2)+λinit\lambda=\exp(\boldsymbol{\lambda}_{q_1}\cdot\boldsymbol{\lambda}_{k_1})-\exp(\boldsymbol{\lambda}_{q_2}\cdot\boldsymbol{\lambda}_{k_2})+\lambda_{\mathrm{init}}

with

λinit=0.80.6×exp(0.3(l1))\lambda_{\mathrm{init}}=0.8-0.6\times\exp(-0.3\cdot(l-1))

for layer index ll (1-based). Early layers start with larger λinit\lambda_{\mathrm{init}}; deeper layers anneal toward 0.20.2.

Why subtraction helps. If A1A_1 and A2A_2 both put mass on the same irrelevant tokens, those coordinates shrink in A1λA2A_1-\lambda A_2. Coordinates where A1A_1 is large and A2A_2 is small become the sparse peaks. The paper’s headphone analogy is apt: the second Softmax is the “noise mic.”

Interactive

How hard to subtract the noise map?

Toy row: fixed Softmax maps A₁ and A₂. Slide λ to form A₁ − λ A₂. Shared noise shrinks; the answer coordinate stays comparatively large.

Around the paper’s λ_init regime, shared noise drops while the answer coordinate remains the tall bar.

Multi-head wrapper. Heads share λ\lambda within a layer. Each head output is GroupNormalized and scaled by (1λinit)(1-\lambda_{\mathrm{init}}) before concatenation and WOW^{O} — matching the paper’s Equations (3)–(5) residual block with SwiGLU.

Multi-head differential attention stackSeveral DiffAttn heads share a layer lambda, each applies GroupNorm and a one-minus-lambda-init scale, then concatenate through WO.head 1DiffAttn+ GroupNormhead 2DiffAttn+ GroupNormhead 3DiffAttn+ GroupNormshare λper layerConcat · Wᴼ× (1−λ_init)Same residual + SwiGLU block as a LLaMA-style Transformer — only attention changes

Algorithm walkthrough

  1. Choose head count hh and differential head dimension dd (paper often uses fewer heads than Transformer at matched parameter count because each Diff head carries two Softmax maps).
  2. For each head, form Q1,Q2,K1,K2,VQ_1,Q_2,K_1,K_2,V from XX.
  3. Compute A1=softmax(Q1K1/d)A_1=\mathrm{softmax}(Q_1 K_1^{\top}/\sqrt{d}) and A2=softmax(Q2K2/d)A_2=\mathrm{softmax}(Q_2 K_2^{\top}/\sqrt{d}).
  4. Form (A1λA2)V(A_1-\lambda A_2)V; apply GroupNorm and the (1λinit)(1-\lambda_{\mathrm{init}}) scale.
  5. Concatenate heads, project with WOW^{O}, residual + MLP as in LLaMA.
  6. Optionally implement the two Softmax paths with FlashAttention-style kernels (Appendix A) — DiffAttn is not anti-FlashAttention; it reuses it twice then subtracts.

The opening figure shows the same story spatially: two Softmax heat strips enter a subtractor; noise bars cancel; a sparse answer peak leaves toward VV.

What to notice when reading

  • DiffAttn changes the score algebra, not the KV cache policy (contrast StreamingLLM’s sink/window cache).
  • λ\lambda is a layer scalar with a carefully chosen λinit\lambda_{\mathrm{init}} schedule — ablations with fixed 0.80.8 / 0.50.5 still work, but the schedule is the default.
  • GroupNorm is load-bearing in their 1.4B ablations: removing it hurts validation loss.
  • Attention scores can be negative after subtraction; the operator is no longer a convex combination of values.
  • Throughput overhead in their microbenchmarks is modest (roughly 5512%12\% slower than matched Transformer at 3B/13B in Table 7 of the paper), not a 2×2\times tax.

Results and evidence

All numbers below are as reported by Ye et al. on their matched training setups — not universal constants.

LM Eval Harness (3B, 1T tokens training comparison in their Table 1). Diff-3B averages 60.6 across ARC-C/E, BoolQ, HellaSwag, OBQA, PIQA, WinoGrande vs 57.5 OpenLLaMA-3B-v2 and 56.8 StableLM-base-alpha-3B-v2 under the authors’ reported comparison.

Scaling (Section 3.2). Their scaling curves claim Diff Transformer needs only about 65% of the model size or training tokens for Transformer to match language-modeling loss.

Multi-needle retrieval at 4K (Table 2). With NN answer-relevant needles and distractors, average accuracy stays higher for Diff as NN grows — e.g. at N=6N=6, 0.85 vs Transformer 0.55. They also report a case where the accuracy gap reaches about 30%.

Attention mass on answer vs noise (Table 3). In the retrieval probe, Diff assigns much more attention to answer spans (e.g. 0.27–0.40 across depths) and far less to noise (~0.01–0.02) than Transformer (~0.03–0.09 answer, ~0.49–0.54 noise).

Contextual hallucination (Tables 4–5 in paper; summarization / QA hit rates). Diff improves the authors’ hallucination-oriented metrics on XSum / CNN-DM / MultiNews and on Qasper / HotpotQA / 2WikiMQA versus their Transformer baseline (e.g. MultiNews 0.61 vs 0.42; Qasper 0.39 vs 0.28).

Activation outliers (Table 5). Top attention-logit magnitudes drop sharply (Transformer top-1 318.0 vs Diff 38.8 in their measurement), which they flag as helpful for low-bit attention kernels.

Limitations

Compressed from the paper’s scope and what it does not claim:

  • Gains are measured against the authors’ LLaMA-style Transformer reimplementation and selected public 3B checkpoints — not against every 2024–2025 long-context baseline.
  • Differential heads change FLOPs/memory shape (two Softmax maps); their throughput table shows a small slowdown, not a free lunch.
  • Negative attention weights change the usual probabilistic interpretation of attention; interpretability tools that assume a simplex may need care.
  • Sparse patterns suggest KV compression opportunities, but the paper leaves production sparse-KV serving as future work.
  • Hallucination metrics are task-specific automatic scores, not a universal factuality guarantee.

How to read the paper

  1. Abstract + §1 — noise-canceling motivation.
  2. §2.1 — DiffAttn equations (1)–(2) and λ\lambda parameterization.
  3. §2.1–2.2 — multi-head GroupNorm wrapper and the full block.
  4. §3.2 — scaling curves (~65% claim).
  5. §3.4 + Tables 2–3 — multi-needle accuracy and attention-to-answer vs noise.
  6. §3.6–3.7 — hallucination metrics and outlier magnitudes.
  7. Appendix A — FlashAttention-friendly implementation sketch.

Knowledge check

What does DiffAttn subtract?

Why can subtraction reduce attention noise when a single Softmax cannot “cancel”?

In the authors’ multi-needle 4K probe (Table 2), what happens as more distracting needles are added?

What role does λ_init play?

Keep reading

  1. Original paper (arXiv:2410.05258) — §2 mechanism, §3.4 retrieval, Appendix A kernels.
  2. Related Fanout Daily: Attention is All You Need, FlashAttention, StreamingLLM, GQA, RoPE.
  3. Vaswani et al., Attention Is All You NeedarXiv:1706.03762.
  4. Dao et al., FlashAttentionarXiv:2205.14135.

Sources