Differential Transformer: Subtract two attention maps to suppress noise
Differential Transformer computes two softmax attention maps and subtracts them to cancel shared noise. The paper reports improvements in language modeling, long-context retrieval and hallucination metrics.
On this page
Differential Transformer addresses excessive attention to irrelevant tokens. Each head learns two query/key systems and subtracts their attention distributions with a learned coefficient.
How it works
Its output is (softmax(Q1K1)-lambda·softmax(Q2K2))V. Subtraction resembles differential denoising, but weights need not be nonnegative. Lambda varies by layer and head, with RMSNorm for stability.
What the evidence shows
Across several scales and token budgets, the paper reports lower perplexity and better key-information retrieval and context robustness. This changes attention allocation rather than extending the context window itself.
A reproducible check
This snippet checks a public formula or configuration; it does not reproduce full training.
import math
logits1 = [2.0, 1.0, 0.0]
logits2 = [1.5, 1.0, 0.5]
def softmax(xs):
es=[math.exp(x-max(xs)) for x in xs]
return [e/sum(es) for e in es]
a,b=softmax(logits1),softmax(logits2)
d=[x-0.8*y for x,y in zip(a,b)]
print("map 1 =", [round(x,4) for x in a])
print("map 2 =", [round(x,4) for x in b])
print("difference =", [round(x,4) for x in d])
map 1 = [0.6652, 0.2447, 0.09]
map 2 = [0.5065, 0.3072, 0.1863]
difference = [0.2601, -0.001, -0.059]
The arithmetic is reproducible, but model quality still depends on the full experiments in the paper.
Limitations and common misreadings
Two QK systems add compute and parameters, controlled through dimension choices. Negative weights are possible, and actual kernel speed requires separate measurement.
The key takeaway
The core hypothesis is attention noise: subtracting related distributions can emphasize useful differences, at a real implementation cost.
Further reading
FAQ
- Does differential attention add two maps?
- No. It subtracts two softmax maps using a learned coefficient.
- Are all resulting weights positive?
- No. Subtraction permits negative weights, so they are not an ordinary probability distribution.
- What improves in the paper?
- Perplexity, long-context key retrieval and robustness to irrelevant context.