Skip to content

[Perf] dsv41: Trim per-step DSpark decode overhead - #46176

Merged
hnyls2002 merged 6 commits into
mainfrom
lsyin/dspark-aux-mean
Oct 24, 2026
Merged

hnyls2002 merged 6 commits into
mainfrom
lsyin/dspark-aux-mean

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Small per-step DSpark decode costs on DeepSeek-V4.1, each removed without changing any output bit.

  • hc stream mean: mhc_stream_mean, a Triton kernel that averages the four hc streams in torch's order (in-order fp32 sum onto +0); used for the DSpark captures and the replay tail. Unverified shapes and dtypes fall back to x.mean(dim=1).
  • aux packing: V4 collects the captures in AuxHiddenStatePacker, and the mean writes straight into its slot, so the logits processor no longer torch.cats them.
  • markov draft step: when one rank holds the whole unpadded vocabulary (TP1, or DP attention with --enable-dp-lm-head), skip the identity vocab gather so the draft step runs one pass instead of two.
  • draft wo_a: on Blackwell, target-verify calls outside the TP4 fast path (more rows, other group counts, as in the DSpark draft) use the existing strided bmm instead of einsum + transpose copy.

Without DSpark nothing changes.

Verification

  • New test_mhc_stream_mean.py pins the kernel bitwise to x.mean(dim=1), including inf, NaN, overflow and all -0 rows.
  • Packed captures, markov draft tokens and step logits, and draft wo_a outputs are bitwise equal to the previous code, eager and under CUDA graph replay.
  • Existing DSv4 / DSpark unit tests pass.

CI States

Latest PR Test (Base): 🚫 Run #40040572712
Latest PR Test (Extra): ❌ Run #40040572575
Latest PR Test (AMD ROCm 10): 🚫 Run #40040572686

@hnyls2002 hnyls2002 changed the title [Perf] dsv41: Average the DSpark capture hc streams with a Triton kernel [Perf] dsv41: Average the DSpark capture hc streams with a Triton kernel and pack them without a cat Oct 23, 2026
@hnyls2002 hnyls2002 changed the title [Perf] dsv41: Average the DSpark capture hc streams with a Triton kernel and pack them without a cat [Perf] dsv41: Trim per-step DSpark decode overhead (hc stream mean, aux packing, markov draft step) Oct 23, 2026
@hnyls2002 hnyls2002 changed the title [Perf] dsv41: Trim per-step DSpark decode overhead (hc stream mean, aux packing, markov draft step) [Perf] dsv41: Trim per-step DSpark decode overhead (hc stream mean, aux packing, markov draft step, draft wo_a) Oct 23, 2026
@hnyls2002 hnyls2002 changed the title [Perf] dsv41: Trim per-step DSpark decode overhead (hc stream mean, aux packing, markov draft step, draft wo_a) [Perf] dsv41: Trim per-step DSpark decode overhead Oct 23, 2026
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test registered/kernels/ops/layernorm/test_mhc_stream_mean.py registered/kernels/ops/speculative/test_dspark_markov_sample.py registered/spec/dspark/test_dspark_draft_graph.py registered/unit/spec/test_dspark_deferred_commit.py registered/kernels/ops/gemm/test_dsv4_wo_a.py registered/kernels/ops/attention/test_wo_a_fused.py registered/unit/models/test_deepseek_v4_boundary.py registered/unit/models/test_deepseek_v4_platform_dispatch.py registered/unit/layers/test_dsv41_late_layer_tail_readers.py registered/unit/layer_boundary/test_aux_hidden_states.py registered/unit/model_executor/model_runner_components/test_spec_aux_hidden_state.py registered/unit/spec/test_dspark_draft_block.py registered/e2e/models/test_deepseek_v41_flash_gb300_dp2ep2.py registered/e2e/models/test_deepseek_v41_flash_gb300_tp2ep2.py

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/layernorm/test_mhc_stream_mean.py

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

cd test/ && python3 registered/kernels/ops/speculative/test_dspark_markov_sample.py
cd test/ && python3 registered/spec/dspark/test_dspark_draft_graph.py
cd test/ && python3 registered/unit/spec/test_dspark_deferred_commit.py

🚀 4-gpu-b200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/gemm/test_dsv4_wo_a.py
cd test/ && python3 registered/kernels/ops/attention/test_wo_a_fused.py

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

cd test/ && python3 registered/unit/models/test_deepseek_v4_boundary.py
cd test/ && python3 registered/unit/models/test_deepseek_v4_platform_dispatch.py
cd test/ && python3 registered/unit/layers/test_dsv41_late_layer_tail_readers.py
cd test/ && python3 registered/unit/layer_boundary/test_aux_hidden_states.py
cd test/ && python3 registered/unit/model_executor/model_runner_components/test_spec_aux_hidden_state.py
cd test/ && python3 registered/unit/spec/test_dspark_draft_block.py

🚀 2-gpu-gb300 (2 tests): ❌ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_dp2ep2.py
cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_tp2ep2.py

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 23, 2026
@hnyls2002
hnyls2002 merged commit 79e5c4b into main Oct 24, 2026
240 of 305 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/dspark-aux-mean branch October 24, 2026 00:24
akhilg-nv added a commit to akhilg-nv/sglang that referenced this pull request Oct 27, 2026
… CUDA-graph replay and at the prefill gate

Verify and draft forwards run wo_a inside CUDA graphs, and bitwise equality there
also depends on cuBLAS picking the same kernel under capture.
test_wo_a_strided_bmm_graph_replay_matches_einsum captures one call per shape of
test_wo_a_strided_bmm_matches_einsum, replays it three times on refreshed inputs
and weights, and checks token-major output equal to the einsum. Against the code
before the 8-group change, its 8-group case fails on the layout assertion and its
2-group case passes.

test_wo_a_strided_bmm_gate_rejects_unmeasured_prefill checks that 4095 prefill
rows at 8 groups, and 4 groups at 4096 rows, keep the einsum's group-major output.
Gate mutants that admit 4095 rows or 4 groups each fail exactly their own case.
Only prefill bounds are checked: main (sgl-project#46176) sends every Blackwell
target-verify call to the same strided bmm at any row and group count, so the
384-row verify bound is not a contract once this branch is rebased.

The two case lists are shared through _strided_bmm_cases. The file takes 23-35 s
on B200 (the new cases add under 0.3 s), so est_time stays at 40. Both new tests
also pass with this branch's deepseek_v4.py hunks merged onto main ee2dd72.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
chaohu2000 added a commit to flytiger-eco/sglang-for-sail that referenced this pull request Oct 27, 2026
(cherry picked from commit 2f51076c18187dd4acd392b0e3a66875994a4393)
akhilg-nv added a commit to akhilg-nv/sglang that referenced this pull request Oct 28, 2026
…s per rank too

At attention TP 2 a rank holds 4 of the 8 wo_a groups. The strided-bmm fast
path accepted 2 and 8 groups only, so 4-group prefill calls (4096-65536 rows,
Blackwell) still ran torch.einsum, whose group-major result wo_b's flatten(1)
copies in every layer, and 4-group single-token decode (Blackwell, SM90) ran the
einsum as well.

Accept 4 groups in the CUDA shape gate. Like 8 groups, they take only the
strided bmm: the 1-row gemv and the 2-8-row Triton kernels stay 2-group only.
HIP is unchanged. 4-group target verify already took this bmm through sgl-project#46176's
fallback branch.

One call at 4 groups (32 heads per rank), CUDA-graph replay, median us per call
over 3 runs, einsum + copy -> strided bmm:
  B200: 4096 rows 152.9 -> 102.9, 8192 rows 299.6 -> 188.6,
        16384 rows 655.3 -> 358.1, 65536 rows 2192 -> 1710
  B300: 4096 rows 157.0 -> 107.5, 8192 rows 321.5 -> 191.5,
        16384 rows 570.9 -> 409.2, 65536 rows 2170 -> 1754
Single-token decode does not change (B200 12.11 vs 12.12 us, B300 11.91 vs
11.92 us, H100 14.39 vs 14.39 us); the einsum's 1-row output is already
token-major.

The eager and graph-replay strided-bmm tests also run at 4 groups (decode,
target verify 1-384 rows, prefill 4096-65536 rows, contiguous and padded-head
inputs) and check token-major output torch.equal to the einsum. 65536 prefill
rows (the gate's upper bound) are added at every group count. Against the
previous gate, both 4-group cases fail on the layout assertion at 4096 prefill
rows. The 4-group gate-reject case moves from 4096 to 4095 rows. The new cases
add about 0.3 s; the file takes 41 s on B200 and B300.

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant