[Bugfix][Spec Decode] Fix NaN handling in rejection sampler tl.argmax (#50183)
Signed-off-by: Gabriel Peracio <gabriel@sigsonic.com> Co-authored-by: Kimi K3 <noreply@moonshot.ai>
This commit is contained in:
co-authored by
Kimi K3
parent
d36f24b66a
commit
47a4e410ba
@@ -108,6 +108,8 @@ def _compute_global_target_argmax(
|
||||
mask=blocks_mask,
|
||||
other=float("-inf"),
|
||||
)
|
||||
# See _insert_resampled_kernel: NaN breaks tl.argmax index bounds.
|
||||
local_max = tl.where(local_max != local_max, float("-inf"), local_max)
|
||||
max_block_idx = tl.argmax(local_max, axis=0)
|
||||
return tl.load(
|
||||
target_local_argmax_ptr + logit_idx * target_local_argmax_stride + max_block_idx
|
||||
@@ -849,6 +851,14 @@ def _insert_resampled_kernel(
|
||||
mask=mask,
|
||||
other=float("-inf"),
|
||||
)
|
||||
# NaN max values (from NaN target logits) make tl.argmax return an
|
||||
# out-of-range block index (into the padded region), causing an OOB read
|
||||
# of resampled_local_argmax. Map NaN to -inf so argmax stays in range.
|
||||
resampled_local_max = tl.where(
|
||||
resampled_local_max != resampled_local_max,
|
||||
float("-inf"),
|
||||
resampled_local_max,
|
||||
)
|
||||
resampled_max_block_idx = tl.argmax(resampled_local_max, axis=0)
|
||||
resampled = tl.load(
|
||||
resampled_local_argmax_ptr
|
||||
|
||||
Reference in New Issue
Block a user