Repository navigation
[Fix] dflash: Apply request penalties under DFLASH and DSPARK - #47020
Merged
hnyls2002 merged 7 commits intoNov 20, 2026
Merged
Conversation
repetition/frequency/presence penalties and min_tokens had no effect with --speculative-algorithm DFLASH or DSPARK (sgl-project#46752): - spec_prepare_for_decode never cumulated penalty output tokens for the DFLASH family (only eagle_prepare_for_decode did), so penalizer state stayed at identity. - apply_dflash_verify_logits_adjustments, _can_skip_verify_logits and verify_logits_adjustments_are_noop read acc_linear_penalties, which SamplingBatchInfo does not have, instead of the acc_additive_penalties / acc_scaling_penalties that copy_for_forward() produces. The dense fallback also scaled a zero buffer, dropping repetition_penalty. Cumulate in the DFLASH-family dispatch branch, apply both accumulated buffers broadcast over the verify block (a live penalizer goes through orchestrator.apply(repeat=)), and let the fast-path checks see them.
- test_dspark_sampling_accept_graph built its fake sampling_info with acc_linear_penalties, so verify_logits_adjustments_are_noop raised AttributeError on it once it read acc_additive/acc_scaling_penalties. - Drop the live-penalizer branch in apply_dflash_verify_logits_adjustments: the scheduler always hands workers a copy_for_forward() copy, so penalties only arrive as the acc_* buffers, as in EAGLE verify. - Replace the live-penalizer test with a grammar-mask + repetition_penalty case, which the old dense fallback got wrong.
cipheraxat
marked this pull request as ready for review
October 28, 2026 10:04
cipheraxat
requested review from
Qiaolin-Yu,
Ying1123,
hnyls2002 and
merrymercy
as code owners
October 28, 2026 10:04
…alties # Conflicts: # python/sglang/srt/speculative/dflash_worker_v2.py
Collaborator
|
/rerun-test test_dflash_verify_penalties.py test_dspark_sampling_accept_graph.py test_runtime_context.py test_eagle_worker_v2_topk1_fastpath.py test_dflash.py |
Contributor
|
🚀 🚀 |
…nd spec verify; drop the unused orchestrator repeat path and the DFlash verify penalty test
Collaborator
|
/rerun-test test_sampling_batch_info.py test_penaltylib.py test_sharded_verify.py test_eagle_post_verify_graphs.py test_dspark_sampling_accept_graph.py test_graph_pool_borrow.py registered/sampling/test_penalty.py test_dflash.py test_spec_eagle.py |
Contributor
|
🚀 🚀 |
Closed
4 of 5 tasks
jasperjiaguo
added a commit
to jasperjiaguo/sglang
that referenced
this pull request
Nov 21, 2026
Pick up the upstream fixes for the Hunyuan-4-Flash test breakage (sgl-project#51969) and the DFLASH / DSpark request-penalty change (sgl-project#47020); no conflicts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
shyeh25
added a commit
to shyeh25/sglang
that referenced
this pull request
Nov 21, 2026
Resolve conflicts with the per-request penalty pool (sgl-project#52035), DFLASH request penalties (sgl-project#47020) and the megakernel runtime binding (sgl-project#51676): the shared logit-adjustment check reads step_penalties, so penalized batches keep the dense verify and get upstream's penalties; the sparse accept syncs its decision across TP ranks like the dense selector accept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Fixes #46752. With
--speculative-algorithm DFLASHorDSPARK,repetition_penalty,frequency_penalty,presence_penaltyandmin_tokenshave no effect. Two causes:spec_prepare_for_decodenever cumulates penalty output tokens for the DFLASH family (onlyeagle_prepare_for_decodedoes), so penalizer state stays at identity.acc_linear_penalties, whichSamplingBatchInfodoesn't have, instead of theacc_additive_penalties/acc_scaling_penaltiesthatcopy_for_forward()produces. The dense fallback also scaled a zero buffer, which dropsrepetition_penalty.Modifications
spec_prepare_for_decode: cumulate in theis_dflash_family()branch, as EAGLE does. It stays per branch so EAGLE doesn't count twice.apply_dflash_verify_logits_adjustments: applyacc_additive_penaltiesandacc_scaling_penaltiesbroadcast over the verify block, as EAGLE verify does. The scheduler always hands workers acopy_for_forward()copy, so these buffers are the only way penalties arrive. The grammar fallback now applies only the vocab mask._can_skip_verify_logitsandverify_logits_adjustments_are_noopnow see the accumulated buffers, so penalized batches take the eager verify path. This also covers the DSPARK block-accept estimator gate from the issue, which uses the same check.test_dspark_sampling_accept_graph.py: its fakesampling_infohad the nonexistentacc_linear_penaltiesfield; it now has the two real ones.Penalties keep EAGLE's relaxed spec-decoding semantics (see Not covered). Requests without penalties are unaffected.
Validation
Unit tests on Colab T4, from
a1966e1b5d(main):test/registered/unit/spec/test_dflash_verify_penalties.pytest_dspark_sampling_accept_graph.py::test_routes_only_all_sampled_static_stepstest_schedule_batch_prepare_for_decode,test_decode_bookkeeping_ownership,test_mamba_prefill_track_metadata)With
ninjaon PATH, the wholetest_dspark_sampling_accept_graph.pyfile (CPU and CUDA cases) passes 7 of 7 on T4 with and without this PR. That run used upstream main as of today, which the PR applies to cleanly.End to end on an L4,
/generateat temperature 0, run on the first commit (the second commit only removes a branch the server never reaches). "Changed" means the output differs from the same request without the penalty.* MiniCPM5-2B also ignores these on this prompt without speculative decoding. On an open-ended prompt, both change DSPARK output.
To reproduce, start the DFLASH server (docs flags at TP1, plus two flags to fit the L4):
Then send the request with and without the penalty and compare the text:
For DSPARK, use the cookbook command:
--model-path openbmb/MiniCPM5-2B --trust-remote-code --speculative-algorithm DSPARK --speculative-draft-model-path openbmb/MiniCPM5-2B-DSpark --speculative-dspark-block-size 7, with the same two extra flags.Not covered
min_tokenshas no end-to-end check.min_tokenscounts verify steps, so EOS stays masked for aboutmin_tokenstimes the accept length. Changing that would affect EAGLE too.Checklist
CI States
Latest PR Test (Base): ❌ Run #44833441922
Latest PR Test (Extra): ⊘ Skipped -- add the
run-ci-nv-extralabel to opt in.Latest PR Test (AMD ROCm 10): ⏳ Run #44833441430
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: