# Rethinking Attention with Performers

Krzysztof Choromanski, Valerii Likhosherstov, David Dohan, Xingyou Song, Andreea Gane, Tamas Sarlos and 7 more · arXiv · 2020-9-30

- **Problem** Regular softmax attention builds an L by L attention matrix, so its time and memory grow quadratically with sequence length L, which blocks long inputs.
- **Method** Writes each attention kernel as an expectation of a feature inner product, then reorders the matrix products with positive random features so the cost is linear in L.
- **Results** Reached about 24% accuracy on concatenated TrEMBL at L = 8192, where a 3-layer Transformer plateaued near 19%.

## Why exact attention is expensive for long inputs

Transformers rely on a trainable attention mechanism that finds dependencies between the elements of an input sequence. The cost of that mechanism grows quadratically with the number of tokens L, which is expensive for large L even at moderate sizes. Bidirectional attention forms the L by L attention matrix A explicitly, so its time is O(L2d) and its space is O(L2+Ld).

Because the matrix must be stored, this form of dot-product attention does not fit end-to-end processing of long sequences.

Sparse and structured remedies restrict attention to local neighborhoods, sliding windows or clusters, or impose sparsity patterns. The authors argue that these methods lack rigorous guarantees on the representational power they keep, and that sparsity patterns are often checked only empirically. Locality sensitive hashing, one such sparse approach, has O(Ld2 logL) time complexity, which is the comparison point the paper uses for its own bound.

## Attention as a kernel with random features

Each entry of the attention matrix is a kernel value K(qi, kj) between a query row and a key row. If the kernel can be written as an expectation of an inner product of feature vectors, K(x, y) = E\[φ(x)ᵀφ(y)\], then the features of all queries and keys can be stacked into matrices Q′ and K′. The paper restricts the feature map to nonnegative outputs, φ mapping Rd into the nonnegative orthant of dimension r.

The normalizer is computed from the same features as \\(\\hat{D}=\\mathrm{diag}(Q'((K')^\\top 1\_L))\\), so no L by L matrix is needed. This order of computation needs O(Lr+Ld+rd) space and O(Lrd) time, against O(L2+Ld) space and O(L2d) time for regular attention.

The mechanism has two parts: the feature-based computation just described, and a second part that asks whether such a feature model can approximate softmax and how to implement it robustly. The second part also covers whether the number of features r can be kept much smaller than L while still giving the desired gains.

## Choosing features for the softmax kernel

The softmax-kernel is SM(x, y) = exp(xᵀy), and it defines the regular attention matrix; the paper omits the scaling by the square root of d because queries and keys can be renormalized instead. Since SM(x, y) = exp(‖x‖²/2) Kgauss(x, y) exp(‖y‖²/2), a trigonometric feature map with h(x) = exp(‖x‖²/2), l = 2, f1 = sin and f2 = cos gives an unbiased approximation of the softmax-kernel, written SMtrig.

Attention forms each output as a convex combination of value vectors, with weights taken from kernel scores, so the kernel scores must be nonnegative. Trigonometric features can take negative values, and the paper reports that this leads to unstable behaviour during training. Positive softmax features with feature redrawing are the variant that the paper reports as matching regular Transformers on PG-19.

The paper states that the resulting estimator is unbiased or nearly unbiased, with uniform convergence, and that it has lower variance of the approximation than the alternatives it compares. Proofs of these properties are part of the theoretical material, and they are not reproduced in the units read here.

## Protein modeling on TrEMBL

The protein experiments train a 36-layer model on TrEMBL sequences, in both the (U) and (B) cases. All runs used the model parameters (nheads, nlayers, dff, d) = (8, 36, 1024, 512) taken from Madani et al., on 16x16 TPU-v2 hardware.

Reformer and Linformer drop noticeably in accuracy on this dataset. Performer-RELU, which takes f = ReLU in the generalized attention form, reaches the highest accuracy in both the (U) and (B) cases.

The softmax approximation of the Performer reaches the same accuracy as the exact-softmax Transformer, which the authors read as confirming the tightness claimed in their theory.

## Long-length training on ImageNet64 and concatenated TrEMBL

On ImageNet64 with L = 12288, the regular Transformer is unfeasible, so the models share the same heads and feed-forward size and differ only in number of layers. Performer/6-layers matches Reformer/12-layers, and Performer/12-layers matches Reformer/24-layers.

The Performer trains at a batch size of 8 per chip with the standard (8, 6, 2048, 512) architecture. The authors describe this as a proof of principle for predicting interactions among groups of proteins.

The 3-layer Transformer is bounded at about 19%, while the Performer keeps training to about 24%. Depending on hardware and with Jax optimizations, the Performer can be 2x faster than the Reformer in the (U) setting.

## Feature choice and weight transfer on PG-19

The original pretrained Transformer's weights were transferred into the Performer, which starts at a non-zero 0.07 accuracy and recovers in a small fraction of the original gradient steps. The comparison covers trigonometric features, positive features without redrawing, Linformer with redrawn projections, and positive features with redrawing.

On PG-19, trigonometric softmax approximation becomes highly unstable during training. Positive features without redrawing and Linformer with redrawn projections plateau at the same perplexity. The authors state that positive softmax features with feature redrawing are necessary to match the Transformer, and that the regularization SMREG allows faster convergence.

Ablations across attention kernels show that trigonometric random features can produce NaN values during training.

## Limitations

The concatenated TrEMBL comparison uses a smaller regular Transformer as baseline, because the full-size regular model overloads memory. The 2x speed-up over the Reformer depends on hardware and on Jax optimizations, and it is reported for the (U) setting only.

The main analysis is written for bidirectional attention; the unidirectional case is described as analogous through prefix sums, with details in the appendix. Without feature redrawing, the positive features plateau instead of matching the regular Transformer on PG-19.

## Paper info

- **Authors**: Krzysztof Choromanski, Valerii Likhosherstov, David Dohan, Xingyou Song, Andreea Gane, Tamas Sarlos, Peter Hawkins, Jared Davis, Afroz Mohiuddin, Lukasz Kaiser, David Belanger, Lucy Colwell, Adrian Weller
- **Venue**: arXiv · Preprint
- **First published**: 2020-9-30
- **Added**: 2026-10-20
- **Updated**: 2022-11-19
- **Version**: v4
- **arXiv**: 2009.14794
- **Category**: cs.LG · cs.CL · stat.ML
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2009.14794v4) · [PDF ↗](https://arxiv.org/pdf/2009.14794v4)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Krzysztof Choromanski, Valerii Likhosherstov, David Dohan, Xingyou Song, Andreea Gane, Tamas Sarlos, Peter Hawkins, Jared Davis, Afroz Mohiuddin, Lukasz Kaiser, David Belanger, Lucy Colwell, Adrian Weller (2020). Rethinking Attention with Performers. arXiv:2009.14794v4. https://arxiv.org/abs/2009.14794v4

**BibTeX**

```
@misc{choromanski2020rethinking,
  title = {{Rethinking Attention with Performers}},
  author = {Krzysztof Choromanski and Valerii Likhosherstov and David Dohan and Xingyou Song and Andreea Gane and Tamas Sarlos and Peter Hawkins and Jared Davis and Afroz Mohiuddin and Lukasz Kaiser and David Belanger and Lucy Colwell and Adrian Weller},
  year = {2020},
  eprint = {2009.14794},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2009.14794v4}
}
```

## Other paper commentary

- [Decision Transformer: Reinforcement Learning via Sequence Modeling](https://refivu.com/en/papers/386e76e8-fee6-4cba-84e8-0ef90a33b3b6-decision-transformer-reinforcement-learning-via-sequence.md)
- [Efficiently Modeling Long Sequences with Structured State Spaces](https://refivu.com/en/papers/9047ef9d-9e54-48f1-8609-ea4ce704605e-efficiently-modeling-long-sequences-with-structured-state.md)
- [Longformer: The Long-Document Transformer](https://refivu.com/en/papers/095aa21a-9a7f-4317-a80b-f961fdd4e423-longformer-the-long-document-transformer.md)
- [Improving neural networks by preventing co-adaptation of feature detectors](https://refivu.com/en/papers/52fe143b-6258-4d22-888e-8274d7357b11-improving-neural-networks-by-preventing-co-adaptation-of.md)
- [Neural Ordinary Differential Equations](https://refivu.com/en/papers/40a9adb0-8309-48fc-abf9-9e698ab35f74-neural-ordinary-differential-equations.md)
- [EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks](https://refivu.com/en/papers/40e064dc-b55a-40c9-a666-b58ee21b4220-efficientnet-rethinking-model-scaling-for-convolutional.md)
- [DeepSeek-V3 Technical Report](https://refivu.com/en/papers/761895a4-08f3-446f-98de-60152a184c97-deepseek-v3-technical-report.md)
- [The Llama 3 Herd of Models](https://refivu.com/en/papers/27985e84-42ca-486e-8e0e-2fa739789ab4-the-llama-3-herd-of-models.md)
- [Linformer: Self-Attention with Linear Complexity](https://refivu.com/en/papers/470ce67a-0f79-4a06-ae89-f26384095187-linformer-self-attention-with-linear-complexity.md)
- [DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning](https://refivu.com/en/papers/2227da56-269c-4116-84dc-2bc76bf3e6c7-deepseek-r1-incentivizing-reasoning-capability-in-llms-via.md)
- [RT-2: Vision-Language-Action Models Transfer Web Knowledge to Robotic Control](https://refivu.com/en/papers/01f24caf-5337-46f9-abb9-a961b79018a1-rt-2-vision-language-action-models-transfer-web.md)
- [Reformer: The Efficient Transformer](https://refivu.com/en/papers/0dd490a3-709f-4bac-ae3f-de0bc9e197db-reformer-the-efficient-transformer.md)

## Terms in this paper

- [Accuracy](https://refivu.com/en/terms/1995c0cd6282-accuracy)
- [perplexity](https://refivu.com/en/terms/2b204e513801-perplexity)
- [Reformer](https://refivu.com/en/terms/09e7750949bd-reformer)
- [Linformer](https://refivu.com/en/terms/760bfa259c19-linformer)
- [Gaussian kernel](https://refivu.com/en/terms/93d7f7f7360b-gaussian-kernel)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/be31745a-9080-4105-b177-3b88d23e4f59-rethinking-attention-with-performers)
