Skip to main content
QUICK REVIEW

[논문 리뷰] HyperAttention: Long-context Attention in Near-Linear Time

In‐Su Han, Rajesh Jayaram|arXiv (Cornell University)|2023. 10. 09.
Advanced Neural Network ApplicationsComputer Science인용 수 9
한 줄 요약

HyperAttention은 perturbation-tolerant diagonal D 근사와 row-norm 기반 샘플링을 사용하는 근사 주의 방법으로 인과 마스킹을 가능하게 하며 긴 컨텍스트에서 실제 속도 향상을 제공하는 거의 선형 시간의 근사 주의 방법이다.

ABSTRACT

We present an approximate attention mechanism named HyperAttention to address the computational challenges posed by the growing complexity of long contexts used in Large Language Models (LLMs). Recent work suggests that in the worst-case scenario, quadratic time is necessary unless the entries of the attention matrix are bounded or the matrix has low stable rank. We introduce two parameters which measure: (1) the max column norm in the normalized attention matrix, and (2) the ratio of row norms in the unnormalized attention matrix after detecting and removing large entries. We use these fine-grained parameters to capture the hardness of the problem. Despite previous lower bounds, we are able to achieve a linear time sampling algorithm even when the matrix has unbounded entries or a large stable rank, provided the above parameters are small. HyperAttention features a modular design that easily accommodates integration of other fast low-level implementations, particularly FlashAttention. Empirically, employing Locality Sensitive Hashing (LSH) to identify large entries, HyperAttention outperforms existing methods, giving significant speed improvements compared to state-of-the-art solutions like FlashAttention. We validate the empirical performance of HyperAttention on a variety of different long-context length datasets. For example, HyperAttention makes the inference time of ChatGLM2 50\% faster on 32k context length while perplexity increases from 5.6 to 6.3. On larger context length, e.g., 131k, with causal masking, HyperAttention offers 5-fold speedup on a single attention layer.

연구 동기 및 목표

  • 동기가 긴 시퀀스에서 트랜스포머의 주의에 대한 이차 시간 복잡도와 메모리 문제를 극복하는 것.
  • 목표: 긴 컨텍스트와 인과 마스킹에서 작동하는 스펙트럼 보장을 갖춘 근사 주의 메커니즘을 설계한다.
  • 목표: 거의 선형 시간과 실제 LLM 및 긴 컨텍스트 벤치마크에서의 성능 유지가 가능하도록 한다.

제안 방법

  • 스펙트럴 특성을 보존하는 주의 출력에 대한 샘플링 기반 근사를 정의한다.
  • 해밍 정렬 LSH를 사용해 주의 행렬의 큰 엔트리를 찾고 희소 지배 엔트리 마스크를 형성한다.
  • 키/행의 균일 샘플링에 의존하는 거의 선형 시간 추정기로 대각 스케일링 D를 근사한다.
  • D^{-1}AV를 근사하기 위해 V의 행을 제곱된 행 노름에 따라 샘플링하는 근사 행렬 곱(AMM)을 수행한다.
  • 재귀적 블록 분할 방식으로 인과 마스킹으로의 확장을 수행한다.
  • 출력이 ε 스펙트럼 노름 오차 이내로 근사되며 거의 선형 런타임을 갖는 주된 이론적 보장(HyperAttention)을 제공한다.
Figure 2: Causal attention matrix can be divided into three equal-sized non-zero sections: ${\bm{M}}^{\mathcal{C}}_{1}\odot{\bm{A}}_{11}$ and ${\bm{M}}^{\mathcal{C}}_{2}\odot{\bm{A}}_{22}$ are both causal attention matrices, and ${\bm{A}}_{21}$ is an unmasked attention matrix.
Figure 2: Causal attention matrix can be divided into three equal-sized non-zero sections: ${\bm{M}}^{\mathcal{C}}_{1}\odot{\bm{A}}_{11}$ and ${\bm{M}}^{\mathcal{C}}_{2}\odot{\bm{A}}_{22}$ are both causal attention matrices, and ${\bm{A}}_{21}$ is an unmasked attention matrix.

실험 결과

연구 질문

  • RQ1긴 컨텍스트 길이에서도 스펙트럼 보장을 유지하면서 dot-product 주의의 거의 선형 시간 근사를 달성할 수 있는가?
  • RQ2무거운 엔트리 탐지와 행-노름 기반 샘플링이 경계된 엔트리나 낮은 안정 랭크를 요구하지 않고도 실용적이고 증명 가능한 보장을 제공하는가?
  • RQ3인과 마스킹 및 긴 컨텍스트 벤치마크에 대해 HyperAttention이 사전 학습된 LLM에서 어떤 성능을 나타내는가?

주요 결과

  • HyperAttention은 약한 가정 하에서 주의 근사에 대해 거의 선형 시간 복잡도를 보인다.
  • 실험적으로 마스크가 없는 경우 131k 컨텍스트에서 순전파/역전파가 50배 이상 빨라지는 등 상당한 속도 향상을 보여주며 긴 컨텍스트 과제에서 경쟁력 있는 perplexity를 유지한다.
  • 프리트레인 모델(ChatGLM2-6B-32k, Phi-1.5 등)에 몽키 패치를 통해 통합 시 특정 과제에서 성능 저하가 경미하고 요약 및 코드 과제에서 품질을 크게 유지한다.
  • 알고리즘 4(재귀적 분할 방식)를 통해 인과 마스킹을 지원하며 LongBench와 같은 긴 컨텍스트 데이터셋에서도 효과적이다.
  • 소프트맥스 주의의 행-노름(alpha bound)과 관련된 경험적 가정이 실무적으로 성립한다.
(a) $\mathtt{chatglm2}$ - $\mathtt{6b}$ - $\mathtt{32k}$
(a) $\mathtt{chatglm2}$ - $\mathtt{6b}$ - $\mathtt{32k}$

이 논문 읽기

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

누빈트에서 이 논문 읽기

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