{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/transformers-are-rnns-fast-autoregressive","title":"Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention","arxiv_id":"2006.16236","date":"2020-06-29","proceeding":"ICML 2020 1","authors":["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.","url_abs":"https://arxiv.org/abs/2006.16236v3","url_pdf":"https://arxiv.org/pdf/2006.16236v3.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"transformers-are-rnns-fast-autoregressive","repo_url":"https://github.com/idiap/fast-transformers","is_official":1,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"transformers-are-rnns-fast-autoregressive","repo_url":"https://github.com/davidsvy/cosformer-pytorch","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"transformers-are-rnns-fast-autoregressive","repo_url":"https://github.com/glassroom/heinsen_attention","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"unanswered"}},{"paper_slug":"transformers-are-rnns-fast-autoregressive","repo_url":"https://github.com/kyle-gao/TF_Transformer","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":{"status":"ok","spdx":"Apache-2.0"}},{"paper_slug":"transformers-are-rnns-fast-autoregressive","repo_url":"https://github.com/lions-epfl/lion","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"transformers-are-rnns-fast-autoregressive","repo_url":"https://github.com/lucidrains/linear-attention-transformer","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"transformers-are-rnns-fast-autoregressive","repo_url":"https://github.com/EugenHotaj/pytorch-generative/blob/master/pytorch_generative/nn/attention.py","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"pytorch","reach":null},{"paper_slug":"transformers-are-rnns-fast-autoregressive","repo_url":"https://github.com/pwc-1/Paper-10/tree/main/transformer","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"mindspore","reach":null}],"tasks":[{"task_slug":"d4rl","task_name":"D4RL"},{"task_slug":"language-modelling","task_name":"Language Modelling"},{"task_slug":"offline-rl","task_name":"Offline RL"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/d4rl-on-d4rl","task":"D4RL","dataset":"D4RL","model":"Linear Transformer","rank_in_archive_order":7,"of":9,"metrics":{"Average Reward":"64.4"},"uses_additional_data":false},{"leaderboard":"/sota/language-modelling-on-wikitext-103","task":"Language Modelling","dataset":"WikiText-103","model":"Linear Attention 125M","rank_in_archive_order":60,"of":89,"metrics":{"Test perplexity":"25.6"},"uses_additional_data":false}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2006.16236","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2006.16236"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/EugenHotaj/pytorch-generative/blob/master/pytorch_generative/nn/attention.py","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/pwc-1/Paper-10/tree/main/transformer","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/lucidrains/linear-attention-transformer","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/idiap/fast-transformers","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/kyle-gao/TF_Transformer","reach":{"status":"ok","spdx":"Apache-2.0"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/davidsvy/cosformer-pytorch","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/lions-epfl/lion","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/glassroom/heinsen_attention","reach":{"status":"unanswered"}}],"summary":{"ran_draft_wrong":1,"ran_violates":2,"unverified":5},"by_repo_kind":{"listed":{"samples":5,"ran":0,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":3,"samples":[{"code_sha256_prefix":"dd3db53ae7ad1c85","entry":"always","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"dd3db53ae7ad1c85"}},{"code_sha256_prefix":"b5307f70349f5c27","entry":"default","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"b5307f70349f5c27"}},{"code_sha256_prefix":"aa5486a3650902d8","entry":"exists","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"aa5486a3650902d8"}},{"code_sha256_prefix":"1cc88f7d37dba081","entry":"elu","repo":"kyle-gao/TF_Transformer","repo_kind":"listed","path":"helperfunctions.py","file_url":"https://github.com/kyle-gao/TF_Transformer/blob/HEAD/helperfunctions.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"1cc88f7d37dba081"}},{"code_sha256_prefix":"0e73ca2dec803da6","entry":"encode","repo":"kyle-gao/TF_Transformer","repo_kind":"listed","path":"preprocess.py","file_url":"https://github.com/kyle-gao/TF_Transformer/blob/HEAD/preprocess.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"0e73ca2dec803da6"}},{"code_sha256_prefix":"d15b7f7e2a78f686","entry":"padding_mask","repo":"kyle-gao/TF_Transformer","repo_kind":"listed","path":"helperfunctions.py","file_url":"https://github.com/kyle-gao/TF_Transformer/blob/HEAD/helperfunctions.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"d15b7f7e2a78f686"}},{"code_sha256_prefix":"cfcb2cdb8e0339a1","entry":"positional_encoding","repo":"kyle-gao/TF_Transformer","repo_kind":"listed","path":"helperfunctions.py","file_url":"https://github.com/kyle-gao/TF_Transformer/blob/HEAD/helperfunctions.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"cfcb2cdb8e0339a1"}},{"code_sha256_prefix":"f8aeab29e343a2f7","entry":"tf_interleave_encode","repo":"kyle-gao/TF_Transformer","repo_kind":"listed","path":"preprocess.py","file_url":"https://github.com/kyle-gao/TF_Transformer/blob/HEAD/preprocess.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"f8aeab29e343a2f7"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}