Conversation
Filter long FP32 rows with a sampled cutoff and retain exact radix selection when the bounded candidate buffer underfills or overflows. Use measured per-row cutoffs and reuse the existing selector for shorter runtime rows. Preserve cooperative decode dispatch and add graph-replay correctness coverage with a standalone CUPTI benchmark. Co-authored-by: OpenAI Codex <noreply@openai.com> Signed-off-by: mgoin <mgoin64@gmail.com>
mgoin
requested review from
AndreasKaratzas,
WoosukKwon,
tlrmchlsmth,
yewentao256 and
zyongye
as code owners
September 10, 2026 21:15
Member
Author
|
/ci run |
|
✅ Triggered Buildkite CI #88352 for commit |
Member
Author
|
/ci run |
|
✅ Triggered Buildkite CI #88691 for commit |
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.
Purpose
Speed up long FP32 sparse-indexer decode top-k with sampling inspired by DeepSelect. A coalesced sample estimates a cutoff, survivors are compacted in shared memory, and exact FP32 selection finishes on those candidates. Too few or too many candidates trigger exact full-row selection.
Enable sampling above 64 rows, with actual valid length ≥98,304 for k=512 or ≥65,536 for k=1024/2048, and at least 144 KiB opt-in shared memory. Shorter runtime rows reuse the existing selector within the same launch. These conservative bounds come from the fine B300 sweep below.
The plot forces sampling to expose the crossover; it shows the minimum speedup across measured batches, allocations, seeds and cache modes. The k=512 slowdown near 80K–86K motivates its later cutoff.
Final dispatch improves every tested case entirely within the sampling region. At B=1024 with 80–100% ragged lengths, warm latency drops 316.58→207.06 µs at 128K/k=2048 and 584.45→301.72 µs at 256K/k=512. Short-row fallback can add up to 3.32%; the largest absolute increase measured was 1.215 µs. Performance validation is B300-only.
Duplicate checks found no open PR implementing this sampled filter: #44606 tunes existing dispatch, #55872 adds a FlashInfer backend, and #55314 fixes existing stash overflow. That overflow remains outside the new path. Prefill is unchanged.
Test Plan
Added graph-replay correctness coverage and
benchmarks/kernels/benchmark_persistent_topk.pyfor full/ragged lengths and warm/cold L2. All GPU runs usedchgreservations and source-built baseline/candidate libraries.Local validation commands run
The wrappers load the isolated candidate library and invoke
tests/kernels/test_top_k_per_row.py.chg run -- .venv/bin/python benchmarks/results/topk_sweep_20260910/run_tests.py chg run -- .venv/bin/python benchmarks/results/topk_sweep_20260910/run_tests96.py \ -k "sampled_graph or workspace_topk or reused_group" chg run -- .venv/bin/python benchmarks/results/topk_sweep_20260910/run_tests96.py -k sampled_graph chg run -- compute-sanitizer --tool memcheck --error-exitcode 1 \ .venv/bin/python benchmarks/results/topk_sweep_20260910/sanitize96.py chg run -- compute-sanitizer --tool synccheck --error-exitcode 1 \ .venv/bin/python benchmarks/results/topk_sweep_20260910/sanitize96.py --fallback .venv/bin/pre-commit run --files csrc/libtorch_stable/{sampled_topk.cuh,persistent_topk.cuh,topk.cu} \ benchmarks/kernels/benchmark_persistent_topk.py tests/kernels/test_top_k_per_row.pyTest Result
AI assistance was used for implementation, benchmarking, tests and analysis.