Skip to main content
QUICK REVIEW

[論文レビュー] Fast Attention Requires Bounded Entries

Josh Alman, Zhao Song|arXiv (Cornell University)|Feb 26, 2023
Machine Learning and AlgorithmsComputer Science被引用数 9
ひとこと要約

論文は近似注意計算の厳密な遷移を示す。入力エントリ制限Bが o(sqrt(log n)) のときほぼ線形時間が可能だが、SETHの下で B = Theta(sqrt(log n)) に対しては超二次時間の困難性が成り立つ。

ABSTRACT

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 = Theta(sqrt(log n)) で鋭い遷移点を特徴づける。
  • 小さな B の場合に近線形時間を達成するアルゴリズムと、より大きな B に対する条件付き下界の双方を提供する。

提案手法

  • AA ttC(n,d,B,εa) を、B で制限されたエントリを持つ近似注意計算問題として導入する。
  • 指数関数の多項式近似を用いて、多項式法によって注意行列 A の低ランク近似を得る。
  • A をランク r の低ランク行列で近似でき、構成可能な因子 U1, U2 を O(n r) 時間で構成できることを示す(Lemma 3.4)。
  • A の近似を、D と V の伝播を制御した注意結果の近似に翻訳する(Lemmas 3.5 および 3.6)。
  • 主な上界アルゴリズム(Algorithm 1)を導出し、実行時間を O(T_mat(n,r,d) + n r g) とする。ここで g と r は B および ε に依存する。
  • B = o(sqrt(log n)) かつ d = O(log n) のとき n^{1+o(1)} 時間を達成するようパラメータを選択する。

実験結果

リサーチクエスチョン

  • RQ1入力サイズにほぼ線形となる注意計算はいつ実現可能か?
  • RQ2SETH の下でサブ二次時間の注意計算が証明上不可能であるのはいつか?
  • RQ3d = O(log n) に対して入力エントリの制限 B が近似注意計算の複雑さにどのように影響するか?
  • RQ4多項式法ベースの手法は AA ttC に実用的な近線形アルゴリズムをもたらすか?
  • RQ5B = Theta(sqrt(log n)) の周りの複雑さの正確な遷移は何か?

主な発見

  • B = Theta(sqrt(log n)) において厳密な遷移が存在する。
  • d = O(log n) かつ B = o(sqrt(log n)) のとき、AA ttC に対して poly(n) の加法誤差で n^{1+o(1)} 時間アルゴリズムが存在する。
  • d = O(log n) かつ B = Theta(sqrt(log n)) で、SETH を仮定すると、AA ttC を近似する真のサブ二次時間 (n^{2−Ω(1)}) アルゴリズムは存在しない。
  • AA ttC の下界は SETH の下で近似最近傍探索からの還元を活用している。
  • 上界アルゴリズムは exp の多項式近似と低ランク分解を用いて計算を高速化する。
  • 本研究は、エントリが制限付きまたは低ビットの場合に注意計算が速いという実務的観察への理論的説明を提供する。

この論文を読む

Nubintのビューアで原文を開き、読みながら気になる箇所をすぐに質問できます。

Nubintでこの論文を読む

このレビューはAIが論文の原文をもとに作成しました。引用する前に原文をご確認ください。