Repository navigation
[Perf][Kernel] Size cooperative_topk's single pass by row length, not stride - #62171
Merged
tlrmchlsmth merged 4 commits intoOct 23, 2026
Merged
Conversation
haosdent
requested review from
AndreasKaratzas,
WoosukKwon,
mgoin,
tlrmchlsmth,
yewentao256 and
zyongye
as code owners
October 17, 2026 10:46
This was referenced Oct 17, 2026
haosdent
marked this pull request as draft
October 17, 2026 10:56
haosdent
commented
Oct 18, 2026
| // staging. | ||
| const uint32_t per_block = | ||
| (params.stride + CS - 1) / CS; // how many elements per block | ||
| ((static_cast<uint32_t>(sl) + 3) / 4 + CS - 1) / CS * 4; |
Contributor
Author
There was a problem hiding this comment.
Could be
(static_cast<uint32_t>(sl) + CS - 1) / CS
haosdent
marked this pull request as ready for review
October 18, 2026 05:46
This was referenced Oct 19, 2026
LopezCastroRoberto
approved these changes
Oct 22, 2026
LopezCastroRoberto
left a comment
Contributor
There was a problem hiding this comment.
LGTM, thanks!
… stride cooperative_topk chose between its single-pass (all TMA stages resident) and two-pass streaming paths from the logits row stride. The indexer's decode logits are allocated with max_model_len columns, so with a long max_model_len every row streamed twice even when its context fit the single-pass staging. Size the decision by the row's own length, the way large_topk already partitions it. Signed-off-by: haosdent <haosdent@gmail.com>
kFusedMax and kSizePerStage are multiples of the 16-byte TMA unit, so rounding the per-block length up to that unit (as large_topk splits the row) picks the same path and stage count. Signed-off-by: haosdent <haosdent@gmail.com>
Signed-off-by: haosdent <haosdent@gmail.com>
haosdent
force-pushed
the
perf/cooperative-topk-row-length
branch
from
October 23, 2026 11:30
fe1f9c9 to
4aa3313
Compare
|
✅ @haosdent, CI is now available for this PR.
|
Contributor
|
/ci run |
|
✅ Triggered Buildkite CI #96880 for commit |
tlrmchlsmth
approved these changes
Oct 23, 2026
bantianyue
pushed a commit
to bantianyue/vllm
that referenced
this pull request
Oct 28, 2026
… stride (vllm-project#62171) Signed-off-by: haosdent <haosdent@gmail.com> Co-authored-by: Roberto L. Castro <38211239+LopezCastroRoberto@users.noreply.github.com>
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.
Overview
cooperative_topknow chooses between its single-pass and two-pass paths from each row's length instead of thelogits row stride. Rows that fit the single-pass staging no longer stream through TMA twice just because the
buffer is wide (
max_model_len).Claims
drops 2.8%, 2.5%, 1.5% and 1.5% at concurrency 1, 4, 8 and 16 (main vs main: within 0.7%). This PR is
about half of that.
than the per-block staging, for example
max_model_len1M at 1-8 rows, or about 200K at 9-64 rows.Validation
tests/kernels/test_top_k_per_row.py: 265 passed, 37 skipped on GB200 (SM100); after rebasing onto [Bugfix] Make cooperative TopK exact on candidate overflow #59645'soverflow recovery, 402 passed, 44 skipped on B300 (SM103). The new
test_cooperative_topk_rows_shorter_than_stridecovers every cluster size (1, 4, 8, 33 and 64 rows) with strides of 64K and 1M and rows of 300 to 300K tokens, so
one launch mixes trivial, register, single-pass and streaming rows. It compares the selected values with
torch.topk.InferenceX AgentX, GLM-5.3-NVFP4 on 4x GB200, main + [Perf] Emit the DSA indexer weights in BF16 on SM100 #62170, [Perf][Kernel] Size cooperative_topk's single pass by row length, not stride #62171 and [Perf][Kernel] Let cooperative_topk read the BF16 indexer logits #62172 vs main (median per-turn change
on the same turns, 95% CI; setup below):
cooperative_topkmicrobenchmark, k=2048, rows = requests x 4 (MTP), CUDA graph replay, B300:Target verify forward (
vllm bench forward, GLM-5.2-NVFP4, TP4, B300, MTP verify shapes, spread < 0.1%), on topof [Perf] Emit the DSA indexer weights in BF16 on SM100 #62170: -0.58% to -1.36% at 1, 3 and 7 requests, 25K and 94K context.
Exactness: with real MTP verification on 32 GSM8K questions (greedy), the three changes together give the same
outputs and the same acceptance length (3.4904) as main.
MRCR (8 needles, 4K to 256K, 594 samples), GLM-5.3-NVFP4 on 4x GB200, greedy: main 0.903, with [Perf] Emit the DSA indexer weights in BF16 on SM100 #62170,
[Perf][Kernel] Size cooperative_topk's single pass by row length, not stride #62171 and [Perf][Kernel] Let cooperative_topk read the BF16 indexer logits #62172 0.890; paired difference -0.013 [-0.038, +0.012], and every bin's CI includes zero. The
256K bin, run three times each: -0.019 [-0.069, +0.031].
InferenceX AgentX setup and results for all GLM-5.3 PRs (4x GB200)
InferenceX c801c9f2d AgentX scenario (pinned AIPerf), 20-minute fast mode, GLM-5.3-NVFP4 rev e3b8f9f2, TP4, MTP 3
with synthetic acceptance 2.99, native KV offload 135 GB per rank, Rust frontend,
max-num-seqs= 2 xconcurrency. vLLM main dcd0796 with its default backends and CUDA graph config, plus the PRs cumulatively in
the order below (FlashInfer with flashinfer-ai/flashinfer#6630, flashinfer-ai/flashinfer#6631 and
flashinfer-ai/flashinfer#6632 from #62174 on). One FlashInfer MoE autotune per concurrency, shared by all
variants. A fresh server per point, with the page cache dropped before each, and main run again at the end of
each concurrency as an A/A check. SGLang a916d91cd3 with IMEX, TRT-LLM
all-reduce fusion and
--mem-fraction-static 0.90.Each cell is the median, over the turns both runs finished (150 to 520), of the per-turn ratio to the previous
variant, with a 95% paired bootstrap CI. Decode is request latency minus TTFT. The bootstrap does not include
run-to-run variance; the main-vs-main row does.
KV cache tokens per GPU (c=1 / 4 / 8 / 16): main 1,176,832 / 1,162,880 / 1,143,872 / 1,105,984; with all PRs
1,178,496 / 1,168,512 / 1,157,824 / 1,103,936. Window throughput (tok/s/GPU) moves up to 2.4% between runs in fast
mode, since it counts whichever long-context turns finish inside the 20 minutes; with all PRs it is +3.0%, -1.4%,
+4.8% and +1.2% at c=1/4/8/16.
vLLM vs SGLang, decode time per turn on the same turns (positive = vLLM slower):
#62170, #62171 and #62172 were measured as one group.
vllm bench forward(target verify forward, spread < 0.1%)splits their gain about 1/6, 1/2 and 1/3. #62173 changes only decode steps of 3, 5 or 7 requests; steps with 3 or
more requests are 0%, 4%, 13% and 37% of all steps at c=1/4/8/16. At c=1 both runs capture the same graphs, so
its +0.5% there is noise. At c=16, three more runs each of + #62174 and + #62173 (4 runs each, compared as
runs): decode time -0.54% [-0.93, -0.16], with every + #62173 run faster than every + #62174 run (permutation
p = 2/70); e2e latency -0.29% [-1.41, +0.82].
Details
The DSA indexer allocates its decode logits with
max_model_lencolumns, andcooperative_topkgets that asstride. The kernel sizedper_block(elements per CTA of the cluster) from the stride. Butlarge_topksplitsthe row by its actual length (
seq_len, in 16-byte units across the cluster ranks). With a longmax_model_len,every row took the two-pass streaming path even when its context fit the all-stages-resident single pass. For
example, 16 rows use 4-CTA clusters, and a 256K stride gives 64K elements per block, above the 48K single-pass
staging, while a 40K-token row needs only 10K per block.
per_blockis nowceil(seq_len / CS), so each row picks its path from its own length.large_topkrounds eachblock to 16-byte units, but the single-pass limit and the stage size are multiples of that unit, so this gives the
same path and stage count as the exact split. Rows in one launch can take different paths. Each row is its own
cluster, and the barrier setup already follows the chosen path.
Pull Request Checklist
I used vLLM's
/pr-checklistskill. (Mandatory for agents, optional for humans).AI assistance was used during the creation of this PR.
Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.
Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.
Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.
Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.