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

Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu +1 more
11/1/2024
154 citations

Official code: thu-ml/SageAttention (3,992 stars, Cuda, Apache-2.0, last commit 2026-01-17).

Abstract

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.

Show full abstract

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.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

[ICLR2025, ICML2025, NeurIPS2025 Spotlight] Quantized Attention achieves speedup of 2-5x compared to FlashAttention, without losing end-to-end metrics across language, image, and video models.

3,992545Cuda, PythonOct 3, 202410 months agoApache-2.0
attentioncudaefficient-attentioninference-accelerationllm+7 more

Similar Papers

Cite this paper

@article{zhang2024sageattention,
  title  = {SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization},
  author = {Jintao Zhang and Haofeng Huang and Pengle Zhang and Jia Wei and Jun Zhu and Jianfei Chen},
  year   = {2024},
  eprint = {2411.10958},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2411.10958},
  journal = {ICML 2025 2025}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2411.10958.svg)](https://codeofpaper.com/paper/2411.10958)

Discussion