arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2411.10958cs.LGcs.AIcs.CVcs.NEcs.PF
收藏

SageAttention2:通过全面离群点平滑与单线程INT4量化实现高效注意力

SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization

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

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

AI总结:

本研究提出SageAttention2注意力加速方案,通过线程级INT4量化、Q矩阵平滑、两级累加等技术,在保证精度的同时大幅提升注意力计算速度,在多类生成模型上仅带来可忽略的指标损失。

摘要:

尽管线性层的量化已得到广泛应用,但其用于加速注意力计算的应用仍然有限。为了在保持精度的同时,进一步提升注意力计算的效率(相较于SageAttention),我们提出了SageAttention2,它采用速度显著更快的4位矩阵乘法(Matmul),并搭配额外的精度增强技术。首先,我们提出以硬件友好的线程级粒度将矩阵$(Q, K)$量化为INT4,并将矩阵$(\tilde P, V)$量化为FP8。其次,我们提出一种对$Q$进行平滑的方法,以提升INT4 $QK^\top$的计算精度。第三,我们为$\tilde PV$提出两级累加策略,以提升FP8 $\tilde PV$的计算精度。在RTX4090上,SageAttention2的每秒操作数(OPS)分别比FlashAttention2和xformers高出约3倍和4.5倍。此外,在Hopper架构GPU上,SageAttention2的速度与FlashAttention3(fp8)相当,同时精度更高。综合实验证实,我们的方法在各类模型(包括语言、图像和视频生成模型)中造成的端到端指标损失可忽略不计。代码可在https://github.com/thu-ml/SageAttention获取。

英文摘要:

Although quantization for linear layers has been widely used, its application to accelerate the attention process remains limited. To further enhance the efficiency of attention computation compared to SageAttention while maintaining precision, we propose SageAttention2, which utilizes significantly faster 4-bit matrix multiplication (Matmul) alongside additional precision-enhancing techniques. First, we propose to quantize matrices $(Q, K)$ to INT4 in a hardware-friendly thread-level granularity and quantize matrices $(\widetilde P, V)$ to FP8. Second, we propose a method to smooth $Q$, enhancing the accuracy of INT4 $QK^\top$. Third, we propose a two-level accumulation strategy for $\widetilde PV$ to enhance the accuracy of FP8 $\widetilde PV$. The operations per second (OPS) of SageAttention2 surpass FlashAttention2 and xformers by about 3x and 4.5x on RTX4090, respectively. Moreover, SageAttention2 matches the speed of FlashAttention3(fp8) on the Hopper GPUs, while delivering much higher accuracy. Comprehensive experiments confirm that our approach incurs negligible end-to-end metrics loss across diverse models, including those for language, image, and video generation. The code is available at https://github.com/thu-ml/SageAttention.

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

↑