Repository navigation
cuda sampler: the fallback selects and sorts min(top_k, 1024) candidates (fixes #3712) - #4099
Merged
Merged
Conversation
ashhart
force-pushed
the
lead/issue-3712-sampler-fallback-topk
branch
from
November 19, 2026 23:24
e2750dc to
9222969
Compare
ashhart
force-pushed
the
lead/issue-3712-sampler-fallback-topk
branch
from
November 20, 2026 05:42
9222969 to
133b93c
Compare
ashhart
added a commit
that referenced
this pull request
Nov 20, 2026
This was referenced Nov 20, 2026
…24) candidates (fixes #3712)
ashhart
force-pushed
the
lead/issue-3712-sampler-fallback-topk
branch
from
November 20, 2026 16:21
133b93c to
bd67abc
Compare
ashhart
added a commit
that referenced
this pull request
Nov 20, 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.
What this changes
In the CUDA sampler's fallback (no window near the max holds the rule's tokens),
first_blockaskedtop_keysfor 1,024 candidates and sorted all of them even whentop_kis small. It now asks formin(top_k, C)and sizes the bitonic sort to that count (at least 32).top_k == 0ortop_k > Ckeeps the full block.Tokens and probabilities stay the same: the
top_klargest keys with the id tie cut are the same set whichever counttop_keysis asked for, the sort order (value desc, id asc) is unchanged,pick()reads onlymin(n_cand, top_k)of them, and the nucleus path's cut is bounded by the same top-k mark either way.Checks on this head
zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu: passed (compiles the CUDA tests for Linux; no GPU run).tf-cuda-test sampleon a GB10 (the flat, tie, peaked and spread rows at top_k 1, 20, 40 and more inzig/tests/cuda/sample_tests.zig) runs on the landing train's GB10 cell before this lands.