SeerAttention:在你的 LLM 中学习内在稀疏注意力
SeerAttention: Learning Intrinsic Sparse Attention in Your LLMs
AI总结:
本文提出 SeerAttention,通过受 MoE 启发的可学习门控从 LLM 中预测块级注意力稀疏性,并结合块稀疏 FlashAttention 内核,在长上下文预填充中提升准确率、降低延迟。
摘要:
注意力是现代大型语言模型(LLM)的基石。然而,其二次复杂度阻碍了效率和可扩展性,尤其是在长上下文处理方面。一种很有前景的方法是利用注意力中的稀疏性。但是,现有的基于稀疏性的解决方案主要依赖于注意力头层面的预定义模式或启发式方法,难以高效地针对不同上下文进行动态适应。我们提出了 SeerAttention,这是一种简单而有效的注意力机制,可直接从 LLM 自身学习块级注意力稀疏性。受混合专家(Mixture of Experts,MoE)中门控机制的启发,SeerAttention 通过一个可学习门控增强传统注意力,该门控选择性地激活注意力图中的重要块。具体而言,门控首先沿序列维度对查询(Q)和键(K)张量进行池化,并通过可学习线性层进行处理。随后将所得矩阵相乘,生成门控分数,用于预测块级注意力稀疏性。结合我们的块稀疏 FlashAttention 内核,SeerAttention 可在 GPU 上实现显著加速。当应用于预训练 LLM 时,SeerAttention 只需以轻量级自蒸馏方式训练门控参数,从而实现快速收敛。我们的评估结果表明,与先前方法相比,SeerAttention 在长上下文预填充方面实现了更好的模型准确率和更低的延迟。代码可在 https://github.com/microsoft/SeerAttention 获取。
英文摘要:
Attention is the cornerstone of modern Large Language Models (LLMs). Yet its quadratic complexity hinders efficiency and scalability, especially for long-context processing. A promising approach is to leverage sparsity in attention. However, existing sparsity-based solutions predominantly rely on predefined patterns or heuristics at the attention head level, struggling to adapt dynamically to different contexts efficiently. We propose SeerAttention, a simple yet effective attention mechanism that directly learns the block-level attention sparsity from the LLM itself. Inspired by the gating mechanism in Mixture of Experts (MoE), SeerAttention augments the conventional attention with a learnable gate that selectively activates important blocks within the attention map. Specifically, the gate first pools the query (Q) and key (K) tensors along the sequence dimension and processes them through learnable linear layers. The resulting matrices are then multiplied together to produce the gating scores, which are used to predict block-level attention sparsity. Combined with our block-sparse FlashAttention kernel, SeerAttention can achieve significant speedup on GPUs. When applied to pre-trained LLMs, SeerAttention only requires training the gate parameters in a lightweight self-distillation manner, allowing rapid convergence. Our evaluation results demonstrate that SeerAttention achieves better model accuracy and lower latency for long-context pre-filling compared to prior methods. Code is available at: https://github.com/microsoft/SeerAttention
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。