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

SageAttention:用于即插即用推理加速的高精度8位注意力机制

SageAttention: Accurate 8-Bit Attention for Plug-and-play Inference Acceleration

Dept. of Comp. Sci. & Tech.(计算机科学与技术系);Institute for AI(人工智能研究院);BNRist Center(BNRist中心);Tsinghua-Bosch Joint ML Center(清华大学-博世联合机器学习中心);THBI Lab(THBI实验室);Tsinghua University(清华大学)

Jintao Zhang, Jia Wei, Haofeng Huang, Pengle Zhang, Jun Zhu, Jianfei Chen

AI总结:

针对现有量化方法多聚焦线性层、长序列下注意力推理耗时高的问题,提出SageAttention 8位注意力量化方法,推理速度优于FlashAttention2、xformers且精度超FlashAttention3,在多类模型上几乎无指标损失。

摘要:

Transformer架构在各类模型中占据主导地位。作为Transformer的核心,注意力机制的计算复杂度为$O(N^2)$,而线性变换的计算复杂度为$O(N)$。在处理长序列时,注意力机制成为主要的耗时组件。尽管量化已被证明是加速模型推理的有效方法,但现有量化方法主要聚焦于优化线性层。针对这一问题,我们首先详细分析了注意力机制中量化的可行性。随后,我们提出了SageAttention,一种高效且高精度的注意力量化方法。我们方法的每秒操作数(OPS)分别比FlashAttention2和xformers高出约2.1倍和2.7倍。SageAttention还取得了优于FlashAttention3的精度表现。综合实验证实,我们的方法在各类模型(包括大语言处理、图像生成和视频生成模型)上几乎不会造成端到端指标损失。代码可在https://github.com/thu-ml/SageAttention获取。

英文摘要:

The transformer architecture predominates across various models. As the heart of the transformer, attention has a computational complexity of $O(N^2)$, compared to $O(N)$ for linear transformations. When handling large sequence lengths, attention becomes the primary time-consuming component. Although quantization has proven to be an effective method for accelerating model inference, existing quantization methods primarily focus on optimizing the linear layer. In response, we first analyze the feasibility of quantization in attention detailedly. Following that, we propose SageAttention, a highly efficient and accurate quantization method for attention. The OPS (operations per second) of our approach outperforms FlashAttention2 and xformers by about 2.1 times and 2.7 times, respectively. SageAttention also achieves superior accuracy performance over FlashAttention3. Comprehensive experiments confirm that our approach incurs almost no end-to-end metrics loss across diverse models, including those for large language processing, image generation, and video generation. The codes are available at https://github.com/thu-ml/SageAttention.

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

↑