[Bugfix][Attention] Preserve small FP8 softmax weights in Triton attention (#60156)

Signed-off-by: Andy Lo <andy@mistral.ai>
This commit is contained in:
Andy Lo
2026-10-08 12:35:22 +02:00
committed by GitHub
parent e161a0798c
commit ba77c4c130
2 changed files with 56 additions and 1 deletions
@@ -586,7 +586,15 @@ def kernel_unified_attention(
P_v = (P * v_token_head_scales[None, :]).to(V.dtype)
acc += tl.dot(P_v, V)
else:
acc += tl.dot(P.to(V.dtype), V)
# Keep softmax weights representable when the P @ V dot uses FP8
# tensor cores. Undo the power-of-two scale after the dot.
if V.dtype == tl.float8e4nv:
p_scale = 256.0
elif V.dtype.is_fp8():
p_scale = 128.0
else:
p_scale = 1.0
acc += tl.dot((P * p_scale).to(V.dtype), V) / p_scale
# ---- Epilogue ---------------------------------------------------------
if IS_3D: