Attn-QAT: 4-Bit Attention With Quantization-Aware Training
Abstract
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 ``drop-in'' QAT -- naively combining an FP4 forward pass with 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 plus 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.
Lay Summary
Modern AI models can generate text, images, and videos, but running them is expensive because they require large amounts of computation and memory. Using 4-bit numbers can reduce this cost, but an important part of these models, attention, often loses quality under such aggressive compression. In this work, we show how to make 4-bit attention reliable. Instead of simply compressing a trained model, we let the model adapt to 4-bit computation through a short additional training stage. We also identify two changes needed to keep this training stable and implement efficient GPU kernels for the method. Our method preserves the quality of full-precision attention across video generation and language models while making attention faster on modern GPUs. This can help reduce the cost and energy needed to serve large AI models.