[Bugfix] Prevent NaN poisoning in xpu_mla_sparse for fully-masked index chunks (#48366)
Signed-off-by: Nick Iusiumbeli <nickuspro@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Kunshang Ji <kunshang.ji@intel.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
Kunshang Ji
parent
fdaa0d9e59
commit
f0553889c0
@@ -73,7 +73,10 @@ def _bf16_mla_sparse_kernel(
|
||||
q_buffer + off_qpe, mask=(mask_h[:, None]) & (mask_dpe[None, :]), other=0.0
|
||||
)
|
||||
|
||||
e_max = tl.zeros([BLOCK_H], dtype=tl.float32) - float("inf")
|
||||
# Use a finite sentinel rather than -inf: if every key in a chunk is
|
||||
# masked (e.g. leading -1 padding in `indices`) an -inf running max gives
|
||||
# re_scale = exp2(-inf - -inf) = NaN, permanently poisoning acc / e_sum.
|
||||
e_max = tl.zeros([BLOCK_H], dtype=tl.float32) - 1.0e30
|
||||
e_sum = tl.zeros([BLOCK_H], dtype=tl.float32)
|
||||
acc = tl.zeros([BLOCK_H, BLOCK_DV], dtype=tl.float32)
|
||||
|
||||
@@ -122,7 +125,7 @@ def _bf16_mla_sparse_kernel(
|
||||
|
||||
# apply scaling
|
||||
qk *= sm_scale
|
||||
qk = tl.where((mask_h[:, None]) & (mask_kv[None, :]), qk, -float("inf"))
|
||||
qk = tl.where((mask_h[:, None]) & (mask_kv[None, :]), qk, -1.0e30)
|
||||
|
||||
# load v
|
||||
mask_v_d = offs_dv < dim_v
|
||||
|
||||
Reference in New Issue
Block a user