Fast Attention Requires Bounded Entries

In modern machine learning, inner product attention computation is a fundamental task for training large language models such as Transformer, GPT-1, BERT, GPT-2, GPT-3 and ChatGPT. Formally, in this problem, one is given as input three matrices $Q, K, V \in [-B,B]^{n \times d}$, and the goal is to construct the matrix $\mathrm{Att}(Q,K,V) := \mathrm{diag}(A {\bf 1}_n)^{-1} A V \in \mathbb{R}^{n \times d}$, where $A = \exp(QK^\top/d)$ is the `attention matrix', and $\exp$ is applied entry-wise. Straightforward methods for this problem explicitly compute the $n \times n$ attention matrix $A$, and hence require time $Ω(n^2)$ even when $d = n^{o(1)}$ is small. In this paper, we investigate whether faster algorithms are possible by implicitly making use of the matrix $A$. We present two results, showing that there is a sharp transition at $B = Θ(\sqrt{\log n})$. $\bullet$ If $d = O(\log n)$ and $B = o(\sqrt{\log n})$, there is an $n^{1+o(1)}$ time algorithm to approximate $\mathrm{Att}(Q,K,V)$ up to $1/\mathrm{poly}(n)$ additive error. $\bullet$ If $d = O(\log n)$ and $B = Θ(\sqrt{\log n})$, assuming the Strong Exponential Time Hypothesis from fine-grained complexity theory, it is impossible to approximate $\mathrm{Att}(Q,K,V)$ up to $1/\mathrm{poly}(n)$ additive error in truly subquadratic time $n^{2 - Ω(1)}$. This gives a theoretical explanation for the phenomenon observed in practice that attention computation is much more efficient when the input matrices have smaller entries.

Paper

References (44)

Scroll for more · 32 remaining

Similar papers

Peer review

Reviewer LkJK6/10 · confidence 3/52023-07-02

Summary

This paper shows that whether or not there exists a fast algorithm for approximately computing the attention matrix ($A \in \mathbb{R}^{n \times d}$, where $d = O(\log n)$ depends on the bound of the entry value $B$ 1. Particularly, the authors show that when $B = o(\sqrt{\log n)}$, their proposed algorithm can compute the attention matrix within $1/\text{poly}(n)$ error in time $n^{1+o(1)}$. 2. Assuming the Strong Exponential Time Hypothesis (SETH) and the fine-grained complexity conjecture is valid, they show that there is no $O(N^{2-q})$ time algorithm that guarantees $1/\text{poly}(n)$ approximation error.

Strengths

+ The results are interesting and correct + An improved hardness result is a good contribution + The observation that the existence of a sublinear algorithm depends on the entry value is interesting.

Weaknesses

The proposed algorithm is a bit incremental, both in terms of the proposed method, and the techniques to establish these results. Minor typo: p5: In the proof of Corollary 2.2, it seems like $\max$ operation is missing in the formula $g = \Theta(...)$.

Questions

+ Although the paper provides an explicit way of the matrix construction $U_1$ and $U_2$, the reviewer is wondering how complex is the matrix construction in practice.

Rating

6: Weak Accept: Technically solid, moderate-to-high impact paper, with no major concerns with respect to evaluation, resources, reproducibility, ethical considerations.

Confidence

3: You are fairly confident in your assessment. It is possible that you did not understand some parts of the submission or that you are unfamiliar with some pieces of related work. Math/other details were not carefully checked.

Soundness

2 fair

Presentation

3 good

Contribution

2 fair

Limitations

+ It would be nice if there were simulation results that demonstrate the practicality for some benchmark datasets on some target tasks.

Reviewer ZPux7/10 · confidence 4/52023-07-03

Summary

The paper is a purely theoretical paper discussing improving the computational time required to solve the attention computation problem which is known to be quadratic in time. The idea hinges upon the use of the boundness of the entries of the matrices involved in such a problem. The authors discuss mainly two cases, where the entries are bounded by a polylogarithmic term in the number of tokens which then the attention computation problem can be solved in time almost linear in the number of tokens. Otherwise, the authors prove via the "Strong Exponential Time Hypothesis" from fine-grained complexity theory that the running time is no better than quadratic in the number of tokens.

Strengths

1) The paper is well-written and easy to follow. 2) The paper proves the existence of almost linear time algorithms for the attention computation problem, as it depends on the boundness of the entries of the matrices. 3) The paper also shows that in case the entires of the involved matrices in the attention computation problem are "not bounded", then the quadratic time associated with the attention computation problem can not be improved.

Weaknesses

The only weakness is the lack of practical evaluation. Although the paper sets a theoretical justification for, e.g., the use of quantization or low-degree polynomial approximation of the attention computation problem, it would be great to observe the quality of the proposed algorithm on the quality of transformer-like models which practices the attention computation problem.

Questions

1) On page 14 of the appendix, did you mean to put n instead of D at the top of the summation symbol (see equation 2)? 2) Also on the same page, did you mean to write $\tilde{D}_{i, i}$ instead of $\tilde{D}_i$? 3) Shouldnt be the $B$ in the denominator of the equation stated at Lemma 3.4 be $B^2$?

Rating

7: Accept: Technically solid paper, with high impact on at least one sub-area, or moderate-to-high impact on more than one areas, with good-to-excellent evaluation, resources, reproducibility, and no unaddressed ethical considerations.

Confidence

4: You are confident in your assessment, but not absolutely certain. It is unlikely, but not impossible, that you did not understand some parts of the submission or that you are unfamiliar with some pieces of related work.

Soundness

3 good

Presentation

3 good

Contribution

4 excellent

Limitations

The authors adequately addressed the limitations of their work.

Reviewer Ze7L3/10 · confidence 4/52023-07-07

Summary

In this work, the author studied the problem of how to efficiently compute or approximate the attention matrix. The major contribution can be summarized as: 1. they found for the case when $d = O(\log n)$ and entries of the input matrices are uniformly bounded by $o(\sqrt{\log n})$, then an algorithm that approximates the attention matrix can be constructed with sub-quadratic complexity, the key idea of the approximation is based on a polynomial approximation of the $e^x$ that was introduced by another work [AA22]. 2. when $d = O(\log n)$, and the entries of the input matrices are of the order $\Theta(\sqrt{\log n})$, then under the Strong Exponential Time Hypothesis, it is impossible to approximate the attention matrix with small error and sub-quadratic complexity.

Strengths

1. I think in this work, the author did a good job explain the basic intuitions and ideas behind their approach. Especially, breaking down the proof steps into smaller parts improved the readability of this work. 2. On the other hand, by elaborating the related works and contributions, the reviewer can have a better understanding of the contribution of this work.

Weaknesses

There are several weakness of this work: 1. The major contribution of this work is not emphasized enough or minor. For example, the technical tools used in this work are developed by previous works to tackle similar problems. As a theory paper, I think the author at least needs to address what technical contribution is made in this work. To me, it seems that the major results are straightforward applications of some closely related recent works. 2. The lack of simulation results is another weakness. As the author is trying to address some practical/computational aspects of the problem, experimental results are essential to validate the theory and claims. 3. Some of the claims in the theorem are ambiguous. For instance, in theorem 4.6, there are many constants $C_a, C_{\beta}, C, q$ used. What are those constants? Numerical constants? What are the relationships between them? Statements like this is not rigorous at all for theory papers.

Questions

Please see some questions I mentioned in the weakness section. Aside from that, can the author explain the claim "This gives a theoretical explanation for the phenomenon observed in practice that attention computation is much more efficient when the input matrices have smaller entries". Why the results in this work explain this in practice?

Rating

3: Reject: For instance, a paper with technical flaws, weak evaluation, inadequate reproducibility and incompletely addressed ethical considerations.

Confidence

4: You are confident in your assessment, but not absolutely certain. It is unlikely, but not impossible, that you did not understand some parts of the submission or that you are unfamiliar with some pieces of related work.

Soundness

2 fair

Presentation

3 good

Contribution

2 fair

Limitations

Please see the weakness section.

Reviewer ioBT6/10 · confidence 2/52023-07-26

Summary

The attention mechanism, whose runtime complexity is approximately quadratic in the sequence length $n$, is the main bottleneck to LLM inference. It is thus quite reasonable to study whether this can be *approximated* with sufficient accuracy in subquadratic time. In particular, for this paper the authors define and study the problem of approximate attention computation (AAttC), wherein one seeks a result that is accurate within a pre-specified entrywise error tolerance $\epsilon_a$. Under what I think are reasonable assumptions, the authors find that whether AAttC can run in subquadratic time hinges on the bound $B$ on the magnitudes of the entries of $Q$/$K$/$V$. This is slightly surprising and, in my opinion, a neat story for the paper. This conclusion consists in two results: 1. Theorem 3.8: an algorithm that computes AAttC in near-linear time provided that $B = o(\sqrt{\log n})$. The high-level idea is - Approximate the $\exp$ in $\exp(QK^T/d)$ with a polynomial $P$ (Lemma 2.1 from [AA22]). - Compute a low-rank decomposition $U_1 U_2^T = P(QK^T/d)$ directly in linear time based on knowledge of $P$ and the entries of $Q$ and $K$ (Lemma 3.2). These lemmas are the main workhorses of Theorem 3.8, but effort is also made stitching everything together. The crucial thread is that $B^2$ determines the degree of $P$, which in turn determines the rank of the decomposition $U_1 U_2^T$. $B$ thus needs to grow slowly in $n$ to make the algorithm subquadratic. 2. Theorem 4.6, which shows that if $B = \Theta(\log n)$, there is no subquadratic-time algorithm for AAttC (assuming the strong exponential time hypothesis, SETH). This result is based on a reduction of approximate nearest neighbor search to AAttC.

Strengths

- Although past work has produced some closely related results (ZHDK23, KWH23), the authors' focus on $B$, the entrywise bound, is original and insightful. Furthermore, the proof techniques in this paper bring up interesting connections to the KDE literature which may be interesting for the community. - They provide a near-linear time attention algorithm based on $B = o(\sqrt{\log n})$, and show that the rate at which $B$ scales cannot be improved upon. In some sense their work is a complete description of the problem, conditional on their (reasonable) assumptions on how other quantities scale with $n$ ($d = O(\log n), \epsilon_a = 1/\text{poly}(n)$). This is quite satisfying. - For a theoretical paper, this is well-written and easy to understand. The authors do a great job of motivating, roadmapping, and explaining their work. - This work offers a key insight about an important problem.

Weaknesses

This is a pair of complexity results. It is not clear to me how the insights provided here can be operationalized to improve AAttC in a practical setting. (The authors do highlight practical examples in ZBIW19 and KVPF20, but the connections between those works and the theory developed here do not seem particularly deep). Typos - L117: Hedge -> Hegde - L133: algoriths -> algorithms - L134: I believe should read "To design our algorithm for *Theorem 1.4*" not Theorem 1.3. - L242: entires -> entries - L232, L257, Algorithm 1 L4: I believe $B$ in $\frac{\log(1/\epsilon)}{\log(\log(1/\epsilon)/B)}$ was meant to be $B^2$ - Appendix L434: roamdap -> roadmap - Appendix L453: $v_i$ -> $u_i$ under the product sign

Questions

I am curious to hear how you think your results might lead to practical speedups in attention computation for future work.

Rating

6: Weak Accept: Technically solid, moderate-to-high impact paper, with no major concerns with respect to evaluation, resources, reproducibility, ethical considerations.

Confidence

2: You are willing to defend your assessment, but it is quite likely that you did not understand the central parts of the submission or that you are unfamiliar with some pieces of related work. Math/other details were not carefully checked.

Soundness

4 excellent

Presentation

4 excellent

Contribution

3 good

Limitations

The authors do highlight their main limitation: Theorem 4.6's reliance on the strong exponential time hypothesis (SETH). As far as I can tell, no important limitations were omitted.

Reviewer ioBT2023-08-14

Thanks for the responses

I have read the authors' rebuttals and the other reviews. I maintain the view that this work should be accepted.

Reviewer LkJK2023-08-17

I would like to thank the authors for answering the question. I remain to be on the positive side for this submission.

Program Chairsdecision2023-09-21

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC