Papers
Topics
Authors
Recent
Search
2000 character limit reached

SageAttention2: Fast Quantized Attention

Updated 16 January 2026
  • SageAttention2 is an efficient attention mechanism that employs low-bit quantization to accelerate QK^T and PV computations in standard attention models.
  • It utilizes INT4/INT8 for Q/K and FP8 for P/V with FP16 accumulation, achieving up to 3.9× faster throughput compared to FlashAttention2.
  • Empirical benchmarks across language, image, and video tasks demonstrate significant speedups while maintaining nearly identical accuracy to full-precision models.

SageAttention2 is an efficient attention mechanism designed to address the quadratic time complexity of standard attention operations, specifically by leveraging low-bit quantization to accelerate the critical matrix multiplications within attention kernels. The method targets both the QKTQK^T computation for similarity scores and the PVPV computation for weighted value aggregation, quantizing on-the-fly and optimizing for NVIDIA TensorCore architecture. SageAttention2++ introduces further optimizations, achieving substantial kernel throughput improvements by utilizing FP8 multiplication with FP16 accumulation, minimizing range overflow, and reducing data conversion overhead. Empirical results demonstrate that SageAttention2++ attains up to a 3.9× speedup over FlashAttention2, with negligible degradation in end-to-end metrics for language, image, and video generation tasks (Zhang et al., 27 May 2025).

1. Core Algorithmic Modifications

SageAttention2++ modifies the matrix multiplication paradigm used in SageAttention2. In typical attention implementations (e.g., FlashAttention-style), computational expense per head is dominated by two operations:

  • QKTQK^T: Shapes N×d×d×NN×NN \times d \times d \times N \to N \times N
  • PVPV: Shapes N×d×d×DN×DN \times d \times d \times D \to N \times D (where DD is head-value dimension)

SageAttention2 quantizes QQ and KK as INT4/INT8 and PP and PVPV0 as FP8 (E4M3), performing PVPV1 multiplication with accumulation in FP32 registers using the mma.f32.f8.f8.f32 TensorCore instruction. SageAttention2++ replaces this with FP8 × FP8 PVPV2 FP16 accumulation via mma.f16.f8.f8.f16, supported by Ada-generation GPUs such as RTX 4090 and RTX 5090. This change yields approximately 4× faster throughput compared to native FP16 MatMul and 2× faster than FP8 PVPV3 FP32 accumulation.

Range narrowing is required because FP16 accumulators can overflow (PVPV4). To control this, PVPV5 and PVPV6 are bounded such that PVPV7, with PVPV8, PVPV9 chosen so that delayed FP32 buffering remains in range: QKTQK^T0. Delayed FP32 buffering reduces PTX conversion cost by accumulating two FP16 results before conversion.

2. Quantization Methodology and Formulas

SageAttention2++ employs block-wise quantization for QKTQK^T1 with specific schemes:

  • QKTQK^T2 quantization: INT4/INT8 block-wise. Given QKTQK^T3,

QKTQK^T4

Reconstruction: QKTQK^T5

  • QKTQK^T6 quantization: FP8 (E4M3) per block. Softmax-attention QKTQK^T7,

QKTQK^T8

with QKTQK^T9.

  • N×d×d×NN×NN \times d \times d \times N \to N \times N0 quantization: FP8 (E4M3) per-channel,

N×d×d×NN×NN \times d \times d \times N \to N \times N1

with N×d×d×NN×NN \times d \times d \times N \to N \times N2.

  • N×d×d×NN×NN \times d \times d \times N \to N \times N3 accumulation: FP16 via TensorCore,

N×d×d×NN×NN \times d \times d \times N \to N \times N4

Together:

N×d×d×NN×NN \times d \times d \times N \to N \times N5

3. Computational Complexity and Throughput

Full-precision attention operates at N×d×d×NN×NN \times d \times d \times N \to N \times N6 for N×d×d×NN×NN \times d \times d \times N \to N \times N7 and N×d×d×NN×NN \times d \times d \times N \to N \times N8 for N×d×d×NN×NN \times d \times d \times N \to N \times N9 per head. SageAttention2++ maintains these asymptotic bounds but improves the constant factor. Defining PVPV0 as FP16 MatMul throughput and PVPV1 as FP8PVPV2FP8PVPV3FP16 throughput:

PVPV4

for PVPV5. For overall end-to-end kernel time PVPV6:

PVPV7

PVPV8

with PVPV9, leading to observed kernel speedups of 3–3.9× over FlashAttention2.

4. Empirical Benchmarks

Tests on NVIDIA RTX 4090 and 5090 (Ada Lovelace) with head-dimensions 64 and 128 and sequence lengths up to 8k revealed peak kernel speedups:

  • SageAttention2++(4+8) (INT4 N×d×d×DN×DN \times d \times d \times D \to N \times D0, FP8 N×d×d×DN×DN \times d \times d \times D \to N \times D1): N×d×d×DN×DN \times d \times d \times D \to N \times D23.9× vs. FlashAttention2
  • SageAttention2++(8+8) (INT8 N×d×d×DN×DN \times d \times d \times D \to N \times D3, FP8 N×d×d×DN×DN \times d \times d \times D \to N \times D4): N×d×d×DN×DN \times d \times d \times D \to N \times D53.0×

Consistent gains were observed for both causal and non-causal masks. End-to-end metrics for representative models:

Model Attention Variant Perplexity or Metric (Delta vs FP32)
Llama3.1(8B) (language) Full-prec Ppl 6.013
SageAttn2 Ppl 6.019
SageAttn2++(8+8) Ppl 6.020
CogvideoX(2B) textN×d×d×DN×DN \times d \times d \times D \to N \times D6video Full-prec CLIPSim 0.179 / FScore 4.974
SageAttn2(8+8) CLIPSim 0.178 / FScore 4.899
SageAttn2++(8+8) CLIPSim 0.179 / FScore 4.386
Flux/StableDiffusion3.5 textN×d×d×DN×DN \times d \times d \times D \to N \times D7image Full-prec vs SageAttn2++ N×d×d×DN×DN \times d \times d \times D \to N \times D80.5 FID, N×d×d×DN×DN \times d \times d \times D \to N \times D90.02 sFID

Across language, image, and video models, SageAttention2++(8+8) matches SageAttention2's metrics, while (4+8) variant incurs only slight degradation.

5. Architectural Integration and Implementation

SageAttention2++ functions as a drop-in replacement for the DD0 kernel in FlashAttention-style fused kernels. Two new CUDA kernels (for the two quantization modes) are required, invoked in lieu of torch.flash_attn(). Hardware compatibility mandates support for mma.f16.f8.f8.f16 instructions (Ada Lovelace or later GPUs) and sufficient shared memory for quantized DD1 blocks; tiling follows FlashAttention conventions.

FP8 matmuls introduce two implementation caveats:

  • FP16 accumulation range (DD2) requires range-narrowing and block-wise scale factors.
  • Delayed FP32 buffering maintains efficiency but needs careful PTX scheduling.

6. Conclusions and Future Directions

SageAttention2++ demonstrates that employing FP16-accumulating FP8 MatMul, together with well-designed quantization bounds and FP16 buffering, can yield up to 4× kernel throughput improvements with negligible accuracy loss. Evaluations on tasks spanning language modeling, image generation, and video synthesis reveal up to a 3.9× reduction in kernel latency relative to FlashAttention2 while maintaining nearly identical performance metrics as SageAttention2.

Areas proposed for future investigation include:

  • Lower-bit accumulation, such as FP4DD3FP8DD4FP16 chains
  • Dynamic range adaptation per token/block for improved quantization efficiency
  • Integration with sparse or linear attention paradigms
  • Exploiting new hardware instructions (e.g., Hopper asynchronous FP8)

The reference implementation is slated for release at https://github.com/thu-ml/SageAttention (Zhang et al., 27 May 2025).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to SageAttention2.