arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2505.14840cs.LGcs.CC
收藏

任意温度下注意力的次平方算法与难度

Subquadratic Algorithms and Hardness for Attention with Any Temperature

University of California, San Diego(加州大学圣地亚哥分校)

Shreya Gupta, Boyang Huang, Barna Saha, Yinzhan Xu, Christopher Ye

AI总结:

本研究刻画了任意温度下快速注意力的可行条件,提出了常数头部维度下适用于大元素规模的次平方注意力算法,同时证明了相关算法改进的难度以及高维度下标准算法的最优性。

摘要:

尽管Transformer架构广受欢迎,标准的注意力计算算法在上下文长度$n$下仍存在二次时间复杂度的问题。Alman和Song[NeurIPS 2023]证明,在强指数时间假设($\textsf{SETH}$)下,当头部维度$d = Θ(\n)$时,次平方注意力可行当且仅当输入元素的绝对值有上界$B = o(\n)$。等价地,对于$d=Θ(\n)$,次平方注意力可行当且仅当softmax在高温下应用。这些算法的运行时间与$B$呈指数关系,因此在$B$的特定范围之外,它们甚至无法产生多项式时间算法。\n这自然引出了一个问题:什么时候可以在不对温度做强假设的情况下高效计算注意力?是否存在运行时间与元素规模$B$呈多对数关系的快速注意力算法?在本研究中,我们解决了这个问题,并刻画了任意温度下快速注意力可行的条件。首先,对于所有常数$d = O(1)$,我们提出了首个适用于大$B$的次平方注意力算法,时间复杂度为$\tilde{O}(n^{2 - 1/d} \n)$。即使头部维度较大的矩阵,只要其秩较低,我们的结果依然成立。在该场景下,我们还给出了具有相似运行时间的注意力梯度计算方法,因此可应用于完整的大语言模型(LLM)训练过程。此外,我们证明对我们的算法进行任何实质性改进都不太可能。具体而言,我们证明即使当$d = 2^{Θ(\n)}$时,在$\textsf{SETH}$下注意力仍需要$n^{2 - o(1)}$的时间。\n最后,在$d = \n$的场景下,我们证明在主流的细粒度复杂度假设下,标准算法是最优的。

英文摘要:

Despite the popularity of the Transformer architecture, the standard algorithm for computing Attention suffers from quadratic time complexity in context length $n$. Alman and Song [NeurIPS 2023] showed that when the head dimension $d = Θ(\log n)$, subquadratic Attention is possible if and only if the inputs have small entries bounded by $B = o(\sqrt{\log n})$ in absolute values, under the Strong Exponential Time Hypothesis ($\mathsf{SETH}$). Equivalently, subquadratic Attention is possible if and only if the softmax is applied with high temperature for $d=Θ(\log n)$. Running times of these algorithms depend exponentially on $B$ and thus they do not lead to even a polynomial-time algorithm outside the specific range of $B$. This naturally leads to the question: when can Attention be computed efficiently without strong assumptions on temperature? Are there fast attention algorithms that scale polylogarithmically with entry size $B$? In this work, we resolve this question and characterize when fast Attention for arbitrary temperatures is possible. First, for all constant $d = O(1)$, we give the first subquadratic $\tilde{O}(n^{2 - 1/d} \cdot \mathrm{polylog}(B))$ time algorithm for Attention with large $B$. Our result holds even for matrices with large head dimension if they have low rank. In this regime, we also give a similar running time for Attention gradient computation, and therefore for the full LLM training process. Furthermore, we show that any substantial improvement on our algorithm is unlikely. In particular, we show that even when $d = 2^{Θ(\log^* n)}$, Attention requires $n^{2 - o(1)}$ time under $\mathsf{SETH}$. Finally, in the regime where $d = \mathrm{poly}(n)$, we show that the standard algorithm is optimal under popular fine-grained complexity assumptions.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑