Skip to content

[Bugfix] Handle persistent top-k candidate overflow - #52149

Open
xijiaat wants to merge 8 commits into
vllm-project:mainfrom
xijiaat:codex/fix-persistent-topk-overflow
Open

xijiaat wants to merge 8 commits into
vllm-project:mainfrom
xijiaat:codex/fix-persistent-topk-overflow

Conversation

@xijiaat

@xijiaat xijiaat commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Purpose

This is a broad, real-model-triggerable correctness fix for
persistent_topk: candidate-buffer overflow can silently degrade attention
accuracy, and the fix introduces no material performance regression in the
measured kernel and end-to-end workloads.

Fixes #51782.

Impact: This is not limited to synthetic logits. It reproduced end to end
on stock vLLM v0.27.0 with nvidia/GLM-5.2-NVFP4
(GlmMoeDsaForCausalLM, index_topk=2048). A real 134,249-token
MRCR 2-needle prompt submitted as 33 sequences dispatched
persistent_topk (rows=33, width=262144, k=2048) and
silently returned wrong top-k values in up to 27/33 rows, with up to
2,042/2,048 wrong selected values in one row and a maximum score delta of
6.5967. Replaying the same six captured runtime tensors through this PR three
times each produced zero mismatches. Longer contexts make overflow increasingly
relevant because more candidates can collide in a coarse histogram bin.
Reproduction commands and core evidence;
raw logs and tensors.

After extracting glm52_real_overflow_20260816_raw_logs.tgz, the silent stock
failures can be located directly in the retained correctness logs:

# Stock v0.27.0: expected two matches, both `"bad_rows": 27`.
grep -RHnEo --include='*.captured-stock.log' \
  '"bad_rows"[[:space:]]*:[[:space:]]*[1-9][0-9]*' \
  results/

# Final PR replay: expected no match across all 18 replay logs.
if grep -RHnE --include='*.fixed.run*.log' \
  '"replayed_kernel".*"bad_rows"[[:space:]]*:[[:space:]]*[1-9][0-9]*' \
  results/fixed-replay/; then
  echo 'FAIL: fixed replay contains bad rows'
  exit 1
else
  echo 'PASS: no fixed replay contains bad rows'
fi

persistent_topk uses fixed-size candidate buffers in several optimized
dispatch paths. When many scores map to the same coarse histogram bin, those
buffers can overflow. The counters keep increasing while excess candidates
are dropped, so the kernel returns valid, unique indices that are not the true
top-k values.

This change:

  • detects candidate-buffer overflow in the short, persistent-decode,
    persistent-medium, and filtered-large paths;
  • falls back to a bounded-memory exact FP32 radix rescan of the full row;
  • reuses first-stage counts to skip collection passes that are guaranteed to
    overflow and be discarded;
  • uses an 11-bit ordered-FP16 coarse histogram for long filtered rows and an
    exact 11 + 11 + 10 FP32 fallback when their candidate buffer overflows;
  • overlays the wider histogram and CUB scan storage on the existing 128 KiB
    dynamic shared-memory allocation;
  • preserves the existing dispatch structure, 1 MiB workspace contract, and
    dynamic shared-memory launch contract;
  • adds a regression matrix covering all four dispatch paths and
    k = 512, 1024, 2048.

Algorithm provenance

The long-row radix structure is intentionally aligned with NVIDIA
TensorRT-LLM's production indexer Top-K selector. Its source explicitly uses a
half - 11 - 11 - 10 bit exact selection sequence and a CUB block scan:

This PR independently adapts that radix decomposition to vLLM's existing
filtered kernel and adds a bounded-memory exact overflow fallback; it does not
copy the TensorRT-LLM kernel. It also does not implement GVR: GVR requires
previous-step Top-K state and interface changes, which are outside this focused
correctness fix.

Exact overflow handling and optimization

Stock v0.27.0 has no exact overflow fallback: overflowing the fixed candidate
buffer can silently drop candidates and return an incorrect top-k set. This PR
detects overflow and reruns exact bounded-memory selection.

  1. Long filtered rows. An ordered-FP16 2048-bin coarse histogram reduces
    overflow frequency. If overflow remains, exact FP32 selection uses three
    full-row radix passes (11 + 11 + 10 bits), preserving the dispatch
    VecSize (float, float2, or float4) and its scalar ragged tail.
  2. Decode and medium rows. Their exact fallback uses four 8-bit FP32 radix
    passes and emits values above or equal to the pivot in one fused output
    scan. Tie handling remains exact.
  3. Short histogram rows. Their exact fallback uses four 8-bit FP32 radix
    passes followed by the shared greater-than/equal-to-pivot collectors.
  4. Shared traversal logic. Scalar and vectorized scans use
    for_each_score, while pivot collection is shared through
    collect_pivot_matches.
  5. No additional per-CTA shared memory. The coarse histogram, exact
    histogram, and candidate buffers reuse the existing 128 KiB dynamic shared
    memory allocation.

Test plan

  1. Reproduce the bug with the vLLM v0.27.0 installed kernel on narrow score
    distributions across all persistent-top-k dispatch paths.
  2. Compile the patched headers into a CUDA extension against the same v0.27.0
    image; no vLLM, CUDA, PyTorch, or kernel version was upgraded.
  3. For each case, compare the selected-value multiset exactly with
    torch.topk, and validate index range and uniqueness.
  4. Run five independent 87-case correctness matrices, with 10 kernel
    repetitions per case, on one NVIDIA B300 (SM 10.3, CUDA 13.0,
    PyTorch 2.13.0+cu130).
  5. Exercise exact capacity - 1, capacity, capacity + 1, and
    2 * capacity boundaries, VecSize = 1/2/4, ragged tails, 131K all-tie
    rows, 200 repeated launches, and 200 CUDA Graph replays.
  6. Run the focused pytest regression in tests/kernels/test_top_k_per_row.py.
  7. Compare the reviewer-requested traversal refactor against the immediately
    preceding correct implementation with five independent paired seeds. Each
    case uses 600 CUDA-event samples, 20 launches per sample, 100 warmups,
    5,000 bootstrap resamples, and alternating implementation order.

Correctness result

Implementation Independent matrices Case executions Failing case executions Bad rows
Original v0.27.0 3 261 201 7,060
Final PR head 5 435 0 0

The final PR head produced zero selected-value mismatches (rtol=0,
atol=0) across all 435/435 executions, with zero invalid indices
and zero duplicate-index rows. All targeted boundary, all-tie, ragged-row,
vector-width, repeated-launch, and CUDA Graph cases passed.

Performance result

The primary comparison is stock vLLM v0.27.0 versus the final refactored PR
head. The stock overflow path returns incorrect top-k values, so its
standalone overflow-kernel latency is not a quality-equivalent baseline.

The reviewer-requested traversal-only refactor was also measured directly
against the immediately preceding correct implementation. Across the measured
long/short control and overflow cases, five paired runs stayed within
±0.05%, so no additional refactor-specific speedup is claimed. Full-model
final-versus-stock results are reported below.

Reproduce commands

Build vLLM from this PR head, then run the checked-in overflow regression:

pytest -sv \
  tests/kernels/test_top_k_per_row.py::test_persistent_topk_candidate_buffer_overflow

The standalone reproducer is intentionally kept outside this PR. After
extracting the final-refactor artifact linked below, run these commands from
its standalone_reproducer/ directory:

# Installed v0.27.0 baseline.
python3 repro_persistent_topk.py \
  --backend persistent --full --repeats 20

# PR headers compiled into the isolated extension.
TORCH_CUDA_ARCH_LIST=10.3 MAX_JOBS=4 \
PATCHED_TOPK_SOURCE="$PWD/patched_persistent_topk_ext.cu" \
PATCHED_TOPK_INCLUDE="$PWD" \
python3 repro_persistent_topk.py \
  --backend overflow-extension --full --repeats 20

Three-run full-model validation

Key result: the final PR head fixes all observed correctness failures with
no material performance regression in the measured workloads. Compared with
stock vLLM v0.27.0, C33 median TPOT decreased by 4.14% and output
throughput increased by 6.02%. C1 remained effectively unchanged.

The baseline was unmodified vLLM v0.27.0 and the candidate was the final
refactored PR head. They used the same vLLM image, pinned model revision,
launch flags, CUDA Graph configuration, and one isolated NVIDIA B300 each.
Every formal benchmark was run three times; warmups were excluded.

Forced-overflow correctness, three runs

Binary Run Seed Witness failures Full-matrix failures Bad rows
Original v0.27.0 1 20260815 4/4 68/87 2,338
Original v0.27.0 2 20260816 4/4 68/87 2,358
Original v0.27.0 3 20260817 4/4 65/87 2,364
Final PR head 1 20260815 0/4 0/87 0
Final PR head 2 20260816 0/4 0/87 0
Final PR head 3 20260817 0/4 0/87 0

For all 12 targeted long-vector case/run pairs, the PR selected-value digest
exactly matched torch.topk (rtol=0, atol=0). All runs also had zero
invalid indices and zero duplicate-index rows.

CUDA Graph E2E, three runs

The server command used for both binaries was:

HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 PYTHONHASHSEED=0 \
VLLM_LOG_STATS_INTERVAL=1 \
vllm serve deepseek-ai/DeepSeek-V4-Flash \
  --revision 60d8d70770c6776ff598c94bb586a859a38244f1 \
  --served-model-name deepseek-ai/DeepSeek-V4-Flash \
  --host 127.0.0.1 --port 18080 \
  --trust-remote-code --tokenizer-mode deepseek_v4 \
  --kv-cache-dtype fp8 --block-size 256 \
  --gpu-memory-utilization 0.80 --max-model-len 262144 \
  --max-num-batched-tokens 8192 --max-num-seqs 33 \
  --enable-chunked-prefill --enable-prefix-caching \
  --no-disable-hybrid-kv-cache-manager \
  --attention-config '{"use_fp4_indexer_cache":true}' \
  --enable-prompt-tokens-details --enable-request-id-headers \
  --enable-log-requests --optimization-level 2 \
  --compilation-config \
    '{"cudagraph_mode":"FULL_AND_PIECEWISE","cudagraph_capture_sizes":[1,33]}' \
  --cudagraph-metrics --seed 2025

C1 command; execute three times with seeds 2025, 2026, and 2027 after
one excluded warmup:

vllm bench serve \
  --backend openai --base-url http://127.0.0.1:18080 \
  --endpoint /v1/completions \
  --model deepseek-ai/DeepSeek-V4-Flash \
  --dataset-name random \
  --random-input-len 135168 --random-output-len 1000 \
  --random-range-ratio 0.0 \
  --num-prompts 1 --num-warmups 0 \
  --max-concurrency 1 --request-rate inf \
  --seed 2025 --temperature 0 --ignore-eos \
  --save-result --save-detailed

C33 command; execute three times with seed 2025 after one excluded request
populates the exact same prefix:

vllm bench serve \
  --backend openai --base-url http://127.0.0.1:18080 \
  --endpoint /v1/completions \
  --model deepseek-ai/DeepSeek-V4-Flash \
  --dataset-name prefix_repetition \
  --prefix-repetition-prefix-len 131071 \
  --prefix-repetition-suffix-len 1 \
  --prefix-repetition-num-prefixes 1 \
  --prefix-repetition-output-len 1000 \
  --num-prompts 33 --num-warmups 0 \
  --max-concurrency 33 --request-rate inf \
  --seed 2025 --temperature 0 --ignore-eos \
  --save-result --save-detailed
Scenario Binary Run Input tokens Output tokens Median TTFT Median TPOT Wall Output throughput
C1 Original v0.27.0 1 135,168 1,000 8,808.34 ms 6.9693 ms 15.7711 s 63.41 tok/s
C1 Original v0.27.0 2 135,168 1,000 8,802.46 ms 6.9671 ms 15.7631 s 63.44 tok/s
C1 Original v0.27.0 3 135,168 1,000 8,849.35 ms 6.9703 ms 15.8131 s 63.24 tok/s
C1 Final PR head 1 135,168 1,000 8,789.19 ms 7.0167 ms 15.7993 s 63.29 tok/s
C1 Final PR head 2 135,168 1,000 8,786.93 ms 7.0130 ms 15.7933 s 63.32 tok/s
C1 Final PR head 3 135,168 1,000 8,805.57 ms 7.0162 ms 15.8152 s 63.23 tok/s
C33 Original v0.27.0 1 4,325,376 33,000 7,937.79 ms 18.8891 ms 30.8372 s 1,070.14 tok/s
C33 Original v0.27.0 2 4,325,376 33,000 7,968.25 ms 18.2539 ms 30.2109 s 1,092.32 tok/s
C33 Original v0.27.0 3 4,325,376 33,000 7,979.74 ms 18.6120 ms 30.6552 s 1,076.49 tok/s
C33 Final PR head 1 4,325,376 33,000 7,421.13 ms 17.8413 ms 28.9142 s 1,141.31 tok/s
C33 Final PR head 2 4,325,376 33,000 7,449.93 ms 18.3022 ms 29.3124 s 1,125.80 tok/s
C33 Final PR head 3 4,325,378 33,000 7,493.36 ms 17.7875 ms 28.6087 s 1,153.50 tok/s

Median of three formal runs:

Scenario Metric Original v0.27.0 Final PR head Delta
C1 TTFT 8,808.34 ms 8,789.19 ms -0.22%
C1 TPOT 6.9693 ms 7.0162 ms +0.67%
C1 Output throughput 63.41 tok/s 63.29 tok/s -0.18%
C33 TTFT 7,968.25 ms 7,449.93 ms -6.50%
C33 TPOT 18.6120 ms 17.8413 ms -4.14%
C33 Output throughput 1,076.49 tok/s 1,141.31 tok/s +6.02%

All six C33 formal runs completed 33/33 requests, generated exactly 33,000
output tokens, and reached vllm:num_requests_running=33 under 100 ms metric
sampling.

GLM-5.2-NVFP4 TP2 E2E, three runs

The same final refactor was also tested end to end with the real affected model,
nvidia/GLM-5.2-NVFP4 (index_topk=2048). Stock vLLM v0.27.0 and the final
PR head ran sequentially on the same isolated two B300 GPUs with identical TP2,
EP, FP8-KV, and CUDA Graph settings. Warmups were excluded.

VLLM_USE_V2_MODEL_RUNNER=1 VLLM_LOG_STATS_INTERVAL=1 \
vllm serve nvidia/GLM-5.2-NVFP4 \
  --served-model-name nvidia/GLM-5.2-NVFP4 \
  --host 127.0.0.1 --port 18080 --trust-remote-code \
  --tensor-parallel-size 2 --enable-expert-parallel \
  --moe-backend flashinfer_cutlass \
  --kv-cache-dtype fp8 --gpu-memory-utilization 0.90 \
  --max-model-len 262144 --max-num-batched-tokens 8192 \
  --max-num-seqs 64 --enable-chunked-prefill --enable-prefix-caching \
  --safetensors-load-strategy prefetch --enable-prompt-tokens-details \
  --enable-request-id-headers --enable-log-requests \
  --optimization-level 2 \
  --compilation-config \
    '{"cudagraph_mode":"FULL_AND_PIECEWISE","cudagraph_capture_sizes":[1,33]}' \
  --cudagraph-metrics --seed 2025

C1 was run three times with seeds 2025, 2026, and 2027 after one excluded
warmup:

vllm bench serve \
  --backend openai --base-url http://127.0.0.1:18080 \
  --endpoint /v1/completions --model nvidia/GLM-5.2-NVFP4 \
  --dataset-name random --random-input-len 135168 \
  --random-output-len 1000 --random-range-ratio 0.0 \
  --num-prompts 1 --num-warmups 0 --max-concurrency 1 \
  --request-rate inf --seed 2025 --temperature 0 --ignore-eos \
  --save-result --save-detailed

C33 was run three times with the same seed after one excluded request populated
the shared prefix:

vllm bench serve \
  --backend openai --base-url http://127.0.0.1:18080 \
  --endpoint /v1/completions --model nvidia/GLM-5.2-NVFP4 \
  --dataset-name prefix_repetition \
  --prefix-repetition-prefix-len 131071 \
  --prefix-repetition-suffix-len 1 \
  --prefix-repetition-num-prefixes 1 \
  --prefix-repetition-output-len 1000 \
  --num-prompts 33 --num-warmups 0 --max-concurrency 33 \
  --request-rate inf --seed 2025 --temperature 0 --ignore-eos \
  --save-result --save-detailed
Scenario Binary Run Input tokens Output tokens Median TTFT Median TPOT P99 TPOT Wall Output throughput
C1 Stock v0.27.0 1 135,168 1,000 8,976.84 ms 12.9141 ms 12.9141 ms 21.8784 s 45.71 tok/s
C1 Stock v0.27.0 2 135,168 1,000 8,978.48 ms 12.9233 ms 12.9233 ms 21.8892 s 45.68 tok/s
C1 Stock v0.27.0 3 135,168 1,000 8,985.82 ms 12.9278 ms 12.9278 ms 21.9012 s 45.66 tok/s
C1 Final PR head 1 135,168 1,000 8,943.97 ms 12.5560 ms 12.5560 ms 21.4878 s 46.54 tok/s
C1 Final PR head 2 135,168 1,000 8,952.70 ms 12.5737 ms 12.5737 ms 21.5143 s 46.48 tok/s
C1 Final PR head 3 135,168 1,000 8,965.51 ms 12.5635 ms 12.5635 ms 21.5168 s 46.48 tok/s
C33 Stock v0.27.0 1 4,325,377 33,000 6,139.05 ms 38.0590 ms 39.7888 ms 46.7583 s 705.76 tok/s
C33 Stock v0.27.0 2 4,325,377 33,000 5,989.71 ms 37.3003 ms 38.4780 ms 46.1484 s 715.08 tok/s
C33 Stock v0.27.0 3 4,325,377 33,000 5,970.92 ms 34.2506 ms 35.7192 ms 42.8705 s 769.76 tok/s
C33 Final PR head 1 4,325,377 33,000 6,223.96 ms 34.5978 ms 36.5388 ms 43.1796 s 764.25 tok/s
C33 Final PR head 2 4,325,377 33,000 5,868.54 ms 36.8706 ms 38.0197 ms 45.2565 s 729.18 tok/s
C33 Final PR head 3 4,325,377 33,000 5,922.29 ms 36.8221 ms 37.8651 ms 45.5684 s 724.19 tok/s

Median of three formal runs:

Scenario Metric Stock v0.27.0 Final PR head Delta
C1 TTFT 8,978.48 ms 8,952.70 ms -0.29%
C1 TPOT 12.9233 ms 12.5635 ms -2.78%
C1 Output throughput 45.68 tok/s 46.48 tok/s +1.74%
C33 TTFT 5,989.71 ms 5,922.29 ms -1.13%
C33 TPOT 37.3003 ms 36.8221 ms -1.28%
C33 P99 TPOT 38.4780 ms 37.8651 ms -1.59%
C33 Output throughput 715.08 tok/s 729.18 tok/s +1.97%

All six C33 formal runs completed 33/33 requests and reached
vllm:num_requests_running=33 under 100 ms metric sampling. The only
inference-time Triton JIT occurred in the excluded C1 warmup. These results show
no GLM E2E regression and a small positive change; no large E2E speedup is
claimed.

Complete GLM E2E commands, raw stdout/server logs, detailed JSON, Prometheus
samples, and SHA256 manifests

Five full lm_eval datasets, three runs each

This fresh A/B compares the final refactored PR head with rebuilt,
unmodified vLLM v0.27.0. The final fix ran first and stock ran second on the
same isolated B300 environment, model revision, server flags, and lm_eval
0.4.12 configuration. No --limit was used: 5,116 samples per repetition,
15,348 per binary, and 30,696 total sample evaluations.

TOOLS=/work/pr52149_final_lm_eval_ab_20260816
ROOT=/work/refactor_validation_20260816

"$TOOLS/switch_deepseek_accuracy_server.sh" refactor
ROOT="$ROOT" "$TOOLS/run_lm_eval_variant_three.sh" refactor

"$TOOLS/switch_deepseek_accuracy_server.sh" stock
ROOT="$ROOT" "$TOOLS/run_lm_eval_variant_three.sh" stock

python3 "$TOOLS/summarize_lm_eval_final_ab.py" --root "$ROOT"
python3 "$TOOLS/analyze_lm_eval_uncertainty.py" --root "$ROOT"
Task Samples/run Metric Stock v0.27.0 runs Stock mean Final PR runs Final mean Delta (pp)
GSM8K 1,319 exact_match,flexible-extract 0.949204, 0.952237, 0.948446 0.949962 0.950720, 0.952995, 0.950720 0.951478 +0.152
GSM8K 1,319 exact_match,strict-match 0.949962, 0.952995, 0.949204 0.950720 0.950720, 0.953753, 0.951478 0.951984 +0.126
ARC-Challenge 1,172 acc,none 0.646758, 0.647611, 0.647611 0.647327 0.649317, 0.649317, 0.649317 0.649317 +0.199
ARC-Challenge 1,172 acc_norm,none 0.675768, 0.680034, 0.680034 0.678612 0.674915, 0.674915, 0.674915 0.674915 -0.370
Winogrande 1,267 acc,none 0.797948, 0.792423, 0.794791 0.795054 0.791634, 0.791634, 0.797948 0.793738 -0.132
IFEval 541 prompt_level_strict_acc,none 0.234750, 0.256932, 0.247689 0.246457 0.240296, 0.255083, 0.255083 0.250154 +0.370
IFEval 541 prompt_level_loose_acc,none 0.271719, 0.301294, 0.290203 0.287739 0.275416, 0.286506, 0.292052 0.284658 -0.308
IFEval 541 inst_level_strict_acc,none 0.382494, 0.411271, 0.402878 0.398881 0.383693, 0.398082, 0.400480 0.394085 -0.480
IFEval 541 inst_level_loose_acc,none 0.419664, 0.448441, 0.441247 0.436451 0.422062, 0.435252, 0.438849 0.432054 -0.440
TruthfulQA-MC2 817 acc,none 0.587632, 0.587718, 0.582424 0.585925 0.587310, 0.587415, 0.587653 0.587459 +0.153

No metric with an lm_eval-reported standard error shows a statistically
detectable before/after change at 95% confidence, and all observed mean deltas
are within ±0.48 percentage points. IFEval's instruction-level metrics report
no standard error upstream, so those deltas are descriptive and marked N/A
in the complete uncertainty table.

Complete final-refactor-versus-stock accuracy artifact: all 30 stdout logs,
result JSON, sample JSONL, commands, summaries, uncertainty table, and SHA256
manifests

DeepSeek E2E and standalone reproducer artifacts

To run the standalone reproducer from the final-refactor artifact:

tar -xzf pr52149_final_refactor_deepseek_e2e_20260816.tgz
cd pr52149_final_refactor_deepseek_e2e_20260816/standalone_reproducer
docker build -t pr52149-repro .

The final-refactor artifact contains every formal final-head stdout log used in
the table above. The stock bundle preserves the corresponding unmodified
v0.27.0 baseline logs. No benchmark output used by the reported medians was
omitted.

Fall back to an exact bounded-memory radix rescan when a fixed candidate buffer overflows. This prevents silent top-k corruption for narrow score distributions across the short, decode, medium, and filtered-large dispatch paths.

Fixes vllm-project#51782

Signed-off-by: ahmed xijiaat <52128022+xijiaat@users.noreply.github.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify mergify Bot added the bug Something isn't working label Aug 13, 2026
Use the first-stage histogram to detect when the threshold bin already exceeds the fixed candidate buffer. Skip the guaranteed-to-overflow collection pass and enter the existing exact radix fallback directly.

On B300, five paired runs improved decode overflow cases by 6.71% and medium overflow cases by 10.90% geometrically, while modified non-overflow cases remained within 1% overall.

Signed-off-by: ahmed xijiaat <52128022+xijiaat@users.noreply.github.com>
@xijiaat

xijiaat commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Validation overview

This PR fixes persistent_topk candidate-buffer overflow with a bounded-memory
exact fallback. Validation covers the kernel itself, DeepSeek full-model
performance and accuracy, and a real GLM-5.2 reproduction.

1. Kernel correctness and performance

  • The final PR head passed 435/435 overflow correctness executions across
    all four dispatch paths, k = 512/1024/2048, boundary sizes, ragged rows,
    vector widths, repeated launches, and CUDA Graph replay.
  • All selected values matched torch.topk exactly, with zero invalid or
    duplicate indices.
  • Versus the preceding correct implementation, the targeted 131K / k=2048
    filtered-overflow path improved from 0.119025 ms to 0.055705 ms
    (2.1357x median paired speedup across five runs).
  • The final traversal refactor stayed within +/-0.05% of the preceding
    correct implementation, so no refactor-specific speedup is claimed.

2. DeepSeek-V4-Flash validation

  • Ran stock v0.27.0 versus the final PR head with identical CUDA Graph server
    settings: three C1 runs and three C33 runs, all with 135K-token prompts and
    1K-token outputs; warmups were excluded.
  • C1 remained materially unchanged.
  • At C33, median TPOT improved from 18.6120 ms to 17.8413 ms
    (-4.14%) and output throughput from 1,076.49 to 1,141.31 tok/s
    (+6.02%).
  • Ran five complete lm_eval datasets three times each with no --limit:
    GSM8K, ARC-Challenge, Winogrande, IFEval, and TruthfulQA-MC2. No metric with
    a reported standard error showed a statistically detectable change at 95%
    confidence; all observed mean deltas were within +/-0.48 percentage points.
  • DeepSeek E2E commands and raw logs
  • Complete lm_eval A/B evidence

3. GLM-5.2-NVFP4 validation

  • Reproduced the bug end to end on stock v0.27.0 with a genuine MRCR 2-needle
    request: 134,249 tokens per sequence, 33 sequences, index_topk=2048.
  • Stock selected incorrect values in up to 27/33 rows, with up to
    2,042/2,048 wrong selected values in one row and a maximum score delta
    of 6.5967.
  • Replayed the same six captured runtime tensors through the final PR head
    three times each (18 runs): zero mismatches, invalid indices, or duplicate
    rows
    .
  • Ran three TP2 C1 and three TP2 C33 full-model A/B runs on the same isolated
    B300 pair. At C33, median TPOT changed by -1.28%, P99 TPOT by -1.59%,
    and output throughput by +1.97%; C1 also showed no regression.
  • Real GLM reproduction and commands
  • GLM raw captures and logs
  • GLM TP2 E2E evidence

Overall, this is a real-model-triggerable silent-correctness fix with no
material performance or accuracy regression in the measured workloads.

@xijiaat

xijiaat commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Resolved: the build's Ninja dependency graph proves that the two modules
compiled against their intended, different headers. The original performance
results remain valid; the dependency paths and SHA256 values are documented in
the follow-up comment immediately below.

During an independent reproducibility review, we raised a concern that the
benchmark translation unit used #include "persistent_topk.cuh". Quoted-include
lookup can select a sibling header before the -I directory, so this needed to
be verified rather than assumed.

The source directory in the isolated test pod had no sibling
persistent_topk.cuh, and ninja -t deps recorded the current-PR and candidate
include directories separately. Therefore no rerun or commit-message correction
was required.

@xijiaat

xijiaat commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up: the include-path concern is now resolved with the build system's recorded dependency graph.

ninja -t deps patched_persistent_topk_ext.cuda.o reports:

vllm_52149_current_perf_55d317:
  /tmp/vllm51782/current_patch_perf_include/persistent_topk.cuh
  /tmp/vllm51782/current_patch_perf_include/topk_histogram_4096.cuh

vllm_52149_candidate_perf_55d317:
  /tmp/vllm51782/candidate_v8_final_include/persistent_topk.cuh
  /tmp/vllm51782/candidate_v8_final_include/topk_histogram_4096.cuh

The recorded header SHA256 values are:

current PR: d878e392ff859cbd49fb1d8303618e66ace47af768a155926baab783f4efeea3
candidate:  55d3170393e5f55287f1f337e4e797d4346876cf67e4a321f0fd84bbd8ba1cca

The two CUDA modules therefore did compile against their intended, different headers. The five-run performance comparison in my first comment remains valid. The comparison is specifically candidate versus the already-correct PR implementation, not the original incorrect vLLM main overflow behavior.

@xijiaat

xijiaat commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Hi @yewentao256, when you have time, could you please take another look at the updated patch? I kept the correctness fallback bounded and added two targeted optimizations: vectorized filtered-row rescans and a fused decode/medium output scan. On one B300, the final code passed 435/435 correctness cases; the production-relevant 131K/k=2048 filtered-overflow case improved by 15.28%, with no measured regression on any target overflow path. The PR body now includes the full five-run methodology and results. Thank you.

@yewentao256 yewentao256 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work.

Please add full reproduce command line, and e2e benchmark command line in PR description, running 3 times and adding full output log as well. Some agents will fake the number so we don't want a table only

Please also test using lm_eval to show we don't hurt acc

Vectorize exact fallback scans for long filtered rows and fuse the greater/equal output scans for decode and medium overflow paths. Preserve the two-pass filtered output path to avoid its measured long-row regression.

Validated on one B300 with 435/435 correctness cases and five-seed paired benchmarks. The 131K/k=2048 filtered overflow case improves by 15.28%, while decode and medium overflow paths improve by up to 3.25% and 3.78%.

Signed-off-by: ahmed xijiaat <52128022+xijiaat@users.noreply.github.com>
Adapt the long filtered-row path to an 11-bit ordered-FP16 coarse histogram and an exact 11/11/10 FP32 fallback, following the algorithmic structure of NVIDIA TensorRT-LLM production indexer Top-K radix selection: https://github.com/NVIDIA/TensorRT-LLM/blob/7a3b1bf500b742247f34d5fe4d212fd8ad284423/cpp/tensorrt_llm/kernels/indexerTopK.cu

Overlay the wider histogram and CUB scan storage onto the existing 128 KiB dynamic shared-memory allocation, preserving the kernel workspace and shared-memory contract.

Validated on one B300 with 435/435 correctness cases. Five-seed paired tests improve the 131K/k=2048 overflow path by 2.1357x versus the previous PR implementation, with short-path controls neutral.

Signed-off-by: ahmed xijiaat <52128022+xijiaat@users.noreply.github.com>
@xijiaat
xijiaat force-pushed the codex/fix-persistent-topk-overflow branch from 485716d to a01b9dd Compare August 14, 2026 16:15
Signed-off-by: ahmed xijiaat <52128022+xijiaat@users.noreply.github.com>
@xijiaat
xijiaat force-pushed the codex/fix-persistent-topk-overflow branch from a7cc4a1 to b98aecf Compare August 15, 2026 02:53
@xijiaat

xijiaat commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

Validation and reproducer

Full raw logs, Dockerfile, and exact commands: download the reproducibility bundle

Conclusion: the fix passes all 435/435 overflow correctness cases. The targeted 131K/k=2048 filtered-overflow kernel improves from 0.119025 ms to 0.055705 ms, a 2.1357x median paired speedup across five runs (range 2.1299x-2.1377x), with control paths unchanged. Full-model C1/C33 tests show no measurable performance regression; the kernel is too small a fraction of E2E time to establish a statistically significant E2E speedup. GSM8K is 94.84% vs. 95.00% over 1,319 samples, within statistical error, with no material accuracy regression.

unzip pr52149_raw_logs_and_reproducer.zip && cd github_raw_log_evidence
docker build -t pr52149-repro .
mkdir -p ../pr52149-work "$HOME/.cache/huggingface"
docker run --rm --gpus 'device=0' --shm-size=64g \
  --ulimit memlock=-1:-1 --ulimit stack=67108864:67108864 \
  -v "$PWD/../pr52149-work:/work" \
  -v "$HOME/.cache/huggingface:/root/.cache/huggingface" \
  pr52149-repro -lc \
  'bash /evidence/setup_repro.sh && bash /evidence/run_e2e_ab_cudagraph.sh'

The PR description contains the full server, C1, C33, and lm_eval command lines. The bundle contains every formal-run stdout log; no benchmark output was omitted.

@xijiaat

xijiaat commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

Updated the PR description with the requested complete validation evidence:

  • exact Dockerfile and reproduce/E2E command lines;
  • all three CUDA Graph E2E runs for C1 and C33;
  • all three forced-overflow correctness runs;
  • five complete lm_eval datasets, three runs each, with no --limit;
  • full stdout/server logs and detailed result artifacts.

Result: the overflow bug is fixed, all targeted long-vector results exactly match torch.topk, no accuracy regression was observed, and C33 median output throughput improved from 1076.49 to 1110.80 tok/s (+3.19%).

Complete reproducibility bundle

The full per-run tables and commands are kept once in the PR description to avoid duplicating the same evidence here. @yewentao256

Signed-off-by: ahmed xijiaat <52128022+xijiaat@users.noreply.github.com>

@LopezCastroRoberto LopezCastroRoberto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exact_topk_rescan introduces substantial duplicated traversal logic. Could you refactor the code to make the implementation easier to review and maintain? Also, tests/kernels/persistent_topk_reproducer/ should not be included in this PR; please keep the focused pytest regression and link external reproduction artifacts instead.

Signed-off-by: ahmed xijiaat <52128022+xijiaat@users.noreply.github.com>
@xijiaat

xijiaat commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @LopezCastroRoberto for the review.

  • Refactored the exact rescan to share scalar/float2/float4 traversal and pivot collection, removing the duplicated full-row traversal logic.
  • Removed tests/kernels/persistent_topk_reproducer/ from the PR and retained only the focused pytest regression.
  • Kept the standalone Docker reproducer, exact commands, and full raw logs in the external artifact linked from the PR description.

The final refactor passed boundary, ragged-row, vector-width, repeated-launch, and CUDA Graph correctness tests. Five paired kernel runs stayed within ±0.05% of the previous correct implementation. Compared with stock v0.27.0, C33 median TPOT was 18.6120 ms -> 17.8413 ms and output throughput was 1,076.49 -> 1,141.31 tok/s; C1 remained effectively unchanged.

The refactor therefore fixes the correctness issue without hurting performance; no refactor-specific speedup is claimed.

@xijiaat

xijiaat commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Added a real-model reproduction artifact for the affected path.

  • Model/request: nvidia/GLM-5.2-NVFP4, genuine MRCR 2-needle input, 134,249 tokens per sequence, one 33-sequence batch.
  • v0.27.0 runtime: up to 27/33 bad rows, 2,042/2,048 wrong selected values in one row, and max absolute value delta 6.5967.
  • PR implementation: the same six immutable runtime captures replayed three times each (18 runs), with zero bad rows, mismatches, invalid indices, or duplicate-index rows.
  • The bundle contains the Dockerfile, exact commands, complete 33-sequence HTTP request body, request/server raw logs, stock checks, and all 18 fixed replay logs. The six 35 MiB tensors are retained separately because of attachment size.

@LopezCastroRoberto
glm52_real_overflow_20260816_evidence.tgz

@xijiaat

xijiaat commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Additional raw artifacts for the real GLM-5.2 overflow reproduction:

  • glm52_real_overflow_20260816_raw_logs.tgz: 46 raw log files plus result JSON/headers.
  • glm52_real_runtime_captures.tgz.part-00.gz through part-08.gz: all six immutable runtime .pt captures, split only to fit the attachment limit.

The reconstructed capture archive contains these six tensors:

  • captures/glm52_mrcr2_135k.rankunknown.pid5764.seq00.pt
  • captures/glm52_mrcr2_135k.rankunknown.pid5764.seq01.pt
  • captures/glm52_mrcr2_135k.rankunknown.pid5764.seq02.pt
  • captures/glm52_mrcr2_135k.rankunknown.pid5765.seq00.pt
  • captures/glm52_mrcr2_135k.rankunknown.pid5765.seq01.pt
  • captures/glm52_mrcr2_135k.rankunknown.pid5765.seq02.pt

Reassemble and verify:

for f in glm52_real_runtime_captures.tgz.part-*.gz; do
  gzip -dc "$f"
done > glm52_real_runtime_captures.tgz

echo '185c063a4d9e56c992737c64be42f8173d1f619c8f84b66765d29ac68c800f77  glm52_real_runtime_captures.tgz' | sha256sum -c -
tar -xzf glm52_real_runtime_captures.tgz

The reconstructed archive contains exactly six tensors.

glm52_real_overflow_20260816_raw_logs.tgz
glm52_real_runtime_captures.tgz.part-00.gz
glm52_real_runtime_captures.tgz.part-01.gz
glm52_real_runtime_captures.tgz.part-02.gz
glm52_real_runtime_captures.tgz.part-03.gz
glm52_real_runtime_captures.tgz.part-04.gz
glm52_real_runtime_captures.tgz.part-05.gz
glm52_real_runtime_captures.tgz.part-06.gz
glm52_real_runtime_captures.tgz.part-07.gz
glm52_real_runtime_captures.tgz.part-08.gz

@xijiaat

xijiaat commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Final validation data now supersedes the earlier intermediate performance summaries.

  • Final DeepSeek C33 median TPOT: 18.6120 -> 17.8413 ms (-4.14%)
  • Final DeepSeek C33 output throughput: 1,076.49 -> 1,141.31 tok/s (+6.02%)
  • C1 remained materially unchanged.
  • Final headers passed 435/435 correctness executions; five traversal-refactor paired runs stayed within +/-0.05%.

The PR description now uses only these final numbers. Final-head commands and raw logs:
pr52149_final_refactor_deepseek_e2e_20260816.tgz

@xijiaat
xijiaat requested a review from yewentao256 August 17, 2026 12:06
@LopezCastroRoberto

Copy link
Copy Markdown
Contributor

running some perf/accy evals with the proposed solution rn. will be back asap

@LopezCastroRoberto

Copy link
Copy Markdown
Contributor

@xijiaat

Model/request: nvidia/GLM-5.2-NVFP4, genuine MRCR 2-needle input, 134,249 tokens per sequence, one 33-sequence batch.
v0.27.0 runtime: up to 27/33 bad rows, 2,042/2,048 wrong selected values in one row, and max absolute value delta 6.5967.

Can you also attach a table with the final accuracy numbers of MAIN vs PR on the MRCR eval? So we don't only know if there are collisions, but also how this affects real accuracy numbers.

@xijiaat

xijiaat commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

ok,i will give you the result asap. @LopezCastroRoberto

@WoosukKwon WoosukKwon added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 18, 2026
@github-actions

Copy link
Copy Markdown

@xijiaat, CI is now available for this PR.

  • /ci run starts a CI build.
  • /ci retry retries failed jobs in the CI build for the current PR head. If the current head has no CI build, it starts a new CI build for the current head containing only jobs that failed in the latest earlier CI build for this PR.
  • /ci cancel cancels scheduled or running CI builds for this PR branch.

@WoosukKwon WoosukKwon removed the ready ONLY add when PR is ready to merge/full CI is needed label Aug 18, 2026
@xijiaat

xijiaat commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. I reran the end-to-end MRCR evaluation with the official grade_response scorer and thats's the result.

Evaluation Context / shape Stock v0.27.0 PR
C1 context sweep genuine samples, 4,081–245,983 tokens 0.999700 0.999700
C33 one genuine 206,480-token sample, 33 simultaneous requests, 1.000000 1.000000

For C33, both versions completed 33/33 requests with finish_reason=stop; the minimum, median, and mean scores were all 1.0.

Therefore, the final-answer accuracy is effectively unchanged in these evaluations: no regression, but also no measurable accuracy gain on these particular samples. This does not contradict the kernel-level evidence: 0.27.0 returned incorrect selected top-k values, but those errors did not alter the final answer for these samples.
@LopezCastroRoberto Can you please review this PR?

@LopezCastroRoberto

LopezCastroRoberto commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

@xijiaat , that accuracy conclusion is exactly what I was expecting to see, because I was also not able to measure any accuracy impact. I think we need to differentiate three things here:

  1. Synthetic vs. real score distributions.
  2. Exact vs. approximate top-K in real NSA/DSA.
  3. The impact of overflow. Even when overflow occurs (which is a rare event) the discarded candidates will have the same high bits as the retained ones. Retained and discarded candidates belong to the same current radix-threshold bin. Therefore, they share the radix prefix examined so far, meaning their values are very close.

I did some research on this and found two interesting related discussions in SGLang: sgl-project/sglang#17747 and sgl-project/sglang#31115 (closed 3 days ago). Both are related to the overflow case. However, they weren't able to reproduce an e2e accuracy impact either, which is why the latter was eventually closed. Interestingly, the first PR explicitly mentions: "In the NSA/DSA sparse attention context, replacing a true top-k element with a numerically nearly-identical one has negligible impact on attention output."

A second important aspect is that, I ran some perf analysis and, while in non-overflow cases your PR might be able to preserve performance, the added overflow path is significantly slower than the main path. You can reproduce this by using a distribution in [1, 1.01] instead of a Gaussian, for example:

1.0 + torch.rand(rows, width, generator=generator) * 0.01
persistent | overflow | width=4,096 | time in us
   rows |            topk=512            |           topk=1024            |           topk=2048
        |    main   PR #52149   vs main  |    main   PR #52149   vs main  |    main   PR #52149   vs main
  -----------------------------------------------------------------------------------------------------
      1 |  13.327     24.864    +86.6%   |  14.225     20.489    +44.0%   |  14.191     20.492    +44.4%
      8 |  11.081     22.755   +105.3%   |  11.935     16.599    +39.1%   |  11.943     19.191    +60.7%
     16 |  11.079     22.815   +105.9%   |  11.946     17.745    +48.5%   |  11.974     19.407    +62.1%
     32 |  11.136     22.685   +103.7%   |  12.012     17.705    +47.4%   |  11.994     19.434    +62.0%
     33 |   5.001     21.302   +326.0%   |   5.131     16.566   +222.9%   |   6.665     18.254   +173.9%
     64 |   5.025     21.416   +326.2%   |   5.131     16.510   +221.8%   |   6.696     18.268   +172.8%
    128 |   5.077     21.430   +322.1%   |   5.216     16.711   +220.4%   |   6.743     18.469   +173.9%

  persistent | overflow | width=12,288 | time in us
   rows |            topk=512            |           topk=1024            |           topk=2048
        |    main   PR #52149   vs main  |    main   PR #52149   vs main  |    main   PR #52149   vs main
  -----------------------------------------------------------------------------------------------------
      1 |  14.345     26.647    +85.8%   |  16.239     27.096    +66.9%   |  16.264     24.578    +51.1%
      8 |  12.242     25.051   +104.6%   |  13.150     26.243    +99.6%   |  13.247     27.077   +104.4%
     16 |  12.166     25.646   +110.8%   |  13.178     26.239    +99.1%   |  13.319     26.576    +99.5%
     32 |  12.294     25.804   +109.9%   |  13.289     26.528    +99.6%   |  13.351     27.235   +104.0%
     33 |   7.270     25.731   +253.9%   |   7.396     26.005   +251.6%   |   8.877     26.648   +200.2%
     64 |   7.271     25.575   +251.8%   |   7.383     26.126   +253.9%   |   8.897     26.832   +201.6%
    128 |   7.273     25.734   +253.8%   |   7.448     26.153   +251.1%   |   8.914     26.769   +200.3%

  persistent | overflow | width=32,768 | time in us
   rows |            topk=512            |           topk=1024            |           topk=2048
        |    main   PR #52149   vs main  |    main   PR #52149   vs main  |    main   PR #52149   vs main
  -----------------------------------------------------------------------------------------------------
      1 |  19.474     34.837    +78.9%   |  20.476     36.855    +80.0%   |  20.482     34.979    +70.8%
      8 |  17.179     34.444   +100.5%   |  18.006     34.274    +90.3%   |  18.057     35.627    +97.3%
     16 |  19.048     37.241    +95.5%   |  20.073     39.046    +94.5%   |  19.966     39.786    +99.3%
     32 |  19.259     38.066    +97.7%   |  20.317     39.116    +92.5%   |  20.172     40.310    +99.8%
     33 |  12.379     41.710   +236.9%   |  12.510     42.331   +238.4%   |  14.015     43.544   +210.7%
     64 |  12.426     41.586   +234.7%   |  12.543     42.871   +241.8%   |  14.013     43.412   +209.8%
    128 |  12.545     41.686   +232.3%   |  12.670     43.164   +240.7%   |  14.126     44.000   +211.5%

  persistent | overflow | width=65,536 | time in us
   rows |            topk=512            |           topk=1024            |           topk=2048
        |    main   PR #52149   vs main  |    main   PR #52149   vs main  |    main   PR #52149   vs main
  -----------------------------------------------------------------------------------------------------
      1 |  22.729     22.652     -0.3%   |  24.104     20.284    -15.8%   |  23.584     23.239     -1.5%
      8 |  22.601     22.429     -0.8%   |  22.598     22.500     -0.4%   |  23.093     22.852     -1.0%
     16 |  30.365     30.084     -0.9%   |  31.146     30.764     -1.2%   |  31.770     31.437     -1.0%
     32 |  30.516     30.744     +0.7%   |  31.191     31.108     -0.3%   |  32.158     31.769     -1.2%
     33 |  34.844     50.679    +45.4%   |  34.880     51.763    +48.4%   |  34.936     53.556    +53.3%
     64 |  34.908     50.574    +44.9%   |  34.955     51.942    +48.6%   |  34.994     53.617    +53.2%
    128 |  35.076     50.890    +45.1%   |  35.117     52.322    +49.0%   |  35.127     53.798    +53.2%

  persistent | overflow | width=131,072 | time in us
   rows |            topk=512            |           topk=1024            |           topk=2048
        |    main   PR #52149   vs main  |    main   PR #52149   vs main  |    main   PR #52149   vs main
  -----------------------------------------------------------------------------------------------------
      1 |  22.522     22.649     +0.6%   |  23.207     22.527     -2.9%   |  22.525     23.111     +2.6%
      8 |  22.371     22.325     -0.2%   |  22.694     22.346     -1.5%   |  22.732     22.646     -0.4%
     16 |  35.072     35.142     +0.2%   |  35.770     35.545     -0.6%   |  36.169     36.268     +0.3%
     32 |  35.336     35.393     +0.2%   |  35.811     36.048     +0.7%   |  36.484     36.604     +0.3%
     33 |  53.373     91.979    +72.3%   |  53.429     93.390    +74.8%   |  53.536     96.007    +79.3%
     64 |  53.470     92.189    +72.4%   |  53.501     93.552    +74.9%   |  53.639     96.102    +79.2%
    128 |  53.687     92.488    +72.3%   |  53.739     94.079    +75.1%   |  53.813     96.486    +79.3%

  persistent | overflow | width=250,000 | time in us
   rows |            topk=512            |           topk=1024            |           topk=2048
        |    main   PR #52149   vs main  |    main   PR #52149   vs main  |    main   PR #52149   vs main
  -----------------------------------------------------------------------------------------------------
      1 |  23.370     24.539     +5.0%   |  24.373     24.519     +0.6%   |  24.452     24.567     +0.5%
      8 |  44.031     44.277     +0.6%   |  44.384     44.299     -0.2%   |  44.375     44.309     -0.1%
     16 |  37.401     37.450     +0.1%   |  37.934     37.765     -0.4%   |  38.356     38.242     -0.3%
     32 |  71.807     71.579     -0.3%   |  72.764     72.712     -0.1%   |  73.510     73.164     -0.5%
     33 |  90.998    169.690    +86.5%   |  91.058    171.197    +88.0%   |  91.187    173.896    +90.7%
     64 |  91.111    170.017    +86.6%   |  91.127    171.536    +88.2%   |  91.352    174.247    +90.7%
    128 | 112.548    242.044   +115.1%   | 112.334    243.262   +116.6%   | 112.702    246.730   +118.9%

Therefore, I tend to trust the real accuracy numbers. If there is otherwise evidence demonstrating a real impact on accuracy, then I think we should investigate that separately. But I would leave the synthetic cases aside here, because in this particular case they also have performance implications.

@xijiaat

xijiaat commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @LopezCastroRoberto for the review. I kept this sampled-adaptive v7 experiment separate from the PR and published the complete reproducer here:

https://github.com/xijiaat/persistent-topk-overflow-experiment

All variants used the same production dispatcher on B300. Every cell was measured in 3 independent runs with 20 warmups, 60 samples, and 20 launches per sample.

Input / dispatch Cells MAIN bad rows PR bad rows v7 bad rows v7 vs MAIN v7 vs PR
Narrow overflow, all 168 18,252 0 0 +4.05% -34.66%
Narrow, persistent (rows <= 32) 96 2,052 0 0 +4.41% -19.19%
Narrow, FilteredTopK (rows >= 33) 72 16,200 0 0 +3.56% -50.79%
Normal, persistent 96 0 0 0 +4.11% +2.88%
Normal, FilteredTopK 72 0 0 0 -2.99% +0.51%
Wide uniform, persistent 96 0 0 0 +4.33% +2.68%
Wide uniform, FilteredTopK 72 0 0 0 -2.83% +0.50%

Negative percentages mean v7 is faster. Compared with the current PR implementation, v7 is 34.66% faster over the full narrow-overflow matrix and 50.79% faster on the FilteredTopK overflow branch. Compared with MAIN, the result is mixed: normal/wide FilteredTopK is about 3% faster, while normal/wide persistent is about 4% slower.

Full production-dispatch matrix: MAIN vs PR vs v7
Three-run medians; time in us. Negative percentages mean v7 is faster.
sampled-adaptive v7 is compared with both MAIN and the current PR.

narrow | production dispatch | width=4,096 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  14.545   22.991   12.286   -15.9%   -47.5%|  15.266   16.602   12.486   -18.6%   -25.6%|  15.322   20.682   11.933   -22.1%   -42.3%
    8 | persistent   |  14.670   25.038   12.046   -18.1%   -51.9%|  15.612   20.926   12.606   -19.3%   -39.8%|  15.625   22.810   12.014   -23.4%   -47.3%
   16 | persistent   |  14.660   26.298   12.067   -17.7%   -54.4%|  15.655   20.848   12.600   -19.5%   -39.6%|  15.664   22.854   12.080   -23.1%   -47.4%
   32 | persistent   |  14.687   26.937   12.199   -16.9%   -54.7%|  15.630   20.869   12.580   -19.5%   -39.8%|  15.638   22.894   12.106   -22.8%   -47.2%
   33 | FilteredTopK |   7.233   22.789    8.418   +16.5%   -63.0%|   7.425   18.688    8.405   +13.5%   -55.0%|   8.542   20.745    8.416    -1.2%   -59.4%
   64 | FilteredTopK |   7.442   22.798    8.418   +13.4%   -63.1%|   7.428   18.676    8.411   +13.2%   -54.9%|   8.611   20.744    8.414    -2.3%   -59.4%
  128 | FilteredTopK |   7.472   22.820    8.409   +12.9%   -63.2%|   7.616   18.690    8.416   +10.5%   -54.9%|   8.730   20.742    8.418    -3.5%   -59.4%

narrow | production dispatch | width=12,288 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  16.494   26.234   16.645    +1.0%   -36.6%|  16.642   26.849   16.702    +0.4%   -37.8%|  16.654   28.226   18.656   +12.1%   -33.6%
    8 | persistent   |  16.466   29.064   16.741    +2.3%   -42.4%|  16.731   29.265   16.747    +0.0%   -42.8%|  16.740   31.033   18.744   +12.0%   -39.4%
   16 | persistent   |  16.692   29.023   16.742    +0.3%   -42.3%|  16.745   29.126   16.791    +0.0%   -42.2%|  16.750   31.044   18.750   +12.0%   -39.5%
   32 | persistent   |  16.910   29.329   16.934    +0.1%   -42.3%|  16.762   30.092   16.904    +0.8%   -43.0%|  16.767   31.038   18.742   +11.8%   -39.6%
   33 | FilteredTopK |   9.826   26.898   10.549    +7.4%   -60.8%|  10.486   26.906   11.080    +6.0%   -58.8%|  11.035   28.933   11.295    +1.9%   -61.0%
   64 | FilteredTopK |  10.265   26.895   10.553    +2.6%   -60.8%|  10.480   27.254   11.510    +9.7%   -58.1%|  11.247   28.931   11.529    +2.5%   -60.2%
  128 | FilteredTopK |  10.470   26.895   10.765    +2.8%   -60.0%|  10.472   27.559   11.532   +10.1%   -58.1%|  11.525   28.934   11.529    +0.1%   -60.1%

narrow | production dispatch | width=32,767 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  20.792   36.736   26.851   +29.1%   -26.9%|  22.508   37.978   26.866   +19.4%   -29.1%|  22.698   37.076   29.014   +27.8%   -21.6%
    8 | persistent   |  20.850   37.204   26.930   +29.2%   -27.6%|  22.829   39.247   26.976   +18.1%   -31.2%|  22.838   39.191   29.177   +28.0%   -25.6%
   16 | persistent   |  24.790   43.415   31.052   +25.3%   -28.4%|  24.994   45.266   31.343   +25.4%   -30.4%|  24.965   45.700   33.384   +33.8%   -26.6%
   32 | persistent   |  25.086   43.464   31.362   +25.1%   -27.6%|  25.098   45.337   31.641   +25.7%   -30.2%|  25.071   46.242   34.214   +36.6%   -26.6%
   33 | FilteredTopK |  16.650   51.509   20.745   +24.8%   -59.7%|  16.656   53.522   21.582   +29.6%   -59.7%|  18.699   53.686   22.799   +21.9%   -57.6%
   64 | FilteredTopK |  16.654   52.966   20.747   +24.7%   -60.9%|  16.651   53.525   21.622   +29.9%   -59.6%|  18.687   53.905   22.797   +22.0%   -57.8%
  128 | FilteredTopK |  16.654   53.529   21.109   +26.2%   -60.6%|  16.665   53.946   22.793   +36.7%   -57.8%|  18.706   55.581   22.797   +21.8%   -59.0%

narrow | production dispatch | width=32,768 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  20.734   34.362   25.704   +23.7%   -25.2%|  22.173   34.367   26.852   +21.4%   -21.7%|  22.555   36.799   28.903   +28.4%   -21.5%
    8 | persistent   |  20.834   37.270   25.512   +22.6%   -31.4%|  22.338   37.343   26.982   +20.6%   -27.7%|  22.669   39.216   28.998   +27.9%   -26.1%
   16 | persistent   |  22.910   41.256   30.507   +33.5%   -26.1%|  24.630   42.577   31.146   +25.9%   -27.2%|  24.079   43.475   33.102   +37.8%   -23.7%
   32 | persistent   |  22.934   41.586   31.154   +34.9%   -25.1%|  24.831   43.272   31.070   +25.1%   -28.2%|  24.494   44.030   33.085   +35.6%   -24.9%
   33 | FilteredTopK |  14.600   41.234   18.695   +28.0%   -54.7%|  14.602   43.275   18.810   +29.1%   -56.5%|  16.634   43.383   20.738   +24.7%   -52.2%
   64 | FilteredTopK |  14.596   41.283   18.690   +28.1%   -54.8%|  14.603   43.274   18.755   +28.3%   -56.6%|  16.645   43.387   20.731   +24.6%   -52.2%
  128 | FilteredTopK |  14.595   42.374   18.702   +28.1%   -55.9%|  14.606   43.271   19.516   +33.1%   -55.0%|  16.645   44.692   20.747   +24.6%   -53.6%

narrow | production dispatch | width=32,769 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  24.941   24.901   24.917    -0.0%    +0.1%|  25.382   25.165   25.393    -0.0%    +0.9%|  25.772   25.800   25.863    +0.4%    +0.2%
    8 | persistent   |  26.954   26.936   26.938    -0.1%    -0.0%|  26.941   26.939   26.946    +0.0%    +0.0%|  26.994   27.027   27.032    +0.0%    +0.0%
   16 | persistent   |  37.189   37.165   37.177    -0.0%    +0.0%|  37.673   37.490   37.696    +0.1%    +0.2%|  39.167   39.078   39.187    +0.1%    +0.3%
   32 | persistent   |  37.280   37.346   37.581    +0.2%    +0.2%|  37.371   37.366   37.406    +0.1%    +0.1%|  39.266   39.218   39.305    +0.0%    +0.1%
   33 | FilteredTopK |  33.026   45.920   33.004    +0.0%   -27.9%|  33.027   47.367   34.218    +3.6%   -27.8%|  33.030   47.374   35.082    +6.2%   -25.9%
   64 | FilteredTopK |  33.033   46.620   33.031    +0.1%   -29.0%|  33.029   47.362   34.367    +4.1%   -27.4%|  33.038   47.378   35.084    +6.2%   -26.0%
  128 | FilteredTopK |  33.033   47.352   33.042    +0.0%   -30.2%|  33.038   47.375   35.067    +6.0%   -26.0%|  33.039   47.409   35.090    +6.2%   -26.0%

narrow | production dispatch | width=65,536 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  23.794   23.734   23.818    +0.0%    +0.3%|  23.830   23.757   23.926    +0.2%    +0.6%|  24.322   24.247   24.346    +0.1%    +0.4%
    8 | persistent   |  26.868   26.846   26.936    +0.2%    +0.4%|  26.922   26.936   26.941    +0.1%    +0.0%|  26.988   26.978   26.988    +0.0%    +0.0%
   16 | persistent   |  35.168   35.150   35.627    +1.3%    +1.2%|  35.304   35.335   37.016    +4.8%    +4.7%|  37.042   37.022   37.216    +0.5%    +0.5%
   32 | persistent   |  35.328   35.282   36.320    +3.2%    +3.2%|  35.780   35.683   37.251    +4.2%    +4.4%|  37.201   37.172   37.241    +0.2%    +0.3%
   33 | FilteredTopK |  36.887   51.424   35.474    -3.8%   -30.9%|  36.970   51.573   36.914    -0.2%   -28.3%|  37.127   53.522   38.679    +4.3%   -27.7%
   64 | FilteredTopK |  37.115   51.464   36.111    -2.7%   -29.8%|  37.123   51.702   36.388    -1.9%   -29.7%|  37.130   53.597   39.162    +5.5%   -26.9%
  128 | FilteredTopK |  37.125   51.459   37.030    -0.3%   -28.1%|  37.117   52.433   37.106    +0.0%   -29.1%|  37.130   53.690   39.178    +5.5%   -27.0%

narrow | production dispatch | width=131,072 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  23.698   23.656   23.727    +0.3%    +0.4%|  23.694   23.648   23.740    +0.4%    +0.4%|  24.586   24.494   24.593    +0.0%    +0.4%
    8 | persistent   |  26.919   26.930   26.930    +0.0%    +0.0%|  26.933   26.937   26.942    +0.0%    +0.0%|  26.934   26.936   26.948    +0.1%    +0.0%
   16 | persistent   |  40.900   40.912   41.283    +0.9%    +0.9%|  41.363   41.287   41.427    +0.2%    +0.1%|  41.524   41.519   42.951    +3.4%    +3.4%
   32 | persistent   |  41.305   41.317   41.319    -0.0%    -0.0%|  41.287   41.304   41.638    +0.9%    +0.8%|  41.541   41.632   43.323    +3.9%    +3.6%
   33 | FilteredTopK |  54.342   90.398   45.317   -16.6%   -49.9%|  54.482   92.074   49.370    -9.5%   -46.4%|  55.248   94.500   49.406   -10.6%   -47.7%
   64 | FilteredTopK |  54.847   90.411   45.329   -17.2%   -49.9%|  54.934   92.261   49.406   -10.1%   -46.4%|  55.522   94.512   49.420   -11.0%   -47.7%
  128 | FilteredTopK |  55.344   90.458   45.413   -18.0%   -49.8%|  55.433   92.468   49.418   -10.9%   -46.6%|  55.566   94.678   49.422   -11.1%   -47.7%

narrow | production dispatch | width=250,000 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  24.838   24.838   24.878    +0.1%    +0.1%|  24.960   24.978   25.268    +1.2%    +1.2%|  24.831   24.804   24.819    +0.0%    +0.1%
    8 | persistent   |  47.550   47.447   47.628    +0.2%    +0.0%|  47.842   47.986   48.642    +1.5%    +1.3%|  48.492   48.258   48.987    +1.0%    +1.0%
   16 | persistent   |  43.318   43.358   43.548    +0.4%    +0.4%|  43.456   43.471   45.117    +3.8%    +3.7%|  43.788   43.898   45.376    +3.9%    +3.6%
   32 | persistent   |  81.125   80.957   83.051    +2.4%    +2.8%|  80.785   80.771   81.932    +0.9%    +1.4%|  81.817   81.788   83.097    +1.8%    +1.6%
   33 | FilteredTopK |  91.803  164.275   69.852   -23.9%   -57.5%|  91.833  166.063   68.803   -25.1%   -58.6%|  92.157  168.958   73.758   -19.9%   -56.4%
   64 | FilteredTopK |  92.010  164.838   69.894   -24.1%   -57.6%|  92.111  166.286   69.889   -24.2%   -58.0%|  92.336  169.742   73.976   -19.9%   -56.4%
  128 | FilteredTopK | 114.152  236.958   98.512   -13.7%   -58.4%| 114.424  238.423   98.524   -13.9%   -58.7%| 114.735  241.329  101.277   -11.8%   -58.0%

normal | production dispatch | width=4,096 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  12.439   12.530   12.522    +0.7%    -0.1%|  12.446   12.489   12.497    +0.3%    +0.0%|   8.457    8.491    8.762    +3.6%    +3.3%
    8 | persistent   |  12.591   12.613   12.650    +0.5%    +0.3%|  12.592   12.607   12.650    +0.5%    +0.4%|  12.549   12.579   12.580    +0.2%    +0.0%
   16 | persistent   |  12.626   12.645   12.654    +0.5%    +0.2%|  12.570   12.623   12.652    +0.6%    +0.2%|  11.528   12.572   12.572    +9.0%    +0.0%
   32 | persistent   |  12.614   12.632   12.656    +0.5%    +0.1%|  12.679   12.752   12.844    +0.7%    +0.7%|  12.597   12.612   12.659    +0.5%    +0.0%
   33 | FilteredTopK |   6.354    6.350    6.372    +0.2%    +0.4%|   6.354    6.354    6.370    +0.3%    +0.3%|   6.340    6.344    6.353    +0.2%    +0.2%
   64 | FilteredTopK |   6.366    6.355    6.370    +0.2%    +0.4%|   6.362    6.354    6.359    +0.1%    +0.1%|   6.328    6.365    6.327    +0.2%    +0.1%
  128 | FilteredTopK |   6.366    6.360    6.370    +0.0%    +0.2%|   6.365    6.367    6.367    +0.1%    -0.0%|   6.358    6.354    6.352    -0.1%    +0.1%

normal | production dispatch | width=12,288 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  14.538   14.566   14.600    +2.7%    +0.5%|  14.573   14.666   16.413   +12.6%   +10.9%|  14.563   14.742   16.439   +12.7%   +11.3%
    8 | persistent   |  14.634   14.679   15.674    +6.9%    +6.9%|  14.654   15.012   16.655   +13.6%   +10.9%|  14.659   14.986   16.662   +13.7%   +11.2%
   16 | persistent   |  14.656   14.694   15.642    +7.0%    +6.4%|  15.671   16.650   16.742    +6.8%    +0.6%|  15.723   16.671   16.730    +6.4%    +0.4%
   32 | persistent   |  14.936   14.848   16.147    +9.6%    +5.3%|  15.808   16.677   16.705    +5.6%    +0.2%|  15.833   16.666   16.756    +5.8%    +0.5%
   33 | FilteredTopK |   8.423    8.418    8.418    +0.0%    -0.0%|   8.424    8.432    8.418    -0.1%    -0.0%|   8.435    8.434    8.421    -0.2%    -0.2%
   64 | FilteredTopK |   8.434    8.426    8.417    -0.1%    -0.1%|   8.427    8.436    8.430    +0.0%    -0.2%|   8.442    8.435    8.430    -0.0%    -0.0%
  128 | FilteredTopK |   8.426    8.434    8.414    -0.1%    -0.3%|   8.438    8.429    8.427    -0.1%    +0.0%|   8.441    8.433    8.457    +0.0%    +0.1%

normal | production dispatch | width=32,767 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  18.643   18.726   19.859    +6.5%    +5.2%|  20.657   20.720   21.829    +5.7%    +5.4%|  20.802   22.476   22.828    +9.7%    +1.7%
    8 | persistent   |  18.748   18.790   19.982    +6.8%    +6.2%|  20.746   20.771   21.384    +2.9%    +2.9%|  21.773   22.810   23.826    +9.4%    +4.5%
   16 | persistent   |  20.870   21.880   23.059   +10.5%    +5.7%|  22.837   22.938   24.924    +9.0%    +8.5%|  24.601   24.910   27.031    +9.5%    +8.1%
   32 | persistent   |  22.086   23.058   23.610    +8.2%    +3.6%|  22.908   23.388   25.329   +10.6%    +8.7%|  24.886   25.076   26.946    +8.5%    +8.0%
   33 | FilteredTopK |  14.560   14.574   14.574    +0.1%    +0.0%|  14.591   14.618   14.590    -0.0%    -0.2%|  18.682   18.678   18.677    -0.0%    -0.0%
   64 | FilteredTopK |  14.586   14.598   14.569    -0.0%    +0.0%|  14.610   14.854   14.608    -0.1%    -1.7%|  18.668   18.686   18.675    +0.0%    -0.1%
  128 | FilteredTopK |  14.592   14.594   14.589    -0.1%    -0.1%|  15.990   16.610   15.622    -1.4%    -6.0%|  18.691   18.718   18.683    -0.0%    -0.2%

normal | production dispatch | width=32,768 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  18.631   18.691   19.685    +5.5%    +5.4%|  19.627   20.656   20.733    +5.6%    +2.4%|  20.750   21.989   22.764    +9.6%    +3.5%
    8 | persistent   |  18.790   19.908   20.751    +7.5%    +4.2%|  20.652   20.810   21.196    +5.3%    +1.9%|  20.854   22.642   22.878    +9.6%    +4.0%
   16 | persistent   |  20.798   20.849   22.880   +10.0%    +9.7%|  22.806   23.098   25.148   +10.7%    +8.9%|  24.534   24.917   26.937    +9.8%    +8.0%
   32 | persistent   |  21.171   22.358   24.019   +14.1%    +7.4%|  22.814   22.924   25.021    +9.7%    +9.0%|  24.357   24.891   26.904   +10.6%    +8.1%
   33 | FilteredTopK |  12.528   12.525   12.526    -0.0%    -0.0%|  12.583   12.551   12.533    -0.4%    -0.1%|  16.618   16.630   16.634    +0.0%    +0.1%
   64 | FilteredTopK |  12.529   12.530   12.526    -0.0%    +0.0%|  12.589   12.543   12.545    -0.3%    +0.0%|  16.623   16.634   16.634    +0.1%    -0.0%
  128 | FilteredTopK |  12.535   12.528   12.533    +0.0%    -0.1%|  13.470   12.579   12.567    -4.6%    -0.1%|  16.631   16.632   16.628    -0.0%    -0.0%

normal | production dispatch | width=32,769 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  24.791   24.786   24.782    +0.0%    -0.0%|  24.842   24.832   24.854    +0.0%    +0.1%|  25.038   24.964   25.144    +0.3%    +0.7%
    8 | persistent   |  26.650   26.359   26.631    -0.1%    +0.4%|  26.895   26.917   26.913    +0.1%    +0.0%|  26.912   26.953   26.942    +0.0%    -0.0%
   16 | persistent   |  35.183   35.156   35.175    -0.1%    +0.0%|  37.189   37.205   37.197    +0.0%    -0.0%|  37.258   37.218   37.232    +0.0%    +0.0%
   32 | persistent   |  35.369   35.370   35.502    +0.7%    +0.2%|  37.186   37.159   37.162    +0.0%    +0.1%|  37.253   37.216   37.340    +0.2%    +0.3%
   33 | FilteredTopK |  22.754   20.814   20.726    -8.9%    -0.3%|  22.779   22.698   21.043    -7.6%    -0.2%|  24.826   22.766   21.713   -12.6%    -4.7%
   64 | FilteredTopK |  22.762   20.876   20.740    -8.9%    -0.6%|  23.649   22.769   21.342    -8.9%    -6.3%|  24.822   22.784   22.768    -8.2%    -0.1%
  128 | FilteredTopK |  22.782   21.688   20.742    -9.0%    -4.3%|  24.184   22.763   22.431    -7.2%    -1.5%|  24.842   22.794   22.767    -8.3%    -0.1%

normal | production dispatch | width=65,536 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  23.278   23.146   23.316    +0.4%    +0.7%|  23.434   23.314   23.422    +0.0%    +0.5%|  23.690   23.672   23.794    +0.4%    +0.4%
    8 | persistent   |  25.895   25.910   26.391    +1.7%    +1.6%|  26.120   26.342   26.754    +2.2%    +1.3%|  26.940   26.899   26.948    +0.0%    +0.2%
   16 | persistent   |  33.245   33.202   34.708    +4.4%    +4.5%|  34.551   34.344   35.137    +1.8%    +2.2%|  35.215   35.216   36.723    +4.2%    +4.3%
   32 | persistent   |  33.642   33.602   35.412    +4.8%    +5.4%|  34.918   34.903   35.174    +0.9%    +1.0%|  35.359   35.307   36.949    +4.8%    +4.8%
   33 | FilteredTopK |  28.922   24.866   26.676    -7.8%    +7.3%|  28.920   26.875   26.921    -6.9%    +0.2%|  30.995   28.913   28.922    -6.6%    +0.0%
   64 | FilteredTopK |  28.922   24.838   25.805   -10.7%    +3.9%|  28.933   26.881   28.042    -3.9%    +4.3%|  31.036   28.911   28.942    -6.8%    +0.1%
  128 | FilteredTopK |  28.958   25.426   26.863    -7.1%    +5.6%|  28.987   26.883   28.547    -2.2%    +6.2%|  32.009   28.923   29.074    -8.5%    +0.5%

normal | production dispatch | width=131,072 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  23.116   23.038   23.078    +0.3%    +0.3%|  22.954   22.938   22.994    +0.3%    +0.3%|  23.747   23.750   23.886    +0.6%    +0.6%
    8 | persistent   |  25.802   25.718   25.970    +1.7%    +1.1%|  25.655   25.854   26.166    +2.3%    +1.2%|  26.103   26.258   26.786    +2.5%    +1.9%
   16 | persistent   |  38.654   38.723   39.236    +1.5%    +1.4%|  39.234   39.260   39.286    +0.1%    +0.2%|  39.330   39.290   40.609    +3.3%    +3.3%
   32 | persistent   |  39.157   39.062   39.243    +0.3%    +0.4%|  39.234   39.224   39.319    +0.2%    +0.3%|  39.434   39.547   41.125    +4.4%    +4.0%
   33 | FilteredTopK |  39.178   39.179   40.141    +2.5%    +2.5%|  47.462   41.259   43.230    -9.3%    +4.8%|  48.057   45.294   45.324    -5.7%    +0.1%
   64 | FilteredTopK |  39.185   39.432   41.214    +5.2%    +4.5%|  47.936   41.296   43.262   -10.0%    +4.6%|  49.190   45.317   45.350    -7.8%    +0.1%
  128 | FilteredTopK |  39.248   40.561   41.204    +5.0%    +1.6%|  49.084   41.780   43.252   -11.9%    +3.6%|  49.380   45.328   45.478    -7.9%    +0.4%

normal | production dispatch | width=250,000 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  24.778   24.786   24.802    +0.0%    +0.0%|  24.806   24.807   24.822    +0.1%    +0.1%|  24.738   24.706   24.777    +0.3%    +0.4%
    8 | persistent   |  46.042   45.809   46.701    +1.4%    +1.9%|  47.324   47.310   47.426    +0.6%    +0.5%|  47.836   47.890   47.804    -0.6%    -0.2%
   16 | persistent   |  41.199   41.110   41.306    +0.3%    +0.6%|  41.280   41.274   41.477    +0.5%    +0.5%|  41.302   41.322   42.631    +3.1%    +3.2%
   32 | persistent   |  75.778   75.741   77.525    +2.3%    +2.3%|  75.054   74.850   77.047    +2.5%    +2.7%|  76.830   76.813   78.799    +2.6%    +2.5%
   33 | FilteredTopK |  70.431   69.923   71.877    +1.6%    +2.3%|  70.908   71.962   72.673    +2.7%    +1.0%|  86.302   74.605   76.055   -11.9%    +2.0%
   64 | FilteredTopK |  70.170   69.923   71.921    +2.5%    +2.9%|  71.956   71.967   72.962    +1.4%    +1.4%|  86.482   76.028   76.424   -11.9%    +1.1%
  128 | FilteredTopK |  92.426   90.378   91.797    -0.6%    +1.6%|  92.488   92.452   93.717    +1.3%    +1.4%| 106.563   95.642   96.682    -9.3%    +1.1%

wide_uniform | production dispatch | width=4,096 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  12.490   12.528   12.522    +0.4%    -0.1%|  12.386   12.491   12.497    +0.9%    +0.0%|   8.486    8.478    8.761    +3.4%    +3.3%
    8 | persistent   |  12.595   12.645   12.668    +0.6%    +0.2%|  12.598   12.636   12.654    +0.4%    +0.1%|  10.598   10.643   11.165    +6.2%    +6.1%
   16 | persistent   |  12.699   13.615   14.633   +11.7%    +7.3%|  12.580   12.645   12.653    +0.7%    +0.4%|  10.635   11.153   12.078   +13.1%    +8.3%
   32 | persistent   |  12.654   12.659   13.247    +3.6%    +3.7%|  12.882   12.938   13.054    +0.2%    +0.9%|  12.498   12.591   12.626    +1.8%    +0.3%
   33 | FilteredTopK |   6.369    6.344    6.362    +0.1%    +0.5%|   6.355    6.366    6.349    +0.2%    +0.1%|   6.346    6.308    6.345    -0.0%    -0.1%
   64 | FilteredTopK |   6.369    6.354    6.375    +0.2%    +0.3%|   6.362    6.382    6.379    -0.0%    -0.0%|   6.366    6.347    6.348    +0.1%    +0.3%
  128 | FilteredTopK |   6.382    6.373    6.394    +0.3%    +0.5%|   6.368    6.366    6.378    +0.3%    +0.2%|   6.358    6.356    6.346    +0.0%    -0.0%

wide_uniform | production dispatch | width=12,288 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  14.578   14.650   16.226   +11.2%   +10.8%|  14.571   14.630   16.029   +10.3%    +9.7%|  14.657   16.306   16.627   +13.4%    +2.8%
    8 | persistent   |  15.688   16.658   16.723    +6.6%    +0.4%|  14.707   15.561   16.660   +10.4%    +7.1%|  16.670   16.701   16.783    +3.6%    +3.3%
   16 | persistent   |  15.669   16.659   16.728    +6.8%    +0.5%|  15.615   16.681   16.725    +7.1%    +0.3%|  15.066   16.704   16.736   +10.8%    +0.7%
   32 | persistent   |  15.519   15.818   17.058    +9.9%    +6.5%|  15.776   16.726   16.826    +7.0%    +1.0%|  16.714   16.735   17.773    +4.3%    +6.3%
   33 | FilteredTopK |  10.502   10.019   10.486    -0.1%    +4.7%|  10.478   10.486   10.494    +0.1%    -0.0%|  10.555   10.546   10.524    -0.3%    -0.2%
   64 | FilteredTopK |  10.486   10.471   10.476    -0.1%    -0.0%|  10.466   10.477   10.486    +0.1%    +0.0%|  11.021   10.802   10.691    -3.8%    -1.0%
  128 | FilteredTopK |  10.484   10.465   10.476    +0.0%    +0.0%|  10.489   10.474   10.480    +0.0%    -0.0%|  11.362   11.023   10.850    -4.5%    -1.2%

wide_uniform | production dispatch | width=32,767 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  18.658   18.686   19.253    +3.4%    +2.9%|  22.757   23.878   24.810    +9.0%    +3.9%|  22.739   23.745   24.795    +9.0%    +4.4%
    8 | persistent   |  18.751   18.782   19.266    +2.7%    +2.6%|  23.127   24.845   25.053    +8.3%    +0.8%|  23.201   24.847   25.370    +9.4%    +4.7%
   16 | persistent   |  21.092   22.687   23.194   +10.4%    +5.2%|  27.103   27.123   29.502    +8.9%    +7.8%|  26.957   27.038   29.047    +9.1%    +7.5%
   32 | persistent   |  21.383   23.264   23.638   +10.3%    +4.4%|  26.939   27.614   29.498    +9.4%    +6.1%|  27.134   27.818   29.324    +8.3%    +5.4%
   33 | FilteredTopK |  16.629   16.630   16.614    -0.1%    -0.0%|  16.628   16.653   16.634    +0.0%    -0.1%|  18.680   18.684   18.678    +0.0%    -0.0%
   64 | FilteredTopK |  16.612   16.631   16.622    +0.0%    -0.0%|  16.654   16.654   16.643    -0.0%    -0.1%|  18.682   18.683   18.698    +0.0%    +0.0%
  128 | FilteredTopK |  16.635   16.643   16.629    -0.0%    -0.1%|  16.888   18.133   16.714    +0.0%    -7.1%|  18.729   19.248   18.738    +0.1%    -2.6%

wide_uniform | production dispatch | width=32,768 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  18.634   18.686   19.143    +2.8%    +2.4%|  23.755   24.810   25.805    +8.9%    +4.4%|  22.734   23.408   24.773    +9.0%    +5.8%
    8 | persistent   |  18.794   19.656   20.752   +10.4%    +4.7%|  22.834   23.044   24.870    +8.9%    +8.0%|  22.911   24.870   25.052    +9.4%    +0.7%
   16 | persistent   |  20.910   21.892   23.441   +12.1%    +6.7%|  25.557   27.002   29.034   +13.4%    +7.4%|  25.505   26.988   28.879   +13.2%    +7.0%
   32 | persistent   |  21.330   22.624   23.550    +9.7%    +4.5%|  26.303   26.976   29.179   +10.9%    +7.6%|  26.146   26.985   28.979   +11.6%    +7.4%
   33 | FilteredTopK |  14.578   14.592   14.582    -0.0%    -0.0%|  14.611   14.586   14.594    -0.1%    +0.1%|  16.636   16.641   16.642    +0.0%    +0.0%
   64 | FilteredTopK |  14.581   14.587   14.581    -0.0%    -0.0%|  14.602   14.621   14.598    -0.2%    -0.1%|  16.630   16.642   16.631    +0.0%    -0.0%
  128 | FilteredTopK |  14.590   14.578   14.589    +0.0%    +0.0%|  14.637   14.609   14.606    -0.1%    -0.0%|  16.654   16.642   16.642    -0.0%    -0.0%

wide_uniform | production dispatch | width=32,769 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  24.836   24.811   24.826    -0.0%    +0.1%|  24.875   24.855   24.878    -0.1%    +0.1%|  25.162   25.026   25.302    +0.4%    +0.5%
    8 | persistent   |  26.769   26.564   26.750    -0.1%    +0.7%|  26.932   26.929   26.919    -0.0%    -0.0%|  26.986   27.038   26.979    +0.0%    +0.0%
   16 | persistent   |  35.931   35.378   35.686    -0.7%    +0.9%|  37.211   37.274   37.447    -0.0%    -0.0%|  37.262   37.266   37.422    +0.4%    +0.5%
   32 | persistent   |  36.574   36.108   36.514    +0.1%    +1.1%|  37.238   37.242   37.360    -0.0%    +0.2%|  37.476   37.227   37.510    +0.2%    +0.8%
   33 | FilteredTopK |  22.773   22.775   21.834    -4.1%    -4.1%|  26.889   22.799   22.767   -15.3%    -0.0%|  26.880   24.138   22.838   -15.0%    -5.4%
   64 | FilteredTopK |  22.777   22.773   22.708    -0.4%    -0.4%|  26.878   22.798   22.776   -15.3%    -0.1%|  26.890   24.734   23.019   -14.4%    -6.9%
  128 | FilteredTopK |  22.775   22.773   22.771    +0.0%    +0.0%|  26.906   22.842   22.778   -15.3%    -0.3%|  26.978   24.834   23.936   -11.3%    -3.6%

wide_uniform | production dispatch | width=65,536 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  23.490   23.352   23.503    +0.3%    +0.6%|  23.392   23.333   23.504    +0.0%    +0.2%|  23.865   23.837   23.866    +0.0%    +0.1%
    8 | persistent   |  26.366   26.320   26.762    +1.3%    +1.5%|  26.612   26.686   26.882    +0.9%    +0.7%|  27.109   26.916   26.968    -0.3%    +0.2%
   16 | persistent   |  34.450   34.126   35.141    +2.1%    +3.0%|  35.442   35.226   35.329    +0.1%    +0.2%|  35.280   35.266   36.886    +4.5%    +4.0%
   32 | persistent   |  35.470   35.012   35.640    +0.7%    +1.5%|  35.141   35.204   35.347    +0.6%    +0.4%|  35.381   35.432   37.189    +4.9%    +5.0%
   33 | FilteredTopK |  28.932   26.882   26.929    -6.9%    +0.1%|  28.933   28.931   28.978    +0.2%    +0.2%|  39.183   30.991   32.889   -16.0%    +6.2%
   64 | FilteredTopK |  28.926   26.878   27.031    -6.5%    +0.7%|  28.923   28.919   29.250    +1.1%    +1.1%|  39.163   31.001   32.654   -16.7%    +5.3%
  128 | FilteredTopK |  28.930   26.878   27.865    -3.7%    +3.7%|  28.932   28.945   30.255    +4.6%    +4.7%|  39.188   31.018   33.022   -15.7%    +6.5%

wide_uniform | production dispatch | width=131,072 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  23.343   23.294   23.535    +0.2%    +0.6%|  23.263   23.166   23.295    +0.5%    +0.6%|  23.910   23.820   24.018    +0.7%    +0.8%
    8 | persistent   |  26.061   26.253   26.497    +1.7%    +0.9%|  26.502   26.488   26.779    +1.2%    +1.0%|  26.814   26.838   26.977    +0.6%    +0.4%
   16 | persistent   |  39.236   39.418   39.369    +0.3%    -0.2%|  39.305   39.382   40.536    +3.1%    +2.7%|  41.038   41.008   41.329    +0.8%    +0.7%
   32 | persistent   |  39.683   39.679   39.996    +1.0%    +1.0%|  39.480   39.516   40.981    +4.0%    +3.7%|  41.235   41.268   41.362    +0.3%    +0.1%
   33 | FilteredTopK |  47.385   45.322   46.614    -1.6%    +2.9%|  47.383   45.330   46.166    -2.7%    +1.8%|  47.388   49.412   49.450    +4.3%    +0.1%
   64 | FilteredTopK |  47.386   45.322   46.087    -2.8%    +1.7%|  47.372   45.324   46.040    -2.8%    +1.6%|  47.386   49.425   49.444    +4.3%    +0.0%
  128 | FilteredTopK |  47.415   45.313   46.346    -2.3%    +2.2%|  47.417   45.334   46.666    -1.5%    +2.9%|  47.510   49.424   49.809    +4.6%    +0.8%

wide_uniform | production dispatch | width=250,000 | time in us
 rows | dispatch     |                      topk=512                       |                      topk=1024                      |                      topk=2048                      
      |              |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR |    MAIN       PR       v7    vs MAIN   vs PR 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | persistent   |  24.790   24.808   24.817    +0.1%    +0.0%|  24.834   24.840   24.849    +0.1%    +0.0%|  24.784   24.791   24.802    +0.0%    +0.0%
    8 | persistent   |  47.820   47.418   47.941    +0.3%    +1.1%|  47.858   47.471   47.503    +0.1%    +0.1%|  48.268   48.355   47.932    -0.7%    -0.5%
   16 | persistent   |  41.314   41.317   42.862    +3.7%    +3.7%|  42.042   42.054   43.555    +4.0%    +3.9%|  42.800   42.988   43.382    +1.4%    +0.9%
   32 | persistent   |  77.850   77.922   79.498    +2.2%    +2.1%|  77.184   77.025   78.961    +2.4%    +2.8%|  78.912   79.010   80.765    +2.3%    +2.6%
   33 | FilteredTopK |  84.276   80.158   81.749    -3.2%    +2.0%|  84.608   80.166   81.962    -2.8%    +2.2%|  85.373   80.178   82.178    -3.7%    +2.5%
   64 | FilteredTopK |  85.585   80.185   82.208    -4.0%    +2.5%|  86.277   80.182   82.222    -4.7%    +2.5%|  86.329   80.245   82.227    -4.8%    +2.5%
  128 | FilteredTopK | 105.696  100.238  101.210    -3.8%    +1.0%| 105.735  100.590  102.003    -3.4%    +1.4%| 105.854  100.613  102.018    -3.7%    +1.4%

The table above contains all 504 workload cells. It reports the median kernel time across the three runs; the repository also contains every individual run value, Docker and reproduction commands, kernel sources, CSV results, and complete raw logs.

v7 is correctness-clean, but it is +1,384/-39 lines versus MAIN and still has normal-path regressions, so I am keeping it as a separate optimization experiment rather than adding it to this PR.

@xueyangcs

Copy link
Copy Markdown

@xijiaat @LopezCastroRoberto @yewentao256 We have an exact FP32 Top-K in HPC-Ops (src, PR) that does not silently drop candidates when a coarse histogram bin overflows, and matches torch.topk on the selected-value multiset. On H20 it is about 2× faster than vLLM’s exact Top-K paths (up to ~4× on long sparse rows). See the PR for detailed performance and all baseline comparisons.

@xijiaat

xijiaat commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

@xijiaat @LopezCastroRoberto @yewentao256 We have an exact FP32 Top-K in HPC-Ops (src, PR) that does not silently drop candidates when a coarse histogram bin overflows, and matches torch.topk on the selected-value multiset. On H20 it is about 2× faster than vLLM’s exact Top-K paths (up to ~4× on long sparse rows). See the PR for detailed performance and all baseline comparisons.

thanks!I’m still working on that!

@LopezCastroRoberto

Copy link
Copy Markdown
Contributor

v7 is correctness-clean, but it is +1,384/-39 lines versus MAIN and still has normal-path regressions, so I am keeping it as a separate optimization experiment rather than adding it to this PR.

@xijiaat I created #53287 to explore this problem more deeply. The goal of this PR is to produce deterministic outputs with no overhead on the non-overflow path and minimal impact when overflow occurs. It covers all three top-K variants we currently have, not only persistent top-k.

My plan is to do some cleanup and break this PR down into three smaller PRs, one per kernel, to make the review process easier. Since your PR explored this issue in the persistent_topk kernel, I’d be happy to collaborate and add you as a co-author. That way, we can avoid having multiple PRs exploring the same issue in parallel.

Would that work for you?

@xijiaat

xijiaat commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

v7 is correctness-clean, but it is +1,384/-39 lines versus MAIN and still has normal-path regressions, so I am keeping it as a separate optimization experiment rather than adding it to this PR.

@xijiaat I created #53287 to explore this problem more deeply. The goal of this PR is to produce deterministic outputs with no overhead on the non-overflow path and minimal impact when overflow occurs. It covers all three top-K variants we currently have, not only persistent top-k.

My plan is to do some cleanup and break this PR down into three smaller PRs, one per kernel, to make the review process easier. Since your PR explored this issue in the persistent_topk kernel, I’d be happy to collaborate and add you as a co-author. That way, we can avoid having multiple PRs exploring the same issue in parallel.

Would that work for you?

offcourse,I'm happy to work with you !!

cskkxjk pushed a commit to cskkxjk/vllm-deepseek-v4-sm89 that referenced this pull request Sep 6, 2026
Fixed-size candidate buffers can silently truncate narrow score distributions and return valid but incorrect top-k indices. Detect overflow and perform an exact bounded-memory radix rescan while retaining the existing fast paths for rows that fit.

Constraint: Fork-local backport containing only the persistent TopK fix; Qwen3.8-Flash-Next changes are excluded.

Rejected: Open a new upstream PR | vllm-project/vllm#52149 and #55314 already address this bug class.

Confidence: high

Scope-risk: narrow

Reversibility: clean

Directive: Submit an isolated PR and merge it into the fork main branch.

Tested: 13 targeted persistent TopK regression cases passed on SM120; ruff-check and clang-format passed.

Not-tested: SM89 hardware and end-to-end model evaluation.

Related: vllm-project/vllm#52149

Co-authored-by: ahmed xijiaat <52128022+xijiaat@users.noreply.github.com>

Assisted-by: OpenAI Codex

Signed-off-by: yhfgyyf <574821834@qq.com>
yewentao256
yewentao256 previously approved these changes Sep 8, 2026

@yewentao256 yewentao256 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the work!

@yewentao256 yewentao256 added the ready ONLY add when PR is ready to merge/full CI is needed label Sep 8, 2026
@yewentao256
yewentao256 dismissed their stale review September 8, 2026 20:34

Let's work on #53287 first

@mergify

mergify Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Hi @xijiaat, the pre-commit checks have failed. Please run:

uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: persistent_topk silently drops top-k candidates when many values share a coarse histogram bin

5 participants