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. † Part of this work done while D. Woodruff was at Google Research and at the Simons Institute for the Theory of Computing. D. Woodruff also acknowledges Office of Naval Research award number N000142112647.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 17bf326b-1a32-4dda-a089-2b37f6a6bb4fCited by top-tier papers1
Ask how each one uses itBuilds 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
