Paper commentary
SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization
SageAttention2 speeds up attention by quantizing to INT4 per thread
- Problem SageAttention's INT8 matmul runs at half the speed of INT4, and its FP16 accumulators only help on RTX 3090 and 4090 GPUs.
- Method SageAttention2 quantizes Q and K to INT4 per thread instead of per block, after smoothing out their shared component.
- Results SageAttention2 reaches about 3x the operations per second of FlashAttention2 on RTX4090, with negligible end-to-end metric loss.
Where quantized attention runs out of room
Attention cost grows quadratically with sequence length, so the speed of its kernel decides whether long inputs stay practical. SageAttention quantizes the QK product to INT8 and keeps the PV product in FP16 with FP16 accumulators. Its first weakness is that INT8 matmul runs at only half the speed of INT4. Its second weakness is that FP16 accumulators give a speedup only on RTX 4090 and RTX 3090 GPUs.
SageAttention also achieves 2 × speedup compared with FlashAttention2, so the authors wanted to keep that gain while moving further.
Moving Q and K to INT4 is hard because the INT4 range is only [-7, +7]. Any element more than 14 times smaller than the largest element in its group quantizes to zero. Outliers are much larger than other values, so many non-outlier elements fall to zero and accuracy drops. Per-tensor INT4 quantization of Q and K makes CogvideoX produce a completely blurry video.
The authors traced this to the per-block quantization of Q and K in SageAttention, which doesn't reach sufficient INT4 accuracy.
Quantizing P and V to FP8 runs into a different obstacle inside the tensor cores. When D has more than 13 mantissa bits, the output C keeps only its values with the least significant 10 mantissa bits zeroed out. So the PV product in FP8 loses accuracy compared with an FP32 accumulator. The design therefore has to handle both the narrow INT4 range and the FP22 accumulator, which leads to the two-level accumulation strategy.
Smooth Q and K, then quantize at thread granularity
The core move is to shrink the values that INT4 has to represent, by removing the part of Q and K that is nearly the same for every token. Q and K for all tokens are highly similar, so the leftover variation is small and quantizes far better. The authors smooth K as SageAttention does, and they also smooth Q by subtracting a per-block mean.
Because INT4 covers only [-7, +7], any element more than 14 times smaller than the largest one in its group rounds to zero. Smoothing keeps the largest element small, so the magnitudes in a group stay closer to uniform.
The removed Q mean isn't lost, because the authors add it back after the QK product. The correction term ΔS is computed by a GEMV, which reads the off-chip Q and K only once. Smoothing, quantization and the GEMV can be fused into one kernel, so the extra work adds only a marginal overhead next to the matrix multiplication. The authors quantize the smoothed γ(Q) and γ(K), not the raw Q and K, because the smoothed matrices hold fewer outliers.
Per-channel quantization and SmoothQuant don't fit the QK product, because the quantization must run along the token axis of QK⊤.
The second idea addresses granularity, since per-token scales would force an extra dequantization step for each thread. Per-block scales from SageAttention don't reach enough accuracy at INT4, so the authors looked at a finer grain. Per-thread quantization groups the tokens that one thread holds, so each thread uses a single scale and no extra dequantization.
The name follows the thread mapping of the PTX mma instructions, which fixes which tokens share a thread. The quantization step appears inside the kernel loop, where Q is quantized per thread and K is quantized per thread for each block.
How one attention step is computed
Figure 3 summarizes the pipeline, which runs in five steps. The first step smooths Q, K and V, and a GEMV computes the bias term from the Q block mean and the smoothed K. The bias for each block pair is the product of the Q block mean and the smoothed K.

Figure 3 . Workflow of SageAttention2. 1 Smooth Q, K, V. 2 A GEMV to obtain ∆S. 3 Per-thread quantize Q, Kand per- channel quantize V . 4 Perform the SageAttention2 kernel. 5 Correct the output.
Original paper · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · Original paper figure · Extracted the figure area from page 4 of the original PDF.Here \( \bar q_i \) is the mean of the i-th block of Q, and \( \gamma(K_j) \) is the smoothed j-th block of K. The bias is \[ \Delta S_{ij} = \bar q_i\,\gamma(K_j)^{\top} \]. The INT4 product of the smoothed blocks is dequantized, and the bias is added back to give the score block.
The softmax values P are then quantized to E4M3 with a static scale, since they already lie in [0, 1]. V is quantized per channel, which addresses the channel-wise outliers that the authors show in Figure 2. Each block product is computed in FP8 with the FP22 accumulator, and the result is added into an FP32 running output.
The authors argue that 22 effective bits suffice, because each block accumulates only a few tokens, for example 64 when bk = 64. An optional smooth V step can reduce the error when V has channel-wise bias, but the main experiments don't use it.
Testing each design choice
The smoothing ablation in CogvideoX shows how much the Q and K treatment matters for accuracy. Without smoothing, the average CosSim over all layers is 80.04%. Smoothing Q and K together raises it to 99.46%, against 98.07% for smoothing K alone and 98.30% for smoothing Q alone. The authors rank the combined setting first, which matches their stated order of effectiveness.
The Llama3.1 end-to-end check points the same way at the model level. With INT4 Q and K and no smoothing, Lambda accuracy drops to 72.6%. Smoothing Q+K lifts Lambda accuracy to 80.8%, close to the 81.5% of full precision. WikiText perplexity falls from 11.698 without smoothing to 6.219 with it, while full precision gives 6.013.
For granularity, per-thread quantization reaches 99.45% CosSim, matching per-token. Per-block quantization reaches only 98.03%, so per-thread gives a clear gain over per-block scales. The per-thread scheme adds no extra dequantization, so the authors count this gain at no extra cost.
For the data types of P and V, E4M3 reaches 99.44% CosSim, close to FP16 at 99.45%. INT8 for the same operands drops to 77.05%, which fits the authors' view that INT quantization suits P poorly.
Quality and speed on real models
On Llama3.1, the WikiText perplexity was 6.013 at full precision and 6.019 with SageAttn2-8b. SageAttn2-4b raised the perplexity to 6.256, and its MMLU accuracy fell from 0.635 to 0.607. SageAttention2-8b quantizes Q and K to INT8, so it targets Hopper GPUs, which lack native INT4 tensor core support. Its end-to-end metrics stay close to full precision on the models in Table 2.
FlashAttn3-fp8 scored 0.1562 on the CLIPSIM metric for CogvideoX (1.5-5B), against 0.1778 at full precision. The authors report that FlashAttention3(fp8) brings noticeable degradation on popular video generation models. SageAttn2-4b has minor differences in those examples, but is much better than the baselines.
Across sequence lengths on RTX4090, SageAttn2-4b ran about 3x faster than FlashAttention2, and SageAttn2-8b about 2.7x faster. Those kernel speedups also held against xformers, at about 4.5x for SageAttn2-4b and 4x for SageAttn2-8b. End to end, CogvideoX (1.5-5B) generation dropped from 1040 s to 577 s on RTX4090 with SageAttn2-8b. Table 8 also lists the Llama3.1 time to first token at 100K tokens on L20, falling from 39.9 s to 25.4 s with SageAttn2-8b.
Limits of the evidence: overheads and remaining gaps
Per-thread quantization adds 0.35% overhead to kernel speed relative to the attention kernel. Smoothing Q adds 3.7%, while two-level accumulation adds 0% against the same attention kernel. The authors report these overheads only at the kernel level, so they don't give an end-to-end cost for the three steps.
Smoothing V is an optional step, and the authors didn't use it in the main experiments. It helps only when V shows channel-wise bias, which the authors say is absent in some models such as Llama3.1. The authors point to Appendix A.4 for the benefit of smoothing V, which this section doesn't cover.
The FP22 finding comes from the authors' probing of the mma(f32f8f8f32) accumulator, with A and B set to zero. The two-level accumulation strategy addresses this by accumulating 22-bit block results into an FP32 buffer. On Llama3.1, MMLU falls from 0.635 at full precision to 0.607 with SageAttn2-4b. SageAttn2-8b keeps Llama3.1 MMLU at 0.634, close to full precision.
The authors' visible examples show SageAttn2-4b with minor differences from full-precision attention. They state that SageAttn2-4b still looks much better than the baselines in those examples. Table 2 marks SageAttention as unable to generate results for CogvideoX (1.5-5B), so that model has no baseline row there.
Paper info
- Authors
- Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen
- Venue
- arXiv · Preprint
- First published
- 2024-11-17
- Added
- 2026-10-29
- Updated
- 2025-10-1
- Version
- v7
- arXiv
- 2411.10958
- Category
- cs.LG · cs.AI · cs.CV · cs.NE · cs.PF
- Original paper terms
- CC BY 4.0
- What we show
- Paper info, commentary and permitted figures from the original paper
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
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. 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.
Quote from the paper
Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen (2024). SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization. arXiv:2411.10958v7. https://arxiv.org/abs/2411.10958v7
BibTeX
@misc{zhang2024sageattention2,
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.10958v7}
}