Papers › Self-attention Does Not Need O(n²) Memory
Self-attention Does Not Need O(n²) Memory
Markus N. Rabe, Charles Staats
We present a very simple algorithm for attention that requires O(1) memory with respect to sequence length and an extension to self-attention that requires O(logn) memory. This is in contrast with the frequently stated belief that self-attention requires O(n²) memory. While the time complexity is still O(n²), device memory rather than compute capability is often the limiting factor on modern accelerators. Thus, reducing the memory requirements of attention allows processing of longer sequences than might otherwise be feasible. We provide a practical implementation for accelerators that requires O(√(n)) memory, is numerically stable, and is within a few percent of the runtime of the standard implementation of attention. We also demonstrate how to differentiate the function while remaining memory-efficient. For sequence length 16384, the memory overhead of self-attention is reduced by 59X for inference and by 32X for differentiation.
In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.
For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2112.05682")
Code
Syntology Ran 17 of 36 code samples harvested from 8 repositories linked to this paper; 19 have no recorded run. Of those that ran: 1 ran · honoured contract; 6 ran · violated contract; 7 ran · our draft was wrong; 2 ran · fixture could not drive it; 1 ran with no contract checked.
By repository: named in the paper: 7 samples from 1 repository, 5 ran; community (archive-listed): 28 samples from 7 repositories, 11 ran; 1 identical to code first harvested elsewhere. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.
17 repositories listed; official and paper-mentioned ones first.
Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.
Code Syntology ran Syntology
36 samples harvested; 17 ran; 1 honoured the contract we drafted; 19 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.
Licence: 2 of the 36 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.
Harvested from 8 repositories linked to this paper, official or community; each sample names its own and says which. Some samples are identical code Syntology first harvested from another repository; for those, this paper's copy is not located and its licence is not recorded. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.
Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.
Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: 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. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.
60fff7c3c400d7ff · report
c16aee9490eb8729 · report
aa5486a3650902d8 · report
3eb58dae620046d3 · report
3b65d5d77510c964 · report
640155bcba1f2f92 · report
1f7d4befc2e41402 · report
68b3637c9b987a61 · report
915fbeb88e13d4a3 · report
6b1a95182607abd6 · report
592b3c1a88f93d7c · report
42a46570620cd9fa · report
bae18947b56f2be1 · report
9b3c1cb391672ccb · report
c3ee9d07c900dd55 · report
f2fe51a4a5646c6f · report
0bf414a2b44babe6 · report
076c252c52cbb161 · report
36090e75c451149f · report
46c06fec5aedf4a4 · report
cb00b798f297e5f3 · report
80dde39da1ba3708 · report
bdb24836d5607016 · report
1fe910f8046380d4 · report
c17fb3de0d47f94a · report
fa3bb9e402f7460c · report
f545ae5663fedf88 · report
c5824da57107fe8c · report
2613e53cccc8a4b4 · report
8dacf011c6f243dc · report
a3698e4aaee89be7 · report
344dff4791fd1381 · report
012fae59ee4131ba · report
dc21db7cf25bfe72 · report
44fab12a908ab057 · report
856d86b39c6005b4 · report
Results from the paper archive 2025-07-28
No leaderboard rows for this paper in the archive.
Methods
Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections