Skip to main content
QUICK REVIEW

[논문 리뷰] Fast Attention Requires Bounded Entries

Josh Alman, Zhao Song|arXiv (Cornell University)|2023. 02. 26.
Machine Learning and AlgorithmsComputer Science인용 수 9
한 줄 요약

본 논문은 근사 어텐션 계산의 엄격한 전이를 보인다: 입력 항 bound B가 o(sqrt(log n))일 때는 근사 선형 시간 가능하지만 B = Theta(sqrt(log n))일 때는 SETH 하에서 부분제곱 시간의 난이도가 성립한다.

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에 대한 조건부 하한을 제공한다.

제안 방법

  • 입력 항이 B로 한정된 근사 어텐션 계산 문제를 AA ttC(n,d,B,εa)로 도입한다.
  • 지수의 다항식 근사를 사용하여 다항식 방법을 통해 어텐션 행렬 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)일 때 입력 항 bound B가 근사 어텐션 계산의 복잡도에 어떤 영향을 미치는가?
  • RQ4다항식 방법 기반 기법이 AA ttC에 대해 실용적 근사 선형 알고리즘을 제공할 수 있는가?
  • RQ5B = Theta(sqrt(log n)) 근처의 복잡도에서 정확한 전이가 무엇인가?

주요 결과

  • B = Theta(sqrt(log n))에서의 치밀한 전이가 있다.
  • d = O(log n)이고 B = o(sqrt(log n))일 때 poly(n) 가산 오차를 갖는 AA ttC에 대한 n^{1+o(1)} 시간 알고리즘이 존재한다.
  • d = O(log n)이고 B = Theta(sqrt(log n))일 때, SETH를 가정하면 AA ttC를 근사하는 truly subquadratic-time(n^{2−Ω(1)}) 알고리즘은 존재하지 않는다.
  • AA ttC에 대한 하한은 SETH 하에서의 근사 최근접 이웃 검색으로의 환원으로 활용된다.
  • 상한 알고리즘은 exp의 다항식 근사와 저랭크 분해를 사용하여 계산을 가속화한다.
  • 본 연구는 바운드된 또는 저 비트 엔트리에서 어텐션이 더 빠르다는 실용적 관찰에 이론적 설명을 제공한다.

이 논문 읽기

누빈트 뷰어에서 원문을 열고, 읽으면서 궁금한 곳을 바로 물어보세요.

누빈트에서 이 논문 읽기

이 리뷰는 AI가 논문 원문을 바탕으로 만들었습니다. 인용하기 전에 원문을 확인해 주세요.