HackerPapers

arXiv:2006.16236cs.LG

Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention

Angelos Katharopoulos, Apoorv Vyas, Nikolaos Pappas, François Fleuret

Abstract

Transformers achieve remarkable performance in several tasks but due to their quadratic complexity, with respect to the input's length, they are prohibitively slow for very long sequences. To address this limitation, we express the self-attention as a linear dot-product of kernel feature maps and make use of the associativity property of matrix products to reduce the complexity from $\mathcal{O}\left(N^2\right)$ to $\mathcal{O}\left(N\right)$, where $N$ is the sequence length. We show that this formulation permits an iterative implementation that dramatically accelerates autoregressive transformers and reveals their relationship to recurrent neural networks. Our linear transformers achieve similar performance to vanilla transformers and they are up to 4000x faster on autoregressive prediction of very long sequences.

arXiv comments
ICML 2020, project at https://linear-transformers.com/
Journal reference
DOI
Subjects
cs.LGMachine Learning stat.MLMachine Learning (Statistics)

On Hacker News

Linked by 10 identifiable commenters in 16 comments across 12 threads, from Jul 2020 to Feb 2026. Found in 1 HN submission from Jul 2020 to Jul 2020. Open submission discussions.

Comments linking this paper, per year.

Discussed in comments12 threads

    • This is a form of linear attention (https://arxiv.org/abs/2006.16236) that approximates standard scaled dot-product attention to arbitrary precision, by adding Taylor terms in an efficient manner. Each additional Taylor term improves the approximation. Efficiency is achieved by…

      fheinsenView on HNParent context

    • [3] is linear attention, https://arxiv.org/abs/2006.16236, a well-known result with ~3K citations: https://scholar.google.com/scholar_lookup?arxiv_id=2006.1623...

      fheinsenView on HNParent context

    • > Who out there is working on ... infinite history? Many people are still working on improving RNNs, mostly in academia. Examples off the top of my head: * RWKV: https://arxiv.org/abs/2006.16236 / https://arxiv.org/abs/2404.05892 https://arxiv.org/abs/2305.13048 * Linear…

      cs702View on HNParent context

    • There is a LOT of effort in the research community currently: 1. Improving the Self-Attention in the Transformer as is, keeping the quadratic complexity, which has some theoretical advantage in principle[1]: The most hyped one probably DeepSeek's Multi-Latent Attention[15]…

      korbipView on HNParent context

  1. LM2: Large Memory Models 1 comment
    • To further problematize this question (which I don't feel like I can actually answer), consider this paper: "Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention" - https://arxiv.org/pdf/2006.16236 What this shows is that actually a specific narrow…

      FripplebubbyView on HNParent context

  2. Mamba-2 – State Space Duality 2 comments
    • Dao and Gu show that if you simplify Mamba so its state-space layer uses a diagonal matrix A_t that is a scalar times the identity matrix, i.e., A_t = a_t I, the state-space transformation can be expressed as a form of causal linear attention[a] by compounding coefficients a_1…

      cs702View on HNParent context

    • TL;DR: The authors show that if you simplify Mamba so its state-space layer uses a diagonal matrix A that is a scalar times the identity matrix, the state-space transformation can be expressed as a form of causal linear attention.[a] That's the duality the authors refer to in…

      cs702View on HNParent context

    • This looks great. Thank you Gu and Dao! For those who are unaware, previous "state-space models" (SSMs) took the classic state space model from control theory[a], parameterized its matrices, and applied it in discrete time to tokens in a sequence. Many people, including me, got…

      cs702View on HNParent context

  3. There is no A.I. 3 comments
    • > They don’t have any internal state This is a common misconception : they do have internal state. Transformers are RNNs : section 3.4 (page 5) https://arxiv.org/pdf/2006.16236.pdf

      GistNoesisView on HNParent context

    • ^^ See above comment and "Transformers are RNNs" paper to convince yourself. There are various ways of seeing how transformer architectures work. For the past data, using a temporal causal mask, you can compute all past features as they would have been seen by applying the…

      GistNoesisView on HNParent context

    • Transformers are turing complete: https://arxiv.org/abs/1901.03429 Additionally, Transformers are RNNs: https://arxiv.org/abs/2006.16236 Transformers are turing complete RNNs, as are the Neocortex. There are differences like spiking vs non-spiking neurons, universal vs…

      MacsHeadroomView on HNParent context

    • The key component is the linear attention[1] and residual connections. [1] https://arxiv.org/abs/2006.16236 > Transformers achieve remarkable performance in several tasks but due to their quadratic complexity, with respect to the input's length, they are prohibitively slow for…

      PartiallyTypedView on HNParent context

  4. What a transformer can NOT do 1 comment
    • >As there is no hidden state, no "memory" or "intention" can be passed to the future This is probably your misconception : "Transformers are RNNs" https://arxiv.org/pdf/2006.16236.pdf (see section 3.4) Even though an inner state is not specified explicitly like in a LSTM, for a…

      GistNoesisView on HNParent context

    • They are also efficient at inference-time. On GPUs the difference is noticeable only for sequences of length > 1024 (2048 for reformer since it adds some operations for hashing) thanks to the massive parallelism of GPUs amortizing the quadratic effect of the "usual"…

      101101001010View on HNParent context

Submitted to Hacker News

Connected through shared HN threads, not inferred similarity or a recommendation.