arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2302.13214cs.LGcs.CCcs.DSstat.ML
收藏

快速注意力需要有界条目

Fast Attention Requires Bounded Entries

Columbia University(哥伦比亚大学);Adobe Research(奥多比研究院)

Josh Alman, Zhao Song

AI总结:

本文研究内积注意力计算的复杂度,证明当矩阵条目上界 $B$ 小于 $\sqrt{\log n}$ 时存在近线性时间近似算法,而达到该界限时在强指数时间假设下无法实现次二次时间近似,解释了实践中条目越小效率越高的现象。

摘要:

在现代机器学习中,内积注意力计算是训练大型语言模型(如 Transformer、GPT-1、BERT、GPT-2、GPT-3 和 ChatGPT)的基础任务。形式上,该问题中,输入为三个矩阵 $Q, K, V \in [-B,B]^{n \times d}$,目标是构造矩阵 $\mathrm{Att}(Q,K,V) := \mathrm{diag}(A {\bf 1}_n)^{-1} A V \in \mathbb{R}^{n \times d}$,其中 $A = \exp(QK^\top/d)$ 是“注意力矩阵”,$\exp$ 按元素应用。直接方法显式计算 $n \times n$ 注意力矩阵 $A$,因此即使 $d = n^{o(1)}$ 很小时也需要 $\Omega(n^2)$ 时间。本文研究是否可以通过隐式利用矩阵 $A$ 实现更快的算法。我们给出两个结果,表明在 $B = \Theta(\sqrt{\log n})$ 处存在急剧转变。$\bullet$ 如果 $d = O(\log n)$ 且 $B = o(\sqrt{\log n})$,存在一个 $n^{1+o(1)}$ 时间的算法,以 $1/\mathrm{poly}(n)$ 加性误差近似 $\mathrm{Att}(Q,K,V)$。$\bullet$ 如果 $d = O(\log n)$ 且 $B = \Theta(\sqrt{\log n})$,假设细粒度复杂度理论中的强指数时间假设,则不可能在真正次二次时间 $n^{2 - \Omega(1)}$ 内以 $1/\mathrm{poly}(n)$ 加性误差近似 $\mathrm{Att}(Q,K,V)$。这为实践中观察到的现象提供了理论解释:当输入矩阵条目较小时,注意力计算效率更高。

英文摘要:

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.

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

↑