Fix top-k ternary search timeout fallback producing inconsistent pivot/stats in Triton kernel#10
Draft
zhenwei-intel with Copilot wants to merge 2 commits into
Draft
Fix top-k ternary search timeout fallback producing inconsistent pivot/stats in Triton kernel#10zhenwei-intel with Copilot wants to merge 2 commits into
zhenwei-intel with Copilot wants to merge 2 commits into
Conversation
Copilot
AI
changed the title
[WIP] Fix correctness bug in top-k ternary search fallback
Fix top-k ternary search timeout fallback producing inconsistent pivot/stats in Triton kernel
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The top-k ternary search in
_topk_topp_kernelhad a correctness bug in its timeout/range-collapse fallback:k_pivotwas set to a fresh midpoint never evaluated during the search, whilemin_larger/num_min_largerpointed atk_pivot_0(1/3-position) andk_pivots_numretained its initial value of0. This broke the invariant that all four values must describe the same threshold, causing uint32 underflow innum_keepand incorrect surviving-token counts when tied logits exist near the truncation boundary.Changes
vllm/v1/sample/ops/topk_topp_triton.pyk_pivot_1whenk_pivots_num_1 >= k, otherwise usek_pivot_0. All four variables (k_pivot,k_pivots_num,min_larger,num_min_larger) are now assigned together from the same evaluated pivot:num_keepcomputation: guard against uint32 underflow withtl.where:tests/v1/sample/test_topk_topp_sampler.pytest_topk_tied_logits_exact_count(parametrized overk∈{5,10,20}): constructs inputs wherek+50tokens share identical logit values, forcing the search interval to collapse and the fallback branch to fire. Asserts surviving-token count exactly matches the PyTorch reference implementation.