Self-attention Does Not Need O(n2) Memory
Not on the map. Why?
Abstract (arXiv)
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(log n) memory. This is in contrast with the frequently stated belief that self-attention requires O(n2) memory. While the time complexity is still O(n2), 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.
Key facts. Cited by 152 papers in the map (data through 7 Oct 2026). Builds on 15 of its 22 references that are in the map. First posted on arXiv 10 Dec 2021.
Builds on
15 of 22 references.
References · 15
- 2017Attention Is All You Needcited by 59,932
- 2018BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingcited by 40,204
- 2014Neural Machine Translation by Jointly Learning to Align and Translatecited by 4,530
- 2020Big Bird: Transformers for Longer Sequencescited by 1,673
- 2020Reformer: The Efficient Transformercited by 1,658
- 2020Rethinking Attention with Performerscited by 1,584
- 2019Generating Long Sequences with Sparse Transformerscited by 1,523
- 2020Linformer: Self-Attention with Linear Complexitycited by 1,462
- 2016Training Deep Nets with Sublinear Memory Costcited by 825
- 2020Long Range Arena: A Benchmark for Efficient Transformerscited by 696
- 2020Efficient Content-Based Sparse Attention with Routing Transformerscited by 469
- 2018Efficient Attention: Attention with Linear Complexitiescited by 366
3 more
- 2019Blockwise Self-Attention for Long Document Understandingcited by 158
- 2021Luna: Linear Unified Nested Attentioncited by 96
- 2021Combiner: Full Attention Transformer with Sparse Computation Costcited by 64
Built on by
Citing papers per year: 2022: 6; 2023: 41; 2024: 48; 2025: 33; 2026: 24.
152 papers.
Sort:
By area:
- 2023GPT-4 Technical Reportcited by 18,132
- 2023LLaMA: Open and Efficient Foundation Language Modelscited by 13,958
- 2022FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awarenesscited by 3,611
- 2023FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioningcited by 2,551
- 2023RWKV: Reinventing RNNs for the Transformer Eracited by 814
- 2023Baichuan 2: Open Large-scale Language Modelscited by 664
- 2023A Comprehensive Overview of Large Language Modelscited by 639
- 2023LightGlue: Local Feature Matching at Light Speedcited by 583
- 2023The Falcon Series of Open Language Modelscited by 526
- 2024Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-Servecited by 507
- 2022Hungry Hungry Hippos: Towards Language Modeling with State Space Modelscited by 495
- 2023Ring Attention with Blockwise Transformers for Near-Infinite Contextcited by 448
38 more
- 2024mGTE: Generalized Long-Context Text Representation and Reranking Models for Multilingual Text Retrievalcited by 233
- 2023Patch n' Pack: NaViT, a Vision Transformer for any Aspect Ratio and Resolutioncited by 226
- 2024World Model on Million-Length Video And Language With Blockwise RingAttentioncited by 196
- 2023SARATHI: Efficient LLM Inference by Piggybacking Decodes with Chunked Prefillscited by 187
- 2024Actions Speak Louder than Words: Trillion-Parameter Sequential Transducers for Generative Recommendationscited by 184
- 2024Flex Attention: A Programming Model for Generating Optimized Attention Kernelscited by 180
- 2024From Decoding to Meta-Generation: Inference-time Algorithms for Large Language Modelscited by 136
- 2023ONE-PEACE: Exploring One General Representation Model Toward Unlimited Modalitiescited by 117
- 2023Towards Efficient Generative Large Language Model Serving: A Survey from Algorithms to Systemscited by 101
- 2023Advancing Transformer Architecture in Long-Context Large Language Models: A Comprehensive Surveycited by 71
- 2024Hydragen: High-Throughput LLM Inference with Shared Prefixescited by 71
- 2024Tracking Meets LoRA: Faster Training, Larger Model, Stronger Performancecited by 70
- 2022General-purpose, long-context autoregressive modeling with Perceiver ARcited by 60
- 2023SiLK -- Simple Learned Keypointscited by 54
- 2023Striped Attention: Faster Ring Attention for Causal Transformerscited by 52
- 2023Geometric Algebra Transformercited by 46
- 2024Post-Training Sparse Attention with Double Sparsitycited by 45
- 2023Boosting Latent Diffusion with Flow Matchingcited by 44
- 2023Replacing softmax with ReLU in Vision Transformerscited by 43
- 2024CATS: Contextually-Aware Thresholding for Sparsity in Large Language Modelscited by 41
- 2024Cut Your Losses in Large-Vocabulary Language Modelscited by 35
- 2025Scaling Laws for Forgetting during Finetuning with Pretraining Data Injectioncited by 35
- 2023MosaicBERT: A Bidirectional Encoder Optimized for Fast Pretrainingcited by 33
- 2025PaTH Attention: Position Encoding via Accumulating Householder Transformationscited by 32
- 2022GACT: Activation Compressed Training for Generic Network Architecturescited by 31
- 2024BatchLLM: Optimizing Large Batched LLM Inference with Global Prefix Sharing and Throughput-oriented Token Batchingcited by 31
- 2025ConTextTab: A Semantics-Aware Tabular In-Context Learnercited by 31
- 2023Scalable, Detailed and Mask-Free Universal Photometric Stereocited by 30
- 2023DISTFLASHATTN: Distributed Memory-efficient Attention for Long-context LLMs Trainingcited by 28
- 2023On Efficient Training of Large-Scale Deep Learning Models: A Literature Reviewcited by 26
- 2023LORD: Low Rank Decomposition Of Monolingual Code LLMs For One-Shot Compressioncited by 26
- 2023Transformer-VQ: Linear-Time Transformers via Vector Quantizationcited by 26
- 2023Efficient Attention via Control Variatescited by 23
- 2023Unsupervised 3D out-of-distribution detection with latent diffusion modelscited by 22
- 2023FABRIC: Personalizing Diffusion Models with Iterative Feedbackcited by 19
- 2025HMAR: Efficient Hierarchical Masked Auto-Regressive Image Generationcited by 19
- 2024FlashMask: Efficient and Rich Mask Extension of FlashAttentioncited by 18
- 2024Token Cropr: Faster ViTs for Quite a Few Taskscited by 18
50 most cited of 152 All 152 (JSON)
- 2026Structure-Guided Masked Autoencoders for Ultra-High Resolution Scientific Image Understanding25 Sep 2026
- 2026FlashBoB: I/O-Efficient Exact Backward-over-Backward for Softmax Attention21 Sep 2026
- 2026GaLe: memory-efficient Global Approximate and Local Exact features2 Sep 2026
- 2026Prefix Sliding for efficient test-time scaling26 Aug 2026
- 2026EXAONE Tabular 1.0 : Technical Report26 Aug 2026
- 2026FLARE++: Low-rank attention with dynamic attention routing12 Aug 2026
- 2026LongStraw: Long-Context RL Beyond 2M Tokens under a Fixed GPU Budget16 Jul 2026
- 2026Design-CP: Context Parallelism for Design of Protein Nanoparticles3 Jul 2026
- 2026Prefilling-dLLM: Predictive Prefilling for Long-Context Inference in Diffusion Language Models9 Jun 2026
- 2026Neural Field Tokenizations with Hierarchy and Spatial Locality Priors6 Jun 2026
- 2026Context Memorization for Efficient Long Context Generation18 May 2026
- 2026ELSA: Exact Linear-Scan Attention for Fast and Memory-Light Vision Transformers26 Apr 2026
38 more
- 2026The Recurrent Transformer: Greater Effective Depth and Efficient Decoding23 Apr 2026
- 2026Stream-CQSA: Exact Out-of-Memory Recovery for Attention22 Apr 2026
- 2026Sessa: Selective State Space Attention20 Apr 2026
- 2026HieraSparse: Hierarchical Semi-Structured Sparse KV Attention18 Apr 2026
- 2026Dispatch-Aware Ragged Attention for Pruned Vision Transformers16 Apr 2026
- 2026Cactus: Accelerating Auto-Regressive Decoding with Constrained Acceptance Speculative Sampling5 Apr 2026
- 2026Drift-Resilient Temporal Priors for Visual Tracking3 Apr 2026
- 2026Think While Watching: Online Streaming Segment-Level Memory for Multi-Turn Video Reasoning in Multimodal Large Language Models12 Mar 2026
- 2026LaCy: What Small Language Models Can and Should Learn is Not Just a Question of Loss12 Feb 2026
- 2026NEST: Nested Event Stream Transformer for Sequences of Multisets31 Jan 2026
- 2026Spelling Bee Embeddings for Language Modeling25 Jan 2026
- 2026ReHyAt: Recurrent Hybrid Attention for Video Diffusion Transformers7 Jan 2026
- 2025Dialect Identification Using Resource-Efficient Fine-Tuning Approaches30 Nov 2025
- 2025GSPN-2: Efficient Parallel Sequence Modeling28 Nov 2025
- 2025Generalizable Insights for Graph Transformers in Theory and Practice11 Nov 2025
- 2025Context Engineering 2.0: The Context of Context Engineering30 Oct 2025
- 2025Vectorized FlashAttention with Low-cost Exponential Computation in RISC-V Vector Processors8 Oct 2025
- 2025KVComm: Enabling Efficient LLM Communication through Selective KV Sharing2 Oct 2025
- 2025TASP: Topology-aware Sequence Parallelism30 Sep 2025
- 2025Attention Surgery: An Efficient Recipe to Linearize Your Video Diffusion Transformer29 Sep 2025
- 2025Fast weight programming and linear transformers: from machine learning to neurobiology11 Aug 2025
- 2025Efficient Speculative Decoding for Llama at Scale: Challenges and Solutions11 Aug 2025
- 2025Modality Agnostic Efficient Long Range Encoder25 Jul 2025
- 2025Custom Algorithm-based Fault Tolerance for Attention Layers in Transformers22 Jul 2025
- 2025Local Representative Token Guided Merging for Text-to-Image Generation17 Jul 2025
- 2025Compute Requirements for Algorithmic Innovation in Frontier AI Models13 Jul 2025
- 2025Inter2Former: Dynamic Hybrid Attention for Efficient High-Precision Interactive13 Jul 2025
- 2025ZeCO: Zero Communication Overhead Sequence Parallelism for Linear Attention1 Jul 2025
- 2025ConTextTab: A Semantics-Aware Tabular In-Context Learner12 Jun 2025
- 2025Scalable Spatiotemporal Inference with Biased Scan Attention Transformer Neural Processes10 Jun 2025
- 2025HMAR: Efficient Hierarchical Masked Auto-Regressive Image Generation4 Jun 2025
- 2025Category-Agnostic Neural Object Rigging26 May 2025
- 2025PaTH Attention: Position Encoding via Accumulating Householder Transformations22 May 2025
- 2025Low-Cost FlashAttention with Fused Exponential and Multiplication Hardware Operators20 May 2025
- 2025FLASH-D: FlashAttention with Hidden Softmax Division20 May 2025
- 2025FlashBias: Fast Computation of Attention with Bias17 May 2025
- 2025Generalized Neighborhood Attention: Multi-dimensional Sparse Attention at the Speed of Light23 Apr 2025
- 2025MOM: Memory-Efficient Offloaded Mini-Sequence Inference for Long Context Language Models16 Apr 2025
50 newest of 152 All 152 (JSON)
- 2023Boosting Latent Diffusion with Flow Matchingcited by 44
- 2023Unsupervised 3D out-of-distribution detection with latent diffusion modelscited by 22
- 2023FABRIC: Personalizing Diffusion Models with Iterative Feedbackcited by 19
- 2025HMAR: Efficient Hierarchical Masked Auto-Regressive Image Generationcited by 19
- 2024AsymRnR: Video Diffusion Transformers Acceleration with Asymmetric Reduction and Restorationcited by 15
- 2025Attention Surgery: An Efficient Recipe to Linearize Your Video Diffusion Transformercited by 13
- 2023DiffSynth: Latent In-Iteration Deflickering for Realistic Video Synthesiscited by 11
- 2023The Big Data Myth: Using Diffusion Models for Dataset Generation to Train Deep Detection Modelscited by 7
- 2026ReHyAt: Recurrent Hybrid Attention for Video Diffusion Transformerscited by 6
- 2025MedLoRD: A Medical Low-Resource Diffusion Model for High-Resolution 3D CT Image Synthesiscited by 3
- 2026Prefilling-dLLM: Predictive Prefilling for Long-Context Inference in Diffusion Language Modelscited by 2
- 2025Local Representative Token Guided Merging for Text-to-Image Generationcited by 1
12 most cited of 13 All 13 (JSON)
- 2026Prefilling-dLLM: Predictive Prefilling for Long-Context Inference in Diffusion Language Models9 Jun 2026
- 2026ReHyAt: Recurrent Hybrid Attention for Video Diffusion Transformers7 Jan 2026
- 2025Attention Surgery: An Efficient Recipe to Linearize Your Video Diffusion Transformer29 Sep 2025
- 2025Local Representative Token Guided Merging for Text-to-Image Generation17 Jul 2025
- 2025HMAR: Efficient Hierarchical Masked Auto-Regressive Image Generation4 Jun 2025
- 2025MedLoRD: A Medical Low-Resource Diffusion Model for High-Resolution 3D CT Image Synthesis17 Mar 2025
- 2024AsymRnR: Video Diffusion Transformers Acceleration with Asymmetric Reduction and Restoration16 Dec 2024
- 2024Inconsistencies In Consistency Models: Better ODE Solving Does Not Imply Better Samples13 Nov 2024
- 2023Boosting Latent Diffusion with Flow Matching12 Dec 2023
- 2023DiffSynth: Latent In-Iteration Deflickering for Realistic Video Synthesis7 Aug 2023
- 2023FABRIC: Personalizing Diffusion Models with Iterative Feedback19 Jul 2023
- 2023Unsupervised 3D out-of-distribution detection with latent diffusion models7 Jul 2023
12 newest of 13 All 13 (JSON)
- 2024Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-Servecited by 507
- 2023SARATHI: Efficient LLM Inference by Piggybacking Decodes with Chunked Prefillscited by 187
- 2023Towards Efficient Generative Large Language Model Serving: A Survey from Algorithms to Systemscited by 101
- 2024Token Cropr: Faster ViTs for Quite a Few Taskscited by 18
- 2025Efficient Speculative Decoding for Llama at Scale: Challenges and Solutionscited by 7
- 2026Cactus: Accelerating Auto-Regressive Decoding with Constrained Acceptance Speculative Samplingcited by 4
- 2024The CAP Principle for LLM Serving: A Survey of Long-Context Large Language Model Servingcited by 3
- 2024Optimized Speculative Sampling for GPU Hardware Acceleratorscited by 2
- 2026Dispatch-Aware Ragged Attention for Pruned Vision Transformerscited by 1
- 2025MOM: Memory-Efficient Offloaded Mini-Sequence Inference for Long Context Language Modelscited by 0
- 2025Modality Agnostic Efficient Long Range Encodercited by 0
- 2026HieraSparse: Hierarchical Semi-Structured Sparse KV Attentioncited by 0
- 2026HieraSparse: Hierarchical Semi-Structured Sparse KV Attention18 Apr 2026
- 2026Dispatch-Aware Ragged Attention for Pruned Vision Transformers16 Apr 2026
- 2026Cactus: Accelerating Auto-Regressive Decoding with Constrained Acceptance Speculative Sampling5 Apr 2026
- 2025Efficient Speculative Decoding for Llama at Scale: Challenges and Solutions11 Aug 2025
- 2025Modality Agnostic Efficient Long Range Encoder25 Jul 2025
- 2025MOM: Memory-Efficient Offloaded Mini-Sequence Inference for Long Context Language Models16 Apr 2025
- 2024Token Cropr: Faster ViTs for Quite a Few Tasks1 Dec 2024
- 2024Optimized Speculative Sampling for GPU Hardware Accelerators16 Jun 2024
- 2024The CAP Principle for LLM Serving: A Survey of Long-Context Large Language Model Serving18 May 2024
- 2024Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-Serve4 Mar 2024
- 2023Towards Efficient Generative Large Language Model Serving: A Survey from Algorithms to Systems23 Dec 2023
- 2023SARATHI: Efficient LLM Inference by Piggybacking Decodes with Chunked Prefills31 Aug 2023
- 2023LLaMA: Open and Efficient Foundation Language Modelscited by 13,958
- 2023TextGenSHAP: Scalable Post-hoc Explanations in Text Generation with Long Documentscited by 17
- 2026Think While Watching: Online Streaming Segment-Level Memory for Multi-Turn Video Reasoning in Multimodal Large Language Modelscited by 7
- 2026Prefix Sliding for efficient test-time scalingcited by 2
- 2026Prefix Sliding for efficient test-time scaling26 Aug 2026
- 2026Think While Watching: Online Streaming Segment-Level Memory for Multi-Turn Video Reasoning in Multimodal Large Language Models12 Mar 2026
- 2023TextGenSHAP: Scalable Post-hoc Explanations in Text Generation with Long Documents3 Dec 2023
- 2023LLaMA: Open and Efficient Foundation Language Models27 Feb 2023
- 2026Sessa: Selective State Space Attentioncited by 0
- 2026Sessa: Selective State Space Attention20 Apr 2026
- 2023GPT-4 Technical Reportcited by 18,132
- 2022FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awarenesscited by 3,611
- 2023FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioningcited by 2,551
- 2023RWKV: Reinventing RNNs for the Transformer Eracited by 814
- 2023Baichuan 2: Open Large-scale Language Modelscited by 664
- 2023A Comprehensive Overview of Large Language Modelscited by 639
- 2023LightGlue: Local Feature Matching at Light Speedcited by 583
- 2023The Falcon Series of Open Language Modelscited by 526
- 2022Hungry Hungry Hippos: Towards Language Modeling with State Space Modelscited by 495
- 2023Ring Attention with Blockwise Transformers for Near-Infinite Contextcited by 448
- 2024mGTE: Generalized Long-Context Text Representation and Reranking Models for Multilingual Text Retrievalcited by 233
- 2023Patch n' Pack: NaViT, a Vision Transformer for any Aspect Ratio and Resolutioncited by 226
12 most cited of 121 All 121 (JSON)
- 2026Structure-Guided Masked Autoencoders for Ultra-High Resolution Scientific Image Understanding25 Sep 2026
- 2026FlashBoB: I/O-Efficient Exact Backward-over-Backward for Softmax Attention21 Sep 2026
- 2026GaLe: memory-efficient Global Approximate and Local Exact features2 Sep 2026
- 2026EXAONE Tabular 1.0 : Technical Report26 Aug 2026
- 2026FLARE++: Low-rank attention with dynamic attention routing12 Aug 2026
- 2026LongStraw: Long-Context RL Beyond 2M Tokens under a Fixed GPU Budget16 Jul 2026
- 2026Design-CP: Context Parallelism for Design of Protein Nanoparticles3 Jul 2026
- 2026Neural Field Tokenizations with Hierarchy and Spatial Locality Priors6 Jun 2026
- 2026Context Memorization for Efficient Long Context Generation18 May 2026
- 2026ELSA: Exact Linear-Scan Attention for Fast and Memory-Light Vision Transformers26 Apr 2026
- 2026The Recurrent Transformer: Greater Effective Depth and Efficient Decoding23 Apr 2026
- 2026Stream-CQSA: Exact Out-of-Memory Recovery for Attention22 Apr 2026
12 newest of 121 All 121 (JSON)