[论文解读] Attn-QAT: 4-Bit Attention With Quantization-Aware Training
本文提出 Attn-QAT,一种针对注意力的 4 位量化感知训练方法,在稳定训练的前提下实现 FP4 注意力与 BF16 级模型质量,并在 RTX 5090 上获得 1.1x–1.5x 的吞吐量提升。
Achieving reliable 4-bit attention is a prerequisite for end-to-end FP4 computation on emerging FP4-capable GPUs, yet attention remains the main obstacle due to FP4's tiny dynamic range and attention's heavy-tailed activations. This paper presents the first systematic study of 4-bit quantization-aware training (QAT) for attention. We find that "drop-in" QAT, which naively combines an FP4 forward pass with a high-precision Flash Attention (FA)-style backward pass, leads to training instability. We identify two key principles for stable FP4 attention: (1) matching low-precision recomputation of attention scores in the backward pass, and (2) resolving implicit precision assumptions in FA's gradient calculation. Based on these insights, we propose Attn-QAT and implement fused Triton kernels for training as well as FP4 inference kernels. Across diffusion and language models, Attn-QAT recovers the quality drop from FP4 attention without explicit outlier-mitigation heuristics used in prior FP4 attention, and delivers up to a 1.5x speedup on an RTX 5090. Video demos can be found at https://drive.google.com/drive/folders/190F6xbBDUF2kGQYIcXBt3ehSYij5jlim?usp=sharing.
研究动机与目标
- 证明需要 4 位注意力以在具备 FP4 能力的 GPU 上实现端到端的 FP4 计算的必要性。
- 研究为什么现有反向传播下的天真 FP4 注意力会不稳定。
- 明确稳定 FP4 注意力在 QAT 过程中的精度协同要求。
- 提出具有专门前向/后向精度处理和内核的 Attn-QAT。
- 证明 Attn-QAT 在扩散模型和语言模型中恢复质量,并带来性能提升。
提出的方法
- 分析 FP4 注意力中的两大挑战:极为粗糙的数值范围和重尾激活。
- 将量化感知训练改造成 FlashAttention 风格的融合算子,通过前向传播模拟 FP4 并保持高精度梯度。
- 确保反向传播重计算的注意力得分与前向传播使用相同的低精度。
- 提供高精度的辅助输出以实现正确的 softmax 梯度计算。
- 实现用于训练的前向和反向 Triton 内核,以及用于部署的 FP4 推理内核。

实验结果
研究问题
- RQ1量化感知训练是否能在 FP4 中稳定 4 位注意力,同时保持模型质量?
- RQ2前向与反向传播之间需要怎样的精度协同,以使 FP4 注意力与 FlashAttention 风格后端对齐?
- RQ3Attn-QAT 是否在扩散模型和语言模型中恢复 BF16 质量,并且与 SageAttention3 相比如何?
- RQ4在现代 GPU 上使用 FP4 注意力可以达到何种吞吐量提升?
主要发现
- Attn-QAT 能恢复因 FP4 注意力而导致的质量损失,在评估指标上达到与 BF16 相当的表现。
- QA 结果显示 Attn-QAT 优于 SageAttention3,并消除了对离群值抑制启发式方法的需求。
- 训练稳定性依赖于两项设计选择:(1) 前向传播中对注意力得分的重计算使用 FP4;(2) 用高精度输出实现准确的 softmax 梯度。
- 在 RTX 5090 上,FP4 注意力下 Attn-QAT 相较于 SageAttention3 提供约 1.1x–1.5x 的速度提升。
- 在大模型继续训练中,Attn-QAT 在 Qwen3-14B 上恢复了近 BF16 的性能,在 llama3.1-70B 上部分恢复,仍有通过更长训练进一步提升的空间。
- 内核基准测试显示 Attn-QAT 的前向输出在 Triton 训练内核与 CUDA 推理内核之间几乎完全一致。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。