LevAttention: Time, Space and Streaming Efficient Algorithm for Heavy Attentions
Ravindran Kannan, Chiranjib Bhattacharyya, Praneeth Kacham, David P. Woodruff
Abstract
A central problem related to transformers can be stated as follows: given two n × d matrices Q and K, and a non-negative function f , define the matrix A as follows: (1) apply the function f to each entry of the n × n matrix QK T , and then (2) normalize each of the row sums of A to be equal to 1. The matrix A can be computed in O(n 2 d) time assuming f can be applied to a number in constant time, but the quadratic dependence on n is prohibitive in applications where it corresponds to long context lengths. For a large class of functions f , we show how to find all the "large attention scores", i.e., entries of A which are at least a positive value ε, in time with linear dependence on n (i.e., n • poly(d/ε)) for a positive parameter ε > 0. Our class of functions include all functions f of the form f (x) = |x| p , as explored recently in transformer models. Using recently developed tools from randomized numerical linear algebra, we prove that for any K, there is a "universal set" U ⊂ [n] of size independent of n, such that for any Q and any row i, the large attention scores Ai,j in row i of A all have j ∈ U . We also find U in n • poly(d/ε) time. Notably, we (1) make no assumptions on the data, (2) our workspace does not grow with n, and (3) our algorithms can be computed in streaming and parallel settings. We call the attention mechanism that uses only the subset of keys in the universal set as LevAttention since our algorithm to identify the universal set U is based on leverage scores. We empirically show the benefits of our scheme for vision transformers, showing how to train new models that use our universal set while training as well, showing that our model is able to consistently select "important keys" during training. * Ravindran Kannan is listed as the first author. The remaining authors are ordered alphabetically. D. Woodruff also acknowledges Office of Naval Research award number N000142112647.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
1 top-tier paper has cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Random Feature Attention cites Sparse Sinkhorn Attention
- Random Feature Attention cites Reformer: The Efficient Transformer
- Sparse Sinkhorn Attention cites Reformer: The Efficient Transformer
- Sublinear Time Quantum Algorithm for Attention Approximation cites Random Feature Attention
- Sublinear Time Quantum Algorithm for Attention Approximation cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- Sublinear Time Quantum Algorithm for Attention Approximation cites Nyströmformer: A Nyström-based Algorithm for Approximating Self-Attention
- Sublinear Time Quantum Algorithm for Attention Approximation cites Reformer: The Efficient Transformer
- Nyströmformer: A Nyström-based Algorithm for Approximating Self-Attention cites Reformer: The Efficient Transformer
Cited by top-tier papers1
Builds on15
- An Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn et al.ICLR 2021 · 21,477 citations
- Reformer: The Efficient TransformerNikita Kitaev, Lukasz Kaiser, Anselm LevskayaICLR 2020 · 2,878 citations
- Nyströmformer: A Nyström-based Algorithm for Approximating Self-AttentionYunyang Xiong, Zhanpeng Zeng, Rudrasis Chakraborty, Mingxing Tan et al.AAAI 2021 · 675 citations
- Random Feature AttentionHao Peng, Nikolaos Pappas, Dani Yogatama, Roy Schwartz et al.ICLR 2021 · 425 citations
- Sparse Sinkhorn AttentionYi Tay, Dara Bahri, Liu Yang, Donald Metzler et al.ICML 2020 · 391 citations
Related papers
- Fast Attention Requires Bounded EntriesJosh Alman, Zhao SongNeurIPS 2023 · 115 citations
- H-Transformer-1D: Fast One-Dimensional Hierarchical Attention for SequencesZhenhai Zhu, Radu SoricutACL 2021
- Subquadratic Algorithms and Hardness for Attention with Any TemperatureShreya Gupta, Boyang Huang, Barna Saha, Yinzhan Xu et al.ICLR 2026 · 5 citations
- How to Capture Higher-order Correlations? Generalizing Matrix Softmax Attention to Kronecker ComputationJosh Alman, Zhao SongICLR 2024 · 53 citations
- Improved Algorithms for Kernel Matrix-Vector Multiplication Under Sparsity AssumptionsPiotr Indyk, Michael Kapralov, Kshiteej Sheth, Tal WagnerICLR 2025
