arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2310.05869cs.LGcs.AI
收藏

HyperAttention:近线性时间的长上下文注意力机制

HyperAttention: Long-context Attention in Near-Linear Time

Yale University(耶鲁大学);Google Research(谷歌研究院);CMU(卡内基梅隆大学)

Insu Han, Rajesh Jayaram, Amin Karbasi, Vahab Mirrokni, David P. Woodruff, Amir Zandieh

AI总结:

本文提出 HyperAttention 近似注意力机制,通过细粒度参数刻画问题难度并结合局部敏感哈希识别大元素,在近线性时间内处理长上下文,显著超越 FlashAttention 的推理速度。

摘要:

我们提出了一种名为 HyperAttention 的近似注意力机制,以应对大语言模型(LLMs)中长上下文日益增长的复杂性所带来的计算挑战。近期研究表明,在最坏情况下,除非注意力矩阵的元素有界或矩阵具有低稳定秩,否则二次时间不可避免。我们引入两个参数来衡量:(1)归一化注意力矩阵中的最大列范数,以及(2)在检测并移除大元素后,未归一化注意力矩阵中行范数的比值。我们利用这些细粒度参数来刻画问题的难度。尽管存在先前的下界,只要上述参数较小,即使矩阵元素无界或稳定秩较大,我们仍能实现线性时间的采样算法。HyperAttention 采用模块化设计,便于集成其他快速的底层实现,尤其是 FlashAttention。实验上,通过使用局部敏感哈希(LSH)来识别大元素,HyperAttention 优于现有方法,相比 FlashAttention 等最先进方案带来了显著的速度提升。我们在多种不同长上下文长度的数据集上验证了 HyperAttention 的经验性能。例如,HyperAttention 使 ChatGLM2 在 32k 上下文长度上的推理时间加快了 50%,而困惑度从 5.6 增加到 6.3。在更大的上下文长度(如 131k)上,配合因果掩码,HyperAttention 在单个注意力层上提供了 5 倍的加速。

英文摘要:

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.

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

↑