2025-02-26 · 进阶 · 机器学习 · 计算机视觉 · 自然语言处理

SpargeAttn: Accurate Sparse Attention Accelerating Any Model Inference

SpargeAttn提出了一种通用的稀疏注意力机制,能够有效地加速各种模型推理,同时保持端到端性能。

更新于 2026-01-04。作者:Jintao Zhang、Chendong Xiang、Haofeng Huang、Jia Wei、Haocheng Xi、Jun Zhu、Jianfei Chen。

中文摘要

高效的注意力实现对于大模型至关重要,因为其时间复杂度为二次方。幸运的是,注意力通常表现出稀疏性,即注意力图中许多值接近于零,这使得可以省略相应的计算。许多研究已经利用稀疏模式来加速注意力。然而,大多数现有工作通过利用注意力图中的某些稀疏模式,专注于优化特定模型内的注意力。保证不同模型速度提升和端到端性能的通用稀疏注意力仍然难以捉摸。在本文中,我们提出了SpargeAttn,这是一种适用于任何模型的通用稀疏和量化注意力。我们的方法使用两阶段的在线滤波器:在第一阶段,我们快速准确地预测注意力图,使得注意力中某些矩阵乘法可以跳过。在第二阶段,我们设计了一种在线softmax感知滤波器,它不会带来额外的开销,并进一步跳过一些矩阵乘法。实验表明,我们的方法显著加速了包括语言、图像和视频生成在内的各种模型,而不会牺牲端到端的指标。代码可在https://github.com/thu-ml/SpargeAttn上获取。

英文摘要

An efficient attention implementation is essential for large models due to its quadratic time complexity. Fortunately, attention commonly exhibits sparsity, i.e., many values in the attention map are near zero, allowing for the omission of corresponding computations. Many studies have utilized the sparse pattern to accelerate attention. However, most existing works focus on optimizing attention within specific models by exploiting certain sparse patterns of the attention map. A universal sparse attention that guarantees both the speedup and end-to-end performance of diverse models remains elusive. In this paper, we propose SpargeAttn, a universal sparse and quantized attention for any model. Our method uses a two-stage online filter: in the first stage, we rapidly and accurately predict the attention map, enabling the skip of some matrix multiplications in attention. In the second stage, we design an online softmax-aware filter that incurs no extra overhead and further skips some matrix multiplications. Experiments show that our method significantly accelerates diverse models, including language, image, and video generation, without sacrificing end-to-end metrics. The codes are available at https://github.com/thu-ml/SpargeAttn.

解读

一句话总结

SpargeAttn提出了一种通用的稀疏注意力机制,能够有效地加速各种模型推理,同时保持端到端性能。

问题1:这篇论文想要解决什么具体问题?

问题2:论文的核心创新点是什么?

问题3:实验结果如何验证了方法的有效性?

问题4:这个研究的实际应用价值是什么?

来源

机器可读索引:llms.txt