arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.15486cs.CLcs.AIcs.LG
收藏

SampleAttention:通过自适应结构化稀疏注意力实现长上下文大语言模型推理的近无损加速

SampleAttention: Near-Lossless Acceleration of Long Context LLM Inference with Adaptive Structured Sparse Attention

Qianchao Zhu, Jiangfei Duan, Chang Chen, Siran Liu, Guanyu Feng, Xin Lv, Xiao Chuanfu, Dahua Lin, Chao Yang

AI总结:

针对长上下文大语言模型原生注意力二次复杂度导致首令牌生成延迟高的问题,提出自适应结构化近无损稀疏注意力方法SampleAttention,无需额外训练即可无缝替换原生注意力,在几乎无损的前提下最高将首令牌生成时间降低2.42倍。

摘要:

大语言模型(LLM)如今支持极长的上下文窗口,但原生注意力的二次复杂度会导致首令牌生成时间(TTFT)延迟显著升高。现有解决该复杂度问题的方法需要额外的预训练或微调,且通常会牺牲模型准确率。在本文中,我们首先为近无损稀疏注意力提供了理论和实证基础。我们发现,在运行时以低开销动态捕获各注意力头特有的稀疏模式至关重要。为解决这一问题,我们提出了SampleAttention——一种自适应结构化的近无损稀疏注意力方法。利用观测到的显著稀疏模式,SampleAttention对固定比例的相邻令牌进行注意力计算以捕获局部窗口模式,并采用两阶段查询引导的键值过滤方法(以低开销自适应选择最小的键值集合)来捕获列条带模式。综合评估表明,SampleAttention可以在几乎无准确率损失的情况下无缝替换现成LLM中的原生注意力,并且与FlashAttention相比,将TTFT降低了最高2.42倍。

英文摘要:

Large language models (LLMs) now support extremely long context windows, but the quadratic complexity of vanilla attention results in significantly long Time-to-First-Token (TTFT) latency. Existing approaches to address this complexity require additional pretraining or finetuning, and often sacrifice model accuracy. In this paper, we first provide both theoretical and empirical foundations for near-lossless sparse attention. We find dynamically capturing head-specific sparse patterns at runtime with low overhead is crucial. To address this, we propose SampleAttention, an adaptive structured and near-lossless sparse attention. Leveraging observed significant sparse patterns, SampleAttention attends to a fixed percentage of adjacent tokens to capture local window patterns, and employs a two-stage query-guided key-value filtering approach, which adaptively select a minimum set of key-values with low overhead, to capture column stripe patterns. Comprehensive evaluations show that SampleAttention can seamlessly replace vanilla attention in off-the-shelf LLMs with nearly no accuracy loss, and reduces TTFT by up to $2.42\times$ compared with FlashAttention.

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

↑