Repository navigation
[Feat] speculative: Apply exact per-row sampling penalties in verify - #52054
Conversation
Co-authored-by: sgrigory <[email protected]>
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
|
/rerun-test test/registered/kernels/ops/sampling/test_verify_penalties.py test/registered/unit/spec/test_verify_penalty_paths.py test/registered/spec/eagle/test_spec_eagle.py test/registered/spec/eagle/test_spec_eagle_topk.py test/registered/spec/dflash/test_dflash.py test/registered/spec/test_spec_ngram.py test/registered/sampling/test_penalty.py |
|
🚀 🚀 🚀 |
|
/tag-and-rerun-ci |
…keep request params in the pool; port the penalized eos e2e kit Co-authored-by: sgrigory <[email protected]>
|
/rerun-test test/registered/kernels/ops/sampling/test_verify_penalties.py test/registered/unit/spec/test_verify_penalty_paths.py test/registered/unit/sampling/test_penalty_status_pool.py test/registered/unit/sampling/test_sampling_metadata_staging.py test/registered/spec/eagle/test_spec_eagle.py test/registered/spec/eagle/test_spec_eagle_topk.py test/registered/spec/dflash/test_dflash.py test/registered/spec/test_spec_ngram.py test/registered/sampling/test_penalty.py test/registered/core/test_basic_sanity_dflash.py test/registered/core/test_basic_sanity_dspark.py test/registered/spec/test_spec_mixed_chunk.py |
|
🚀 🚀 🚀 |
Co-authored-by: sgrigory <[email protected]>
Resolve the conflict with exact per-row verify penalties (sgl-project#52054): keep the shared logit-adjustment check as an early return in apply_dflash_verify_logits_adjustments and take upstream's new body (verify_tokens, step_penalties.apply_verify, custom logit processor last). Penalized batches still keep the dense verify. Co-Authored-By: Claude Opus 5.5 <[email protected]>
main (sgl-project#52184) replaced apply_dflash_verify_logits_adjustments with the shared verify stage. PARD2 now adjusts the verify logits with adjust_verify_logits and commits the accepted block with TargetVerify.commit, as DFlash does: the commit feeds the accepted tokens to the per-request penalty history (sgl-project#52054) and computes the logprobs.
…0-03fde9cc Root cause: nightly-dev-cu13-20261122-e96e9675 includes sgl-project/sglang#52054, which raised MEGAKERNEL_API_VERSION to 3 while its bundled sgl-nvidia-mega plugin still exposes API version 2 (sgl-project/sgl-nvidia-mega#85 is still open). All four agg points enable --enable-nvidia-megakernel and fail at startup on that image, whereas disagg does not enable the megakernel and stays on 20261122. Fix: roll dsv41flash-fp4-gb300-dynamo-sglang-agentic-agg back to nightly-dev-cu13-20261120-03fde9cc (Dynamo 1.8.0.dev20261119, SGLang 0.0.0.dev1+g03fde9cc3) in nvidia-master.yaml, agg-variants.yaml, and the PR perf-changelog.yaml entry, leaving the disagg key on 20261122-e96e9675. Validation: all four agg points previously succeeded on 20261120-03fde9cc in the PR sweep; local changelog, curve, and recipe generation checks pass.
Fixes the unit test failures that running against SGLang main exposes (#81), where they come from SGLang interface changes this package can follow on its own: - Megakernel API 3 (sgl-project/sglang#52054 replaced the verify penalty tables with step_penalties): every spec declares API 3; Kimi K3.1's base declares 3 on a host with VerifyPenaltiesView. No spec read the removed tables; the GLM-5.3 SM107 verify tail and the spec_step runner now decline on step_penalties, and the runner on watermark. - --enable-dp-attention is gone (sgl-project/sglang#51074): GLM-5.3's draft checks read attn_dp_enabled, Qwen3.5's topology attn_dp_size. The GLM checks read the old field with getattr and so passed silently. - Kimi K3.1's DFlash runtime: SGLang shares one verify logit adjustment (sgl-project/sglang#52184, #52159); the runtime hands rounds back on adjusts_logits() or a sampling mask and adjusts the gathered greedy logits with adjust_verify_logits. - Qwen3.5 MTP: mtp.fc is a ReplicatedLinear (sgl-project/sglang#49790) and returns (output, bias); fc_input took the tuple as the output. - Moved names: next_power_of_2 (utils/triton_utils), is_cuda and is_float4_e2m1fn_x2 (utils/device; Muse Spark imported the latter from a module that no longer has it), hf_transformers (srt/). - Mirrors re-read and re-pinned where SGLang's change does not reach the mirrored path (XPU / HIP / NPU / Ascend branches, sliding-window writes Qwen3.5 has none of, a bias out_proj the GDN step declines, the ReplaySSM ring index that equals the request row for GDN, prefill staging for the strided pools the prefill slot declines). - Test fakes follow SGLang's GDN backend, a2a backend and dp_attention helpers. Still failing against SGLang main, for their owners: Kimi K3's DSpark verify views (removed by sgl-project/sglang#48414), the GLM-5.3 mirrors, Qwen3.5's ReplaySSM kernel mirror, Muse Spark's candidate top-k and the spec_step lifted eagle_sample. Co-Authored-By: Claude Opus 5.5 <[email protected]>
* [CI] test: Run the CPU unit tests against SGLang main The unit tests ran against SGLang cf6133a (2026-11-05), 1253 commits behind main on 2026-11-20. At that pin the contract tests skip every check whose SGLang side it lacks, including all of Kimi K3.1's bindings. Check out SGLang main instead, install SGLang's own torch pin, and record the SGLang commit in the job summary. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] all: Follow SGLang main in the unit-tested contracts Fixes the unit test failures that running against SGLang main exposes (#81), where they come from SGLang interface changes this package can follow on its own: - Megakernel API 3 (sgl-project/sglang#52054 replaced the verify penalty tables with step_penalties): every spec declares API 3; Kimi K3.1's base declares 3 on a host with VerifyPenaltiesView. No spec read the removed tables; the GLM-5.3 SM107 verify tail and the spec_step runner now decline on step_penalties, and the runner on watermark. - --enable-dp-attention is gone (sgl-project/sglang#51074): GLM-5.3's draft checks read attn_dp_enabled, Qwen3.5's topology attn_dp_size. The GLM checks read the old field with getattr and so passed silently. - Kimi K3.1's DFlash runtime: SGLang shares one verify logit adjustment (sgl-project/sglang#52184, #52159); the runtime hands rounds back on adjusts_logits() or a sampling mask and adjusts the gathered greedy logits with adjust_verify_logits. - Qwen3.5 MTP: mtp.fc is a ReplicatedLinear (sgl-project/sglang#49790) and returns (output, bias); fc_input took the tuple as the output. - Moved names: next_power_of_2 (utils/triton_utils), is_cuda and is_float4_e2m1fn_x2 (utils/device; Muse Spark imported the latter from a module that no longer has it), hf_transformers (srt/). - Mirrors re-read and re-pinned where SGLang's change does not reach the mirrored path (XPU / HIP / NPU / Ascend branches, sliding-window writes Qwen3.5 has none of, a bias out_proj the GDN step declines, the ReplaySSM ring index that equals the request row for GDN, prefill staging for the strided pools the prefill slot declines). - Test fakes follow SGLang's GDN backend, a2a backend and dp_attention helpers. Still failing against SGLang main, for their owners: Kimi K3's DSpark verify views (removed by sgl-project/sglang#48414), the GLM-5.3 mirrors, Qwen3.5's ReplaySSM kernel mirror, Muse Spark's candidate top-k and the spec_step lifted eagle_sample. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Test] kimi_k3: Build the hybrid views as SGLang main defines them SGLang's hybrid binding views are dataclasses now (sgl-project/sglang#48414): MlaPoolView takes dtype codes and an int serving capacity, and KdaStepView.track_decode_state is a method (SGLang snapshots the KDA state after the step). The Kimi K3 tests build the views that way and record the executor's per-layer tracking by patching that method. The DSpark verify fields (tokens_per_request, verify_scratch_indices, aux_hidden_states and the KDA verify scratch) need the SGLang change that offers them again. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] glm5_3: Follow SGLang main in the mirrored verify and draft steps Store the verify KV through KVWriteLoc.for_batch, as the DSA backend now does (a unified pool refuses a bare loc), and refuse an indexer without RoPE, which SGLang now quantizes without it. Re-pin the ten mirrors whose SGLang changes leave the served path as it was: Kimi-K3 / DCP / ROCm / Prims-TS branches, beam-search and candidate-selector logits, and helper extractions with the same calls. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] muse_spark: Read the candidate top-k names SGLang main defines SGLang now takes the shard top-k from radix_topk and gathers over the target lm_head's own group (sgl-project/sglang#47267). Follow it in the eligibility check, the shard top-k and the stock tail. The dflash.py source pins are unchanged, so on a revision they do not list the component keeps the stock path until it is validated there. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] spec_step: Lift _tree_accept from SGLang main for the verify fusions SGLang split eagle_sample into the logit adjustment and _tree_accept, and took the per-request temperature softmax and a packed verify broadcast upstream. Lift _tree_accept instead of the stale eagle_sample copy: the packed broadcast also follows the Mega switch, the lean chain verify drops the zero-filled draft probs, and the chunked sampling applies with it. Pin the lifted body as a mirror so the next SGLang change to it is caught. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] qwen3_5: Port SGLang's ReplaySSM verify kernel changes into the fork SGLang's gdn_replayssm_spec_circular_kernel now reads the ring cursors with a stride (they can sit in one request sub-pool entry), skips the history terms of a row without committed history, and selects the causal terms with tl.fma so a non-finite rejected draft cannot reach an earlier position. Apply the same changes to the fork, keeping its dependent launch; the history decay stays before the wait. Under the Triton interpreter the fork matches SGLang's verify launch bitwise (output and ring entries, with and without history, contiguous and strided cursors). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…PI v3 and contract (#103) * [Fix] minimax_m31: Speak megakernel API version 3 and follow SGLang main's contract #66 merged after #81 moved the unit tests to SGLang main, but its last unit run was against the old pinned SGLang, where the MiniMax-M3.1 checks are skipped. On SGLang main the spec is refused at registration and four contract checks fail, so main's unit job has been red since #66. - Megakernel API 3 (sgl-project/sglang#52054 replaced the verify penalty tables with step_penalties): declare 3, as #81 did for the other specs. The package reads no verify sampling penalties (its slots are the verify forward and the DSpark draft proposal), so nothing else changes. - sgl-project/sglang#52870 moved minimax_sparse_nvfp4_backend.py to minimax_sparse/msa_v1_backend.py; msa_v1_decode_plan is the same field. Name the new file first and keep the old one as the alternative. - fused_experts_none_to_flashinfer_trtllm_fp4: sgl-project/sglang#50195 passes the ignored output buffer on the logits-routed path too; the routed-top-k path moe_nofill follows already passed it. Re-pin. - _draft_step and _markov_sample_partial_kernel: sgl-project/sglang#51298 adds a step softcap and vocab limit that only Inkling2's MTP head sets, and #52728 a folded-bias kernel path _draft_step never takes. The chain serves only VanillaMarkov, which leaves both None. Re-pin. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] qwen3_5: Follow SGLang main's GDNAttnBackend.forward_extend sgl-project/sglang#39595 (FlyDSL GDN prefill on AMD) passes prefill_metadata=self.kernel_prefill_metadata to the extend kernel in the prefill arm of forward_extend, None for every kernel but FlyDSL, and adds kernel_prefill_metadata = None to GDNAttnBackend. - gdn/prefill.py serves only the Triton prefill kernel (view.kernel_id), and gdn/verify.py mirrors the target-verify arm, which the change does not touch. Re-pin both mirrors. - The runtime tests' fake GDN backend gains kernel_prefill_metadata=None, as SGLang's class now defines it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] kimi_k31: Follow SGLang main's verify sampling stages in the DFlash runtime sgl-project/sglang#52406 deleted sampling_batch_info.adjusts_logits and speculative/target_verify.py (adjust_verify_logits). SGLang's DFlash round now reads VerifyRoute.adjusts_logits and calls VerifyStep.adjust from SamplingPipeline.plan_verify. The K3.1 DFlash runtime imported both old names, so it no longer imported on SGLang main. - _unserved: VerifyRoute.derive(...).adjusts_logits is the same predicate as adjusts_logits (grammar, watermark, penalties, logit bias or a custom logit processor), so the same rounds go back to SGLang. - _accept, greedy round on gathered logits: the target's sampling_pipeline.plan_verify(batch, watermark_full_mask=False).adjust() runs the same stages in the same order as adjust_verify_logits did: penalties along the chain, logit bias and the custom logit processor, each width rows per request, with no grammar mask. DFlash refuses the watermark, so none is bound. As before, _unserved already refuses every round these stages would change. - The test fakes gain the target's sampling_pipeline and need_min_p_sampling, which SGLang's SamplingBatchInfo defines. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] qwen3_5: Re-pin GDNAttnBackend.forward_extend after sgl-project/sglang#44195 sgl-project/sglang#44195 gives the Triton GDN kernel an FP32 track snapshot and gates the snapshot in forward_extend's prefill arm on use_track_state_snapshot(): a snapshot-capable kernel in batch-invariant mode. - gdn/prefill.py: only --enable-deterministic-inference turns on batch-invariant mode, and it refuses the trtllm_mha attention backend this spec requires. The served prefill arm still writes checkpoints from the per-chunk states, as the slot does. Re-pin. - gdn/verify.py mirrors the target-verify arm, which the change does not touch. Re-pin. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Motivation
Follow-up to #52035. Speculative verify scores several draft positions of a request in one forward, but every verify row of a request got the same penalty: the request's history as of the start of the block. A row at draft depth
dtherefore missed the draft tokens before it on its own path, andmin_new_tokenswas off byd.With the history now in a per-request device pool, exactness only needs the same formula applied over the pool counts plus each row's ancestor tokens. This replaces #51903: it covers EAGLE trees and NGRAM as well as DFlash and DSpark, it is exact on every device, and it costs less per step.
Modifications
sampling.verify_penalties(JIT, CUDA sm_80+), inkernels/jit/csrc/sampling/verify_penalties.cuh.rof requesticountscounts[penalty_index_i]plus the in-vocab draft tokens onr's path. The root is excluded andritself is included.min_new_tokensis gated bylens + depth(r).next_child/next_siblingformat; with neither, the block is a chain.cp.asyncand rewritten with 16-byte vectors.div.full.f32division that the compiledapply_scaling_penaltiesuses.sampling.accumulate_penalty_counts: one launch with exact int32 atomics oncountsandlens. It replacesindex_put_/index_add_on CUDA, with the same out-of-vocab and accept-mask rules.PenaltyStatusPoolkeeps each request's params (frequency, presence, repetition,min_new_tokens, padded stop ids) on the device, written atalloc.StepPenalties.builduploads only the step's indices, in one H2D copy.StepPenalties.apply_verifyruns the kernel on CUDA sm_80+ and an exact torch fallback elsewhere.eagle_sample. This covers both post-verify routes.VerifySamplingViewcarriesstep_penalties(VerifyPenaltiesView) instead of the two block-start tables, andMEGAKERNEL_API_VERSIONis now 3.apply_acc_penalties,has_acc_penalties, theacc_additive_penalties/acc_scaling_penaltiesviews, and the table build incopy_for_forward. Non-spec tables are built when sampling first reads them.Behavior changes
VerifySamplingViewno longer exposes the two penalty tables. No in-tree provider read them; an out-of-tree provider that did must callstep_penalties.apply_verify.[rows, vocab]temporaries.min_new_tokensare read once at admission.Follow-up
A Triton verify kernel for ROCm and pre-sm_80 CUDA, so those devices stop paying the torch fallback's time and memory. It must pass the bit-exact
test_verify_penalties.pyagainst the non-spec path; the CUDA kernel here and the Triton kernel in #51903 are references.Accuracy Tests
kernels/ops/sampling/test_verify_penalties.pyis bit-exact (compared as integer bit patterns) against the real non-spec path. Each row decodes one token at a time throughStepPenaltiesandSamplingBatchInfo.apply_logits_bias. Coverage:min_new_tokenscrossing within the depth;The torch fallback is checked bitwise on CPU.
unit/spec/test_verify_penalty_paths.py:PenalizedEOSMixin(from [Fix] speculative: Exact sampling penalties and min_new_tokens in DFlash and DSpark verify #51903) sends greedy requests with penalties,min_new_tokensand a +100 logit bias on EOS, and requires each request to stop one token after its minimum. It is mixed into:The EAGLE case passes locally on B300.
Unit tests in sampling, spec and speculative pass, except failures that also fail on main.
Speed Tests and Profiling
Device time per verify step for penalties on B300, with V=151936, all four penalties set, and about 500-token histories. #51903 is measured on the same harness: its block-start tables, verify kernel, and anchor plus draft counts. This PR is measured as verify plus commit.
Host time per step for building the step and committing went from about 330-560 us to about 50-75 us.
Checklist
Co-authored-by: sgrigory [email protected]
CI States
Latest PR Test (Base): 🚫 Run #44956872163
Latest PR Test (Extra): ⊘ Skipped -- add the
run-ci-nv-extralabel to opt in.Latest PR Test (AMD ROCm 10): 🚫 Run #44956872079
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: