[论文解读] Fast Attention Requires Bounded Entries
本文证明了近似注意力计算的一个紧转变:当输入条目界 B 为 o(√(log n)) 时,近线性时间是可能的;但在 B = Θ(√(log n)) 下,依照 SETH,存在子二次时间的困难性。
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 imes 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 imes d}$, where $A = \exp(QK^ op/d)$ is the `attention matrix', and $\exp$ is applied entry-wise. Straightforward methods for this problem explicitly compute the $n imes 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.
研究动机与目标
- 推动在 Transformer 中的内积注意力超越显式的 O(n^2) 计算的加速研究。
- 研究输入条目大小 B 如何影响快速近似注意力的可行性。
- 在 d = O(log n 时,表征 B = Θ(√(log n)) 的尖锐转移点。
- 提供一个在小 B 时实现近线性时间的算法,以及对较大 B 的有条件下界。
提出的方法
- 引入 AA ttC(n,d,B,εa) 作为条目上限为 B 的近似注意力计算问题。
- 利用指数的多项式近似,通过多项式方法获得注意力矩阵 A 的低秩近似。
- 证明 A 可以被秩为 r 的低秩矩阵近似,且可构造的因子 U1,U2 在 O(n r) 时间内得到(引理 3.4)。
- 将对 A 的近似转化为对注意力结果的近似,同时实现对 D 和 V 传播的受控(引理 3.5 和 3.6)。
- 推导出一个主上界算法(算法 1),运行时间为 O(T_mat(n,r,d) + n r g),其中 g 和 r 依赖于 B 与 ε。
- 选择参数以在 B = o(√(log n)) 且 d = O(log n 时实现 n^{1+o(1)} 时间。
实验结果
研究问题
- RQ1何时可以在输入规模几乎线性时间内完成注意力计算?
- RQ2在 SETH 下何时可以证明不存在真正的子二次时间(n^{2−Ω(1)})的近似注意力计算算法?
- RQ3输入条目界 B 如何影响 d = O(log n 时近似注意力计算的复杂性?
- RQ4基于多项式方法的技术是否能为 AA ttC 提供实际的近线性算法?
- RQ5在 B = Θ(√(log n)) 附近,复杂度的精确转变点是什么?
主要发现
- 在 B = Θ(√(log n)) 处存在紧致转变。
- 若 d = O(log n) 且 B = o(√(log n)),存在 n^{1+o(1)} 运行时间的 AA ttC 算法,误差为多项式(n) 的可加误差。
- 若 d = O(log n) 且 B = Θ(√(log n)),在 SETH 假设下不存在真正的子二次时间(n^{2−Ω(1)}) 的近似 AA ttC 算法。
- AA ttC 的下界利用了在 SETH 下的近似最近邻搜索的归约。
- 上界算法利用对 exp 的多项式近似和低秩分解来加速计算。
- 该工作为注意力在存在边界或低比特条目的情况下更快的观察提供了理论解释。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。