P-Cast Precision in FP8 Attention: Sink-Induced Collapse and the Optimality of S=2^8
Organizations: Tencent
Abstract
FP8 (E4M3) acceleration for attention computation offers significant throughput gains, but the 3-bit mantissa introduces precision challenges when the softmax probability matrix~ is cast to FP8 before the matrix multiplication. We analyze two implementation choices that affect output precision under the \emph{Attention Sink} phenomenon: (1)~the KV block iteration order, and (2) the static scaling factor applied to before casting. We show that forward KV iteration causes \emph{P-collapse} -- to leading order a fraction of non-sink values underflow to zero, where the small shift (for ) is the expected within-sink-block score maximum -- and that reverse iteration removes it, with a zero-underflow guarantee when reverse is combined with . We further give a constructive characterization of as the static scale that simultaneously satisfies (i)~bit-exact IEEE 754 scaling, (ii) the lower envelope of a sawtooth function over the E4M3 number line (, the minimum worst-case quantization step), and (iii)~the maximum normal-range coverage \emph{among bit-exact () scales} (a non-bit-exact scale such as attains slightly higher coverage; sec.5}). Both optimizations are already deployed in FlashAttention-3/4 on engineering grounds; our contribution is a quantitative account of \emph{why} these choices are good and a closed-form threshold for predicting kernel-level precision loss. Kernel-faithful experiments ( in FP32 to isolate the P-cast effect) show - MSE improvement at moderate sink strengths, and paired tests confirm both fixes saturate to the same precision floor when combined -- which motivated updating the hpc-ops kernel from to .