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

XAttention: Block Sparse Attention with Antidiagonal Scoring

XAttention通过利用注意力矩阵中反斜对角线值的和作为块重要性的强大代理,实现了在Transformer模型中长上下文推理的加速,同时保持了与全注意力相当的性能。

更新于 2025-03-21。作者:Ruyi Xu、Guangxuan Xiao、Haofeng Huang、Junxian Guo、Song Han。

中文摘要

长上下文Transformer模型(LCTMs)在现实应用中至关重要,但由于注意力机制的二次复杂度,其计算成本高昂。块稀疏注意力通过集中在关键区域来缓解这一问题,但现有方法由于块重要性的测量成本高,在平衡准确性和效率方面存在困难。在本文中,我们介绍了XAttention,这是一个即插即用框架,利用稀疏注意力大幅加速Transformer模型的长上下文推理。XAttention的关键创新在于,注意力矩阵中反斜对角线值之和(即从左下角到右上角)为块重要性提供了一个强大的代理指标。这允许精确地识别和修剪非关键块,从而实现高稀疏度和推理速度的大幅提升。在多个长上下文基准测试的综合评估中——包括语言领域的RULER和LongBench,视频理解领域的VideoMME,以及视频生成领域的VBench。XAttention在保持与全注意力相当准确性的同时,实现了实质性的计算优势。我们展示了注意力计算速度最高可提升13.5倍。这些结果凸显了XAttention释放块稀疏注意力实际潜力,为LCTMs在实际应用中的可扩展和高效部署铺平了道路。代码可在https://github.com/mit-han-lab/x-attention上获取。

英文摘要

Long-Context Transformer Models (LCTMs) are vital for real-world applications but suffer high computational costs due to attention's quadratic complexity. Block-sparse attention mitigates this by focusing computation on critical regions, yet existing methods struggle with balancing accuracy and efficiency due to costly block importance measurements. In this paper, we introduce XAttention, a plug-and-play framework that dramatically accelerates long-context inference in Transformers models using sparse attention. XAttention's key innovation is the insight that the sum of antidiagonal values (i.e., from the lower-left to upper-right) in the attention matrix provides a powerful proxy for block importance. This allows for precise identification and pruning of non-essential blocks, resulting in high sparsity and dramatically accelerated inference. Across comprehensive evaluations on demanding long-context benchmarks-including RULER and LongBench for language, VideoMME for video understanding, and VBench for video generation. XAttention achieves accuracy comparable to full attention while delivering substantial computational gains. We demonstrate up to 13.5x acceleration in attention computation. These results underscore XAttention's ability to unlock the practical potential of block sparse attention, paving the way for scalable and efficient deployment of LCTMs in real-world applications. Code is available at https://github.com/mit-han-lab/x-attention.

解读

一句话总结

XAttention通过利用注意力矩阵中反斜对角线值的和作为块重要性的强大代理,实现了在Transformer模型中长上下文推理的加速,同时保持了与全注意力相当的性能。

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

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

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

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

来源