Repository navigation
[DCP] Drop two per-layer launches from the MLA target-verify path - #34240
Merged
kpham-sgl merged 4 commits intoAug 11, 2026
Merged
Conversation
Between the MLA attention and the DCP all-to-all, each MLA layer of the captured verify graph launched two kernels that do no useful work: - `lse * log2(e)` rebasing the cute-dsl kernel's natural-log LSE to base-2 (~1.8 us/layer). The cross-rank merge already takes an `is_lse_base_on_e` flag and both implementations (`dcp_lse_combine_triton` for a2a/fi_a2a, `correct_attn_out` for the allgather fallback) branch exp/log vs exp2/log2 on it, so declare the base instead of converting to it. - `torch.arange` building the dense verify query indptr (~0.9 us/layer). It is constant for a given num_draft_tokens, so materialize it once at init. On Kimi-K3 @128k, DCP8+DSpark, B300 x8 that is ~2.7 us per MLA layer, 12 MLA layers per verify step, i.e. ~32 us/step off the critical path. No numerics change beyond dropping one rounding step from the LSE. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
kpham-sgl
requested review from
Fridge003,
HaiShaw,
Qiaolin-Yu,
ch-wan,
fzyzcjy,
hebiao064,
ispobock and
merrymercy
as code owners
August 10, 2026 07:59
kpham-sgl
commented
Aug 10, 2026
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…se-and-arange # Conflicts: # test/registered/dcp/test_dcp_layout_unit.py
Pure refactor, no behavior change: the frozenset had a single use, and a bare set literal in an `in` comparison is constant-folded by CPython, so it is still built once rather than per call. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Collaborator
Author
|
/rerun-test test/registered/dcp/* |
Contributor
|
Results for 🚀 🚀 🚀 |
Collaborator
Author
|
/rerun-test test/registered/kernels/test_dcp_lse_combine.py |
Contributor
|
Results for 🚀 |
Collaborator
Author
|
Should be safe to merge. CPU tests are currently broken |
vstone-w
pushed a commit
to ClownBin/sglang
that referenced
this pull request
Aug 12, 2026
…l-project#34240) Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
qtris123
added a commit
to qtris123/sglang
that referenced
this pull request
Aug 12, 2026
…the base at the merge site Obsoletes 2e5e123 ("[DCP] Fix the decode LSE base for trtllm-gen; resolve it per backend"), which is superseded by the merge-site LSE convention that landed upstream in sgl-project#34240. 2e5e123 fixed a real bug: the decode LSE was rebased by log2(e) unconditionally, which is right for cute-dsl (natural log) but corrupts trtllm-gen, which already emits base-2. It fixed it inside the backend, resolving the base from a registry keyed on the flashinfer kernel string ("trtllm-gen" / "cute-dsl"). sgl-project#34240 fixes the same problem from the other end: a backend now returns its native LSE and the merge site decides, keyed on the sglang attention backend name instead: def is_mla_dcp_lse_base_on_e(attention_backend): return attention_backend in {"flashmla", "cutedsl_mla"} Keeping both would leave two registries for one correction, and the rebase in _run_decode_kernel would re-enter the very double-rebase 2e5e123 removed as soon as a cute-dsl call reached the base hook with return_lse=True. So drop the backend-side mechanism; the merge-site convention already gives the right answer across the family: - trtllm_mla -> merge assumes base-2; trtllm-gen emits base-2. - cutedsl_mla -> merge assumes base-e; cute-dsl emits natural log, and sgl-project#34240 removed its own rebase. - tokenspeed_mla -> merge assumes base-2; unaffected, it never passed a flashinfer backend string so it never rebased. _run_decode_kernel keeps only the return_lse passthrough that the DCP decode path needs and otherwise returns the kernel result unchanged, as upstream does.
4 of 5 tasks
This was referenced Aug 12, 2026
saturn-acc
pushed a commit
to saturn-acc/sglang
that referenced
this pull request
Aug 16, 2026
…l-project#34240) Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
kpham-sgl
pushed a commit
to qtris123/sglang
that referenced
this pull request
Aug 26, 2026
…the base at the merge site Obsoletes 2e5e123 ("[DCP] Fix the decode LSE base for trtllm-gen; resolve it per backend"), which is superseded by the merge-site LSE convention that landed upstream in sgl-project#34240. 2e5e123 fixed a real bug: the decode LSE was rebased by log2(e) unconditionally, which is right for cute-dsl (natural log) but corrupts trtllm-gen, which already emits base-2. It fixed it inside the backend, resolving the base from a registry keyed on the flashinfer kernel string ("trtllm-gen" / "cute-dsl"). sgl-project#34240 fixes the same problem from the other end: a backend now returns its native LSE and the merge site decides, keyed on the sglang attention backend name instead: def is_mla_dcp_lse_base_on_e(attention_backend): return attention_backend in {"flashmla", "cutedsl_mla"} Keeping both would leave two registries for one correction, and the rebase in _run_decode_kernel would re-enter the very double-rebase 2e5e123 removed as soon as a cute-dsl call reached the base hook with return_lse=True. So drop the backend-side mechanism; the merge-site convention already gives the right answer across the family: - trtllm_mla -> merge assumes base-2; trtllm-gen emits base-2. - cutedsl_mla -> merge assumes base-e; cute-dsl emits natural log, and sgl-project#34240 removed its own rebase. - tokenspeed_mla -> merge assumes base-2; unaffected, it never passed a flashinfer backend string so it never rebased. _run_decode_kernel keeps only the return_lse passthrough that the DCP decode path needs and otherwise returns the kernel result unchanged, as upstream does.
qtris123
added a commit
to qtris123/sglang
that referenced
this pull request
Aug 31, 2026
…the base at the merge site Obsoletes 2e5e123 ("[DCP] Fix the decode LSE base for trtllm-gen; resolve it per backend"), which is superseded by the merge-site LSE convention that landed upstream in sgl-project#34240. 2e5e123 fixed a real bug: the decode LSE was rebased by log2(e) unconditionally, which is right for cute-dsl (natural log) but corrupts trtllm-gen, which already emits base-2. It fixed it inside the backend, resolving the base from a registry keyed on the flashinfer kernel string ("trtllm-gen" / "cute-dsl"). native LSE and the merge site decides, keyed on the sglang attention backend name instead: def is_mla_dcp_lse_base_on_e(attention_backend): return attention_backend in {"flashmla", "cutedsl_mla"} Keeping both would leave two registries for one correction, and the rebase in _run_decode_kernel would re-enter the very double-rebase 2e5e123 removed as soon as a cute-dsl call reached the base hook with return_lse=True. So drop the backend-side mechanism; the merge-site convention already gives the right answer across the family: - trtllm_mla -> merge assumes base-2; trtllm-gen emits base-2. - cutedsl_mla -> merge assumes base-e; cute-dsl emits natural log, and sgl-project#34240 removed its own rebase. - tokenspeed_mla -> merge assumes base-2; unaffected, it never passed a flashinfer backend string so it never rebased. _run_decode_kernel keeps only the return_lse passthrough that the DCP decode path needs and otherwise returns the kernel result unchanged, as upstream does.
Atituiset
pushed a commit
to Atituiset/sglang
that referenced
this pull request
Sep 10, 2026
…l-project#34240) Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
19 of 39 tasks
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
Profiling Kimi-K3 @ 128k on 8xB300 (
--dcp-size 8+ DSpark,cutedsl_mla) shows that in every MLA layer of the captured target-verify graph, the window between the attention epilogue and the DCP all-to-all is mostly glue. Two of those kernels do no useful work at all:vectorized_elementwise<MulFunctor<float>>, grid[1]lse * log2(e)— rebase the cute-dsl kernel's natural-log LSE to base-2elementwise_kernel_with_index<arange>, grid[1]dense_q_indptrfor the zero-KV fixupBoth are pure launch overhead: the multiply touches 768 fp32 values, the arange produces
bs + 1int32 values. With 12 MLA layers per verify step that is ~32 µs/step serialized on the main stream, ahead of the a2a.Modifications
LSE base is declared, not converted.
dcp_a2a_lse_reduce/cp_lse_ag_out_rs_mlaalready takeis_lse_base_on_e, and both merge implementations branch on it symmetrically (dcp_lse_combine_tritonpicksexp/logvsexp2/log2,correct_attn_outlikewise). Socutedsl_mlais added to a new_MLA_DCP_BASE_E_LSE_BACKENDSset inforward_mla.pyandCuteDslMLABackend._run_decode_kernelreturns the kernel's LSE untouched.HybridAttnBackend._select_backendroutes a forward mode to the same backend that_set_current_attention_backendnames, so the string reliably identifies the backend object that produced the LSE.Dense verify indptr is materialized once.
arange(0, (bs + 1) * draft_token_num, draft_token_num)is constant for a givendraft_token_num, soTRTLLMMLABackend.__init__builds it from the existingq_indptr_decodebuffer and_dense_q_indptr(bs, draft_token_num)slices it. The general expression is kept for the case where a batch'sdraft_token_numdiffers from the server-args value (it does not on the EAGLE / DFLASH / DSpark verify paths, wherespeculative_num_draft_tokensis validated to equal the verify window).Other MLA DCP backends are unaffected:
tokenspeed_mla,trtllm_mlaand FlashInfer-MLA still report base-2 and still take the same merge path.Accuracy Tests
Not run. The runs below pin acceptance with
SGLANG_SIMULATE_ACC_LEN=5, so they measure kernel structure and speed, not output quality — I have not validated accuracy for this change.The LSE change is mathematically an identity (softmax output is base-invariant; only the LSE value changes), and it removes a rounding step rather than adding one, since the
log2(e)multiply no longer touches the fp32 LSE. The indptr change produces bit-identical indices, pinned by the new unit test. Happy to run GSM8K on the 8xB300 box before merge if a reviewer wants it.Speed Tests and Profiling
Before
After

Checklist
Tests added:
test/registered/kernels/test_dcp_lse_combine.py::test_natural_log_lse_backends— pins which backends declare base-e, including the negative branches.test/registered/dcp/test_dcp_layout_unit.py::test_dense_q_indptr_matches_the_arange_it_replaces— pins both the precomputed buffer and the general path to the arange formula.Neither was executed locally (no torch in this environment); both are CPU-only and registered in CI.
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ❌ Run #31374613530
Latest PR Test (Extra): ❌ Run #31374613569