Skip to content

[Bugfix][Sampler] Carry the boundary tie count across blocks in the split top-p mask kernel - #62046

Merged
njhill merged 4 commits into
vllm-project:mainfrom
cipheraxat:fix/split-topp-tie-count-61997
Oct 17, 2026
Merged

njhill merged 4 commits into
vllm-project:mainfrom
cipheraxat:fix/split-topp-tie-count-61997

Conversation

@cipheraxat

@cipheraxat cipheraxat commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Fixes #61997. The split top-p mask kernel (_topp_sb_mask_kernel) restarts its count of tied boundary tokens at every 8192-entry block. Slices longer than one block therefore keep too many copies of the boundary value. This PR carries the count across blocks, as the monolithic kernel already does.

Claims

  • In the split top-p pipeline (top-p-only rows, batch ≤ 64, CUDA/ROCm), the number of copies of a tied boundary value that are kept now matches the sort-based reference. The kept copies are the first ones in index order, as the cross-slice logic intends.
  • Rows without an exact tie at the boundary, and rows whose ties fit in one block, are unchanged.

Validation

All runs on an NVIDIA L4 (58 SMs, so S=1 at B=64; torch 2.14.0+cu132), branch at bc6de71192, VLLM_USE_PRECOMPILED=1.

New test, unfixed kernel (main version of topk_topp_triton.py): fails as expected.

pytest tests/v1/sample/test_topk_topp_sampler.py -k test_topp_ties_across_blocks
E   AssertionError: kept [4160], expected [2300]
1 failed, 133 deselected

Fixed kernel, the whole Triton class:

pytest tests/v1/sample/test_topk_topp_sampler.py -k TestTritonTopkTopp -v
95 passed, 39 deselected in 210.12s

Issue's repro script (4096 tied tokens at the boundary, B=64, p=0.7, run against the main kernel file; the script patches its own copy with the same line as this PR):

kernel ties over 8 blocks ties in 1 block
float64 reference 1913 (mass 0.700) 1913 (mass 0.700)
main 4160 (mass 0.994) 1913 (mass 0.700)
this PR 1913 (mass 0.700) 1913 (mass 0.700)

End to end: VLLM_USE_FLASHINFER_SAMPLER=0 routes top-p through these Triton kernels. With it set, LLM("Qwen/Qwen3-0.6B") generated 16 prompts with SamplingParams(temperature=1.0, top_p=0.95, max_tokens=48), which uses the split path at batch ≤ 16. All 16 completions came back with no errors, and the text reads normally.

Details

Root cause. A copy of the boundary value dup gets rank num_preceding + cumsum(dmask), and only copies with rank ≤ numkeep are kept. Here num_preceding is the number of copies in lower-indexed slices. The block loop never advanced num_preceding, so every block of a slice ranked its copies starting from the same base. Each block could keep up to numkeep - num_preceding copies of its own. Only slices longer than BLOCK=8192 are affected, i.e. S < V / 8192. On current GPUs, S is 1 or 2 at batch 64, so every current vocab hits this.

Fix. Add num_preceding += tl.sum(dmask.to(tl.float32)) after each block. It counts every copy, kept or not, which matches how the cross-slice num_preceding is built from nmin. The monolithic kernel counts kept copies (num_kept += tl.sum(duplicate_keep_mask)), which is equivalent here. The added work is one block reduction per block, and it runs only when the row has a tie at the boundary.

Test. test_topp_ties_across_blocks spreads 4096 tied tokens over every block of the row, at stride 37 in a 151936-entry vocab. It adds 64 higher tokens and a -8.0 tail, and sets p=0.75, so the boundary falls mid-copy inside the tie group. That keeps the fp32 reference from landing one copy off. The tail matters: if the tied value were the row's minimum, the ladder search could not place a pivot below it, and the row would take the keep-everything fallback before reaching the mask loop. The test asserts that the kept count equals apply_top_k_top_p_pytorch, and that the kept copies are an index-ordered prefix. The existing test_topp_tie_break_deterministic puts all its ties in one block, so it can't catch this. B=64 gives multi-block slices on any GPU with fewer than 256 SMs. That includes the H200 MIG slice used by the "V1 Sample" CI step. The test also still covers this after #61996, which shrinks slices to about 9.5K entries (two blocks) at this vocab.

Not duplicating: the issue has no comments or assignee, and searches for the issue number, num_preceding, topp_sb_mask and "split top-p tie" turned up no PR. #61996, also by the reporter, changes _topp_split_count but not the mask loop.

Model evals: the tests/evals/gsm8k configs either decode greedily or sample without top_p, so none of them reaches the split top-p path. They can't measure this change. The kernel-level comparison against a float64 reference is above.

cc @njhill @abmfy


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.

  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.

@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 Oct 16, 2026
…plit top-p mask kernel

_topp_sb_mask_kernel ranks copies of the boundary value as
num_preceding (copies in lower slices) plus their cumsum within the
current 8192-entry block, but never advanced num_preceding inside its
block loop. Each block of a slice restarted the count, so slices longer
than one block over-kept tied boundary tokens. Advance the count past
each block, as the monolithic kernel already does.

Fixes vllm-project#61997

Signed-off-by: cipheraxat <[email protected]>
@cipheraxat
cipheraxat force-pushed the fix/split-topp-tie-count-61997 branch from e5a49fe to bc6de71 Compare October 16, 2026 17:24

@njhill njhill 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 @cipheraxat

@njhill njhill added the ready ONLY add when PR is ready to merge/full CI is needed label Oct 16, 2026
@github-actions

Copy link
Copy Markdown

✅ @cipheraxat, CI is now available for this PR.

  • /ci run starts upstream CI; /amd-ci run starts AMD CI only.
  • Run commands test your branch with every commit currently on its upstream target branch. If it is behind, the bot merges the target branch into it first (pull before pushing again). Append --allow-stale to a run command to test an outdated branch as is, at your own risk.
  • /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.
  • /amd-ci retry retries failed jobs in AMD CI for the current PR head. Use /amd-ci run when the current head has no AMD CI build.
  • /ci cancel cancels scheduled or running CI builds for this PR branch; /amd-ci cancel does the same for AMD CI only.

@njhill
njhill enabled auto-merge (squash) October 16, 2026 18:04
@njhill

njhill commented Oct 16, 2026

Copy link
Copy Markdown
Member

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #95444 for commit 27e36deaed18.

@github-actions

Copy link
Copy Markdown

@cipheraxat

Copy link
Copy Markdown
Contributor Author

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #95476 for commit 0e9c5197d0ba.

ℹ️ This PR is 3 commits behind upstream main. Merged upstream main into this branch as 0e9c5197d0ba before starting CI. Pull the branch before pushing more changes.

@njhill
njhill merged commit ce49c47 into vllm-project:main Oct 17, 2026
161 checks passed
zamog added a commit to zamog/vllm that referenced this pull request Oct 17, 2026
Resolve the test conflict with vllm-project#62046 by keeping both new tests
(test_topp_keeps_forced_huge_logit and test_topp_ties_across_blocks).
The kernel merged cleanly: the probability-space mask from this PR plus
vllm-project#62046's num_preceding carry across blocks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Gilad Zamoscinski <[email protected]>
michael-gpu pushed a commit to practical-inference/vllm-ampere-extended that referenced this pull request Oct 20, 2026
…plit top-p mask kernel (vllm-project#62046)

Signed-off-by: cipheraxat <[email protected]>
Co-authored-by: cipheraxat <[email protected]>
Co-authored-by: Bowen Wang <[email protected]>
GindaChen added a commit to hao-ai-lab/rsibox that referenced this pull request Nov 8, 2026
…rd (#57)

## What and why

Distill what building FastRSI for vLLM taught us (prototype → v1 by restart boundaries → replay of 19 upstream PRs) into lessons future agents read, and turn the workflow fixes we are sure of into rules.

- **`docs/lessons.md`** (new, framework): 11 lessons, each "what happened (numbers, generic source) → rule → apply it": boundaries before mechanisms; toy proves the protocol, only a live engine proves the engine; find the cost ladder; replay real PRs as the end-to-end proof; build/import/capture-time code is not reached by a swap; programs schedule, agents judge; GPU locks checked and taken in one step; stacked-PR merge trap; review is advice (check re-raised findings at the new head); keep slow review off the merge path; talk in records.
- **`repos/vllm/kb/lessons.md`** (new, engine): pitfall/rule/evidence tables for the v1 replay findings (Triton `@jit`, constructors, the graph-split decorator, CustomOp re-registration, LazyLoader names), start-up measuring traps and node sharing.
- **`core/orchestrator.md`**: a "Roles in the loop" table (leader, Codex workers, GPU runner program, Antigravity, reviewers, owner) and how a brief and a report look; new rules 13–17: a standing replay per engine, when GPU receipts are due, stack merges, GPU sharing, the report format. Rule 2's evidence now has the measured numbers.
- **`AGENTS.md`**: three short bullets (stacks, where lessons go, the standing replay as the bar for fixes).

Drafted with Codex from a verified facts sheet, cross-checked by Antigravity for wrong facts and unclear wording (it caught that the Triton no-op was a prototype finding, so the v1 replay found 4 bugs, not 5); every number checked against its source. Leader review added the replay rerun on main bf7981a (2026-11-06 23:44 – 11-07 00:11 PST), which proved #52–#55 on GPUs, and the cache-root rule (reuse warm roots in place; a copied root rebuilt FlashInfer's JIT).

## Proposals (not encoded; for the owner to decide)

1. **Run the standing replay on a reserved GPU by schedule** (nightly + after each merge batch) and post the outcome diff to a PR or status page. Needs a standing GPU budget.
2. **Stop using native stacked PRs for lanes**: open the next PR only after the lower one merges (rebase onto main). Stacks needed two landing PRs (#36, #56).
3. **Owner-delegated merge**: an agent may merge after the owner comments `/merge`, with the base check. Saves the morning merge batch; changes "agents never merge".
4. **Antigravity fact check on every docs PR by default** (cheap, catches wrong numbers); code review stays opt-in.
5. **A `needs: gpu` label with a pending-replay status** so merged PRs without a GPU receipt are visible, without blocking merges.
6. **Clean up stale worktrees and stack branches** in the shared checkout so agents stop starting from old bases.

## Evidence

none (docs only). Leak check: `OK: no leak pattern` on the added lines. Sources (private, described generically in the docs): our 2026-11-06/07 replay summary (19 PRs, 50 runs), the replay rerun records on main bf7981a (12 runs), the 2026-11-06 start-up dissection, the v1 boundaries design and prototype records, PR bodies #33, #49, #51–#55.
Not shown: the new rules have not been exercised yet; the standing replay (rule 13) has no runner yet.

## Loop record

- Engine: vllm
- Upstream PRs: vllm-project/vllm#58231, vllm-project/vllm#59941, vllm-project/vllm#61213, vllm-project/vllm#61323, vllm-project/vllm#62046, vllm-project/vllm#62872 (cited as evidence; no new replay)
- Function groups: none (docs only)
- Rule added: standing replay per engine and "a replay fix is done when the replay shows it" (`core/orchestrator.md` rules 13–14, `AGENTS.md` Trust)
- Overheads measured: none (existing numbers cited with their sources)
- Receipts: none
- Not verified: the rerun covered the 4 fixed PRs and the 7 in-place ones, not all 19; vllm-project/vllm#61323 graph still reports `undo_ok` false (golden back and `at_base` true; code identity is "same content, new code objects"). `repos/vllm/kb/costs.md`, `mechanisms.md` and `docs/architecture.md` still cite the unpublished paper draft by name
zihaok pushed a commit to zihaok/vllm that referenced this pull request Nov 11, 2026
The verify-path top-p kernel (_topk_topp_kernel) is latency-bound on Rubin:
one persistent 8-warp program per SM sweeps its rows serially, and row costs
vary several-fold (the pivot search stops after 1-18 sweeps; flat rows take
the full-vocab fallback), so a static round-robin row assignment leaves most
SMs idle while the unluckiest programs finish.

- Move the per-row body into _topk_topp_row, shared by all kernels so they
  compile the per-row math to the same instructions (same tiles, warps and
  reduction layouts; PTX float-op mix verified identical).
- _topk_topp_dynamic_kernel: persistent programs take the next row from an
  atomic counter; 2 programs per SM with maxnreg=128 so both fit. Used for
  CUDA batches above the split pipeline's range (> 64 rows), registered for
  JIT warmup.
- Add CTA barriers between the outlier scatter-stores and the pivot search
  that reads them back from other threads (see _BUFFER_BARRIER_NOTE).

Bitwise identical to the old kernel on 320k randomized rows (batch 1..3000;
peaky / flat / tied / agentic logits; mixed temperatures, top-k and top-p).
Kernel time on Rubin at 1553 rows: 1.33x faster on agentic-like logits,
1.44x on peaky and 1.50x on mixed.

(cherry picked from commit 0e6958e)

Backport note (d63b810): the commit moves the per-row body into
_topk_topp_row, and this base has upstream changes to that code which the
commit's base lacks (vllm-project#61213, vllm-project#61996, vllm-project#58231, vllm-project#62046), so a 3-way merge
mangles the moved code. The file is the commit's version plus exactly that
delta; the vllm-project#61213 hunk (num_finite_total <= k) sits inside _topk_topp_row.

(cherry picked from commit a012d54)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GindaChen added a commit to hao-ai-lab/rsibox that referenced this pull request Nov 21, 2026
## What and why

Third PR of the rsibox stack. GPU cases that drive a real `vllm serve` through the rsibox HTTP API only, the calls an agent makes. The CPU tests prove the daemon's plumbing on the toy lab; these prove the plumbing does the right thing to a real engine.

`repos/vllm/examples/rsibox-e2e/` holds `cases.json` (43 step cases as data), `run.py` (runs them against one box and judges every reply) and `scenarios.py` (four box-level situations a step list cannot express). The runner saves the base output before each case and requires it again afterwards, so a case that leaks an edit fails itself.

| Group | Cases | Question |
|---|---|---|
| edits | 17 | does a good edit take effect, and does the undo really undo it |
| refusals | 16 | is a bad edit refused with the engine left untouched |
| lifecycle | 10 | does the box stay consistent over many calls |
| scenarios | 4 | calls during boot, a second call during a long check, the worker killed from outside, shutdown |

Three agents drafted 50 cases and three others reviewed them, two reviews per case. One was dropped as a duplicate, six prose scenarios were replaced by `scenarios.py`, and about twelve were fixed. The main fix: five cases with no-op edits could not detect an undo that leaves the edit in place, so each now installs the same edit again after the undo.

## Evidence

1× B200, vLLM 0.33, Qwen3-8B, tensor-parallel 1, eager.

| Run | Pass | Fail | Skip |
|---|---|---|---|
| local box, `run.py --fresh-state` | 43 | 0 | 0 |
| `scenarios.py` | 4 | 0 | 0 |
| same cases, box under nested gVisor | 36 | 3 | 4 |
| build whose `uninstall` reports success without undoing (stopped after 40 cases) | 10 | 26 | 4 |

- The 3 gVisor failures are the diff cases: the sandbox image has no `git`, so the lab refuses the diff with `patch_invalid`. The 4 skips are the restart comparisons, not enabled for that run.
- In the broken build, every one of the 10 passing cases is one that never performs an undo.
- Scenarios: `info` answered in 3 ms during a 141 s boot; a second verb got `busy` after 5.0 s while a 37.5 s check ran; after the worker was killed the session was poisoned, an install was refused, and `reset respawn` took 36 s; `down` left no process and no GPU memory.

This does not show anything under `torch.compile` or CUDA graphs, or on another engine.

## Loop record

- Engine: vllm
- Upstream PRs: none replayed as a loop iteration. Some cases send reverse ports of merged upstream PRs as diffs, for example vllm-project/vllm#57951 and vllm-project/vllm#62046.
- Function groups: none (no engine or adapter function changed)
- Rule added: a case about an edit that keeps the output must install the same edit again after the undo, or it cannot tell an undo from a no-op. It lives in the cases and in the example's README.
- Overheads measured: restart comparison about 150 s each (a second engine start); `reset respawn` 36 to 39 s. Source: our 2026-11-21 rsibox runs.
- Receipts: the tables above.
- Not verified: the suite on the plain Docker launcher, on AMD and under Slurm; the restart comparisons under gVisor; two scenario variants (close while edited, a verb that waits and then succeeds). Findings these runs made about the lab, not fixed here: an install or uninstall does not clear cached KV blocks, so a live edit to model code matches a restart only after `reset state`; `reset respawn` drops installed edits by design.
- Ideal full GPU test: 1 GPU that fits two engines, vLLM 0.33 with a text model, all 43 step cases with `--fresh-state` and the 4 scenarios, on each launcher, plus a broken build to show the cases can fail.
- Actual tests run: `python3 run.py --out results.json --fresh-state <scratch>` on a local box (43 pass, 0 fail, 0 skip); `python3 scenarios.py --state <dir>` (4 pass); `run.py` against a nested-gVisor box (36 pass, 3 fail, 4 skip); `run.py` against the broken build (26 fail of 40 run).
- Why unrun GPU paths were skipped: the other launchers and AMD, for lack of time; the restart comparisons under gVisor need a second engine inside the sandbox, which the runner does not start yet.
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]: Split top-p mask kernel restarts its tie count every 8192 entries and over-keeps boundary ties

3 participants