Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention

  • 2020-06-29 17:55:38
  • Angelos Katharopoulos, Apoorv Vyas, Nikolaos Pappas, Fran├žois Fleuret
  • 21


Transformers achieve remarkable performance in several tasks but due to theirquadratic complexity, with respect to the input's length, they areprohibitively slow for very long sequences. To address this limitation, weexpress the self-attention as a linear dot-product of kernel feature maps andmake use of the associativity property of matrix products to reduce thecomplexity 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 aniterative implementation that dramatically accelerates autoregressivetransformers and reveals their relationship to recurrent neural networks. Ourlinear transformers achieve similar performance to vanilla transformers andthey are up to 4000x faster on autoregressive prediction of very longsequences.


Quick Read (beta)

loading the full paper ...