Skip to content

[Fix] dflash: Apply request penalties under DFLASH and DSPARK - #47020

Merged
hnyls2002 merged 7 commits into
sgl-project:mainfrom
cipheraxat:fix/dflash-dspark-penalties
Nov 20, 2026
Merged

hnyls2002 merged 7 commits into
sgl-project:mainfrom
cipheraxat:fix/dflash-dspark-penalties

Conversation

@cipheraxat

@cipheraxat cipheraxat commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Fixes #46752. With --speculative-algorithm DFLASH or DSPARK, repetition_penalty, frequency_penalty, presence_penalty and min_tokens have no effect. Two causes:

  1. spec_prepare_for_decode never cumulates penalty output tokens for the DFLASH family (only eagle_prepare_for_decode does), so penalizer state stays at identity.
  2. DFLASH verify and its fast-path checks read acc_linear_penalties, which SamplingBatchInfo doesn't have, instead of the acc_additive_penalties / acc_scaling_penalties that copy_for_forward() produces. The dense fallback also scaled a zero buffer, which drops repetition_penalty.

Modifications

  • spec_prepare_for_decode: cumulate in the is_dflash_family() branch, as EAGLE does. It stays per branch so EAGLE doesn't count twice.
  • apply_dflash_verify_logits_adjustments: apply acc_additive_penalties and acc_scaling_penalties broadcast over the verify block, as EAGLE verify does. The scheduler always hands workers a copy_for_forward() copy, so these buffers are the only way penalties arrive. The grammar fallback now applies only the vocab mask.
  • _can_skip_verify_logits and verify_logits_adjustments_are_noop now 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 fake sampling_info had the nonexistent acc_linear_penalties field; 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 main this PR
New test/registered/unit/spec/test_dflash_verify_penalties.py 5 of 6 fail 6 pass
test_dspark_sampling_accept_graph.py::test_routes_only_all_sampled_static_steps pass pass
Related suites (test_schedule_batch_prepare_for_decode, test_decode_bookkeeping_ownership, test_mamba_prefill_track_metadata) 18 pass 18 pass

With ninja on PATH, the whole test_dspark_sampling_accept_graph.py file (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, /generate at 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.

Server repetition_penalty=2.0 frequency_penalty=2.0 presence_penalty=2.0
DFLASH, main unchanged unchanged unchanged
DFLASH, this PR changed changed changed
DSPARK, main unchanged unchanged unchanged
DSPARK, this PR changed unchanged* unchanged*

* 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):

python3 -m sglang.launch_server --model-path Qwen/Qwen3-4B --speculative-algorithm DFLASH --speculative-draft-model-path z-lab/Qwen3-4B-DFlash-b16 --attention-backend flashinfer --speculative-draft-attention-backend flashinfer --cuda-graph-backend-prefill disabled --cuda-graph-max-bs-decode 4 --mem-fraction-static 0.8

Then send the request with and without the penalty and compare the text:

curl -s localhost:30000/generate -d '{"text": "Repeat the sentence '\''The weather is very nice today.'\'' five times, one per line:\n", "sampling_params": {"temperature": 0, "max_new_tokens": 96, "repetition_penalty": 2.0}}'

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

  • No accuracy or throughput runs.
  • Not run on Hopper/Blackwell or multi-GPU. Grammar-constrained requests are covered by a unit test only.
  • min_tokens has no end-to-end check.
  • As in EAGLE, one token per request is cumulated per verify step. With multi-token accepts, penalties don't see tokens accepted mid-block, and min_tokens counts verify steps, so EOS stays masked for about min_tokens times 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-extra label 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-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

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
cipheraxat marked this pull request as ready for review October 28, 2026 10:04
…alties

# Conflicts:
#	python/sglang/srt/speculative/dflash_worker_v2.py
@hnyls2002 hnyls2002 added the run-ci CI: run the baseline test suite on this PR label Nov 20, 2026
@hnyls2002

Copy link
Copy Markdown
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

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (3 tests): ✅ View workflow run

cd test/ && python3 registered/unit/spec/test_dflash_verify_penalties.py  # base-a
cd test/ && python3 registered/unit/test_runtime_context.py  # base-a
cd test/ && python3 registered/unit/spec/test_eagle_worker_v2_topk1_fastpath.py  # base-a

🚀 1-gpu-5090 (2 tests): ✅ View workflow run

cd test/ && python3 registered/unit/speculative/test_dspark_sampling_accept_graph.py  # base-b
cd test/ && python3 registered/spec/dflash/test_dflash.py  # extra-a

…nd spec verify; drop the unused orchestrator repeat path and the DFlash verify penalty test
@hnyls2002

Copy link
Copy Markdown
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

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (2 tests): ✅ View workflow run

cd test/ && python3 registered/unit/sampling/test_sampling_batch_info.py  # base-a
cd test/ && python3 registered/unit/sampling/test_penaltylib.py  # base-a

🚀 1-gpu-5090 (7 tests): ✅ View workflow run

cd test/ && python3 registered/unit/spec/test_sharded_verify.py  # base-b
cd test/ && python3 registered/unit/spec/test_eagle_post_verify_graphs.py  # base-b
cd test/ && python3 registered/unit/speculative/test_dspark_sampling_accept_graph.py  # base-b
cd test/ && python3 registered/unit/model_executor/runner_utils/test_graph_pool_borrow.py  # base-b
cd test/ && python3 registered/sampling/test_penalty.py  # base-b
cd test/ && python3 registered/spec/dflash/test_dflash.py  # extra-a
cd test/ && python3 registered/spec/eagle/test_spec_eagle.py  # base-b

@hnyls2002
hnyls2002 merged commit ed939d6 into sgl-project:main Nov 20, 2026
139 of 149 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] DSPARK/DFLASH speculative decoding silently ignores repetition_penalty / frequency_penalty / presence_penalty

2 participants