kNN Attention Demystified: A Theoretical Exploration for Scalable Transformers
Not on the map. Why?
Abstract (arXiv)
Despite their power, Transformers face challenges with long sequences due to the quadratic complexity of self-attention. To address this limitation, methods like k-Nearest-Neighbor (kNN) attention have been introduced [Roy, Saffar, Vaswani, Grangier, 2021] enabling each token to attend to only its k closest tokens. While kNN attention has shown empirical success in making Transformers more efficient, its exact approximation guarantees have not been theoretically analyzed. In this work, we establish a theoretical framework for kNN attention, reformulating self-attention as expectations over softmax distributions and leveraging lazy Gumbel sampling [Mussmann, Levy, Ermon, 2017] with kNN indices for efficient approximation. Building on this framework, we also propose novel sub-quadratic algorithms that approximate self-attention gradients by leveraging efficient sampling techniques, such as Markov Chain-based estimation. Finally, we demonstrate the practical effectiveness of these algorithms through empirical experiments, showcasing their benefits in both training and inference.
Key facts. Cited by 1 paper in the map (data through 14 Oct 2026). Builds on 30 of its 47 references that are in the map. First posted on arXiv 6 Nov 2024.
Builds on
30 of 47 references.
References · 30
- 2017Attention Is All You Needcited by 60,361
- 2020An Image is Worth 16x16 Words: Transformers for Image Recognition at Scalecited by 30,186
- 2022FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awarenesscited by 3,673
- 2020Longformer: The Long-Document Transformercited by 3,413
- 2020Transformers are RNNs: Fast Autoregressive Transformers with Linear Attentioncited by 2,022
- 2020Reformer: The Efficient Transformercited by 1,668
- 2020Rethinking Attention with Performerscited by 1,601
- 2019Generating Long Sequences with Sparse Transformerscited by 1,546
- 2020Linformer: Self-Attention with Linear Complexitycited by 1,474
- 2020Long Range Arena: A Benchmark for Efficient Transformerscited by 700
- 2019Enhancing the Locality and Breaking the Memory Bottleneck of Transformer on Time Series Forecastingcited by 607
- 2022Transformers in Time Series: A Surveycited by 497
18 more
- 2022Memorizing Transformerscited by 226
- 2021BookSum: A Collection of Datasets for Long-form Narrative Summarizationcited by 184
- 2019Blockwise Self-Attention for Long Document Understandingcited by 159
- 2019Adaptively Sparse Transformerscited by 155
- 2022On The Computational Complexity of Self-Attentioncited by 139
- 2023Unlimiformer: Long-Range Transformers with Unlimited Length Inputcited by 128
- 2014Asymmetric LSH (ALSH) for Sublinear Time Maximum Inner Product Search (MIPS)cited by 109
- 2023Fast Attention Requires Bounded Entriescited by 102
- 2019Star-Transformercited by 94
- 2023HyperAttention: Long-context Attention in Near-Linear Timecited by 85
- 2020The De-democratization of AI: Deep Learning and the Compute Divide in Artificial Intelligence Researchcited by 67
- 2021Memory-efficient Transformers via Top-k Attentioncited by 60
- 2023KDEformer: Accelerating Transformers via Kernel Density Estimationcited by 58
- 2021Is Sparse Attention more Interpretable?cited by 31
- 2024The Fine-Grained Complexity of Gradient Computation for Training Large Language Modelscited by 30
- 2020The Cascade Transformer: an Application for Efficient Answer Sentence Selectioncited by 20
- 2017Fast Amortized Inference and Learning in Log-linear Models with Randomly Perturbed Nearest Neighbor Searchcited by 8
- 2024The I/O Complexity of Attention, or How Optimal is Flash Attention?cited by 6
Built on by
Citing papers per year: 2026: 1.
1 paper.