# 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.

- URL: https://dmxsf.com/en/blog/differential-transformer/
- [DMXSF](https://dmxsf.com/en/about/)
- Published: 2024-10-17
- Updated: 2026-11-13
- Paper notes
- Paper: [Differential Transformer](https://arxiv.org/abs/2410.05258) (Tianzhu Ye, Li Dong, Yuqing Xia, et al. · arXiv, 2024)

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.

```python
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])
```

```text
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

- [Differential Transformer](https://arxiv.org/abs/2410.05258)
- [The original Transformer](https://dmxsf.com/en/blog/attention-is-all-you-need/)
- [Lost in the Middle](https://dmxsf.com/en/blog/lost-in-the-middle/)

## 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.
