Linear-Transformer (Katharopoulos)
A transformer whose attention cost grows linearly, not quadratically, with sequence length.
276 operations Checked
Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.
At a glance
- Parameters
- 16.8M
- Operations
- 276
- Framework
- PyTorch
- Recurrent
- No
- Published
- ICML 2020
- Cited by
- 827 (as of 26 October 2026)
- Authors
- Angelos Katharopoulos, Apoorv Vyas, Nikolaos Pappas, François Fleuret
- License
- MIT
- Checked
- Passed: the trace was replayed operation by operation and matched the model's own output for this input.
Files
The file opened in a new tab. Use your browser's Save command there to keep it.
The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.
Details
- Stable ID
- m17949
- Graph hash
- e1424c78f42970c07c5dd04d1edd2c10bad613a0e6ebac55e5885713626ff8b4
- Skeleton hash
- 5cad6c13b0b75c36b6328ecb3374433e709717b14848c3cc55543ebd3110bc5c
- Architecture hash
- 3658c3f48399e0239b414f661cdf1e9a54234f067b9aa923f29df1a7d252466d
- Diagram SHA-256
- a5dc068e04dea4409d26e6201cad2e652ff754eda9f97c6f7077771889308906
- TorchLens version
- 2.36.0
- Renderer
- graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
- Check
- Forward pass replayed in PyTorch
What it is
The Linear Transformer is a transformer whose self-attention is computed in time and memory that scale linearly with the sequence length. The paper starts from the observation that ordinary transformers have quadratic complexity in the input length, which makes them prohibitively slow for very long sequences.
The change is inside the attention: it is expressed as a linear dot-product of kernel feature maps, and the associativity of matrix products is then used to reduce the complexity. The feature map in the paper's experiments is built on the exponential linear unit (elu), which the authors prefer over relu to avoid setting the gradients to 0 when x is negative. With causal masking, any transformer layer can then be written as a model that modifies an internal state and predicts an output, that is, a recurrent neural network, which gives the paper its title, Transformers are RNNs.
The paper evaluates on image generation and automatic speech recognition and reports that the linear transformer reaches the performance levels of the transformer while being up to three orders of magnitude faster during inference. This model is a transformer encoder with linear attention built with the Fast Transformers library, as in the library's quick-start, which encodes a sequence with 1000 elements.
Key idea. The paper rewrites self-attention as a linear dot-product of kernel feature maps, reducing its cost from quadratic to linear in sequence length and exposing a link to recurrent networks.
- linear transformer
- linear attention
- transformers are rnns
- fast transformers
- fast-transformers
- efficient attention
- kernel feature map attention
- katharopoulos linear attention
AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.
Cite the paper
@misc{katharopoulos2020transformersrnnsfastautoregressive,
title={Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention},
author={Angelos Katharopoulos and Apoorv Vyas and Nikolaos Pappas and François Fleuret},
year={2020},
eprint={2006.16236},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2006.16236},
}