[DFlash2] Keep the greedy selector walk in range for all-NaN score rows (#41737)

Co-authored-by: Rahul Chalamala <22563365+rchalamala@users.noreply.github.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
rodamani
2026-10-05 14:29:13 -07:00
committed by GitHub
co-authored by Rahul Chalamala Devin AI
parent 57826a62ea
commit c765f8818a
2 changed files with 29 additions and 2 deletions
@@ -271,8 +271,12 @@ def _selector_walk_kernel(
tl.float32
)
if greedy:
best = tl.max(scores, axis=0)
index = tl.min(tl.where(scores == best, offsets, top_k), axis=0)
# Same pick as torch.argmax: the first NaN if any, else the first max.
is_nan = scores != scores
best = tl.max(tl.where(is_nan, -float("inf"), scores), axis=0)
has_nan = tl.max(is_nan.to(tl.int32), axis=0) > 0
hit = tl.where(has_nan, is_nan, scores == best)
index = tl.min(tl.where(hit, offsets, top_k), axis=0)
probabilities = tl.where(offsets == index, 1.0, 0.0)
else:
scaled = scores / temperature