Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention
About
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.
Related benchmarks
| Task | Dataset | Result | Rank | |
|---|---|---|---|---|
| Language Modeling | WikiText-103 (test) | Perplexity22.2 | 524 | |
| Natural Language Understanding | GLUE (dev) | SST-2 (Acc)91.51 | 504 | |
| Natural Language Understanding | GLUE | SST-284.63 | 452 | |
| Machine Translation | WMT En-De 2014 (test) | BLEU28.4 | 379 | |
| Machine Translation | WMT En-Fr 2014 (test) | BLEU41.8 | 237 | |
| Character-level Language Modeling | enwik8 (test) | BPC1.207 | 195 | |
| Language Modeling | WikiText-103 (val) | PPL27.44 | 180 | |
| Long-range sequence modeling | Long Range Arena (LRA) | Text Accuracy65.9 | 164 | |
| Long-range sequence modeling | Long Range Arena (LRA) (test) | Accuracy (Avg)50.5 | 158 | |
| Density Estimation | CIFAR-10 (test) | Bits/dim3.4 | 134 |