[Bugfix][Attention] Preserve small FP8 softmax weights in Triton attention (#60156)
Signed-off-by: Andy Lo <andy@mistral.ai>
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user