Skip to content

[Perf] kimi-k3.1: Faster DCP decode reduce (push-combine, V pre-projection, direct exchange) - #48740

Merged
kpham-sgl merged 7 commits into
sgl-project:mainfrom
kpham-sgl:kpham/k31-dcp-reduce-perf
Nov 7, 2026
Merged

kpham-sgl merged 7 commits into
sgl-project:mainfrom
kpham-sgl:kpham/k31-dcp-reduce-perf

Conversation

@kpham-sgl

@kpham-sgl kpham-sgl commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Original authors: @yhyang201, @BBuf

Stacks on #48721. Until #48721 merges, this PR's diff also contains it; the commits from "Raw port of the DSA DCP decode reduce" on are this PR.

Port of #48414

Under DCP, Kimi-K3.1 decode merges the attention partials of every rank by LSE. #48721 ports that through the existing pack + all-to-all + Triton combine. This PR ports the faster reduce from #48414:

  • V pre-projection: W_UV is applied to the partials before the reduce (a head's linear V projection commutes with its LSE-weighted sum), so ranks exchange 128-wide instead of 512-wide partials. Used for DSA layers with bf16 w_vc at 512 rows or more, or whenever the push-combine plane takes the batch.
  • Push-combine: one kernel pushes each peer's heads into that peer's CustomAllReduceV2 push slot over NVLink and combines this rank's heads by LSE weight, replacing pack + all-to-all + combine. It falls back to the all-to-all reduce when the plane is not set up or too small.
  • Direct exchange: under fi_a2a, the 8-rank, 96-head partials are stored straight into peer buffers. It is gated to B300 and 512-1024 rows, and falls back to FlashInfer's exchange otherwise.
  • Candidate prefix gather: the indexer's candidate all-gather sends only each row's valid prefix over multimem. [Feat] kimi-k3.1: DSA decode context parallelism runtime #48721 dropped it.
  • Strided partials: K3.1's DSA partials skip .contiguous(), since the a2a pack reads any strides.
  • All-gather reorder: large byte-packed DCP KV all-gathers are reordered with word-sized loads after the collective.

Against the raw port (first commit):

  • Rename: SGLANG_DCP_PUSH_COMBINE becomes SGLANG_ENABLE_DCP_PUSH_COMBINE, following the env-var naming rules.
  • Max-rows default: SGLANG_DCP_PUSH_COMBINE_MAX_ROWS defaults to 1024. The source's GB300-specific default helper is not on main.
  • No getattr: dcp_v_preproject and _dcp_v_weights are declared on the MLA mixin and read directly.
  • Shared tail: the absorbed path's gate + o_proj tail goes through one helper, _finish_absorb_output, which both the V-preprojected exit and the regular exit use.
  • Kernel registration: dcp_push_combine is registered in the attention kernel group.
  • API change for the source's callers: the env var rename only.

The tests come from the history #48414 was squashed from, because #48414 dropped its unit tests. The token-packing case is removed.

Left for later ports:

  • Absorbing W_UK straight into the attention q buffer under the indexer. It builds on the source's alt-stream absorb (dsa_decode_absorb_under_indexer, _flashmla_kv_q), which is not on main.
  • Native-head FlashMLA.
  • The precomputed windowed FlashMLA schedule for DCP decode (source Use HTTP link in 3rdparty module #42's schedule part, through _maybe_precompute_flashmla_sched_meta); [Feat] kimi-k3.1: DSA decode context parallelism runtime #48721 lets FlashMLA schedule DCP decode itself.
  • The trtllm / Prims-TS DCP paths.
  • Speculative and PD paths.
  • FlashMLA prefill token packing.

Modifications

  • kernels/jit/csrc/dsa/dcp_push_combine.cuh, kernels/ops/attention/dcp_push_combine.py: the push + LSE combine kernel and its op.
  • kernels/ops/attention/dcp_kernels.py: DcpDirectAllToAll and its peer-store pack kernel; _gather_candidate_prefix_kernel.
  • layers/dcp/comm.py, layers/dcp/__init__.py: init_dcp_push_combine / dcp_push_combine_fits / dcp_push_combine_reduce; the direct exchange in the fi_a2a reduce; the word-sized reorder in _all_gather_dcp_kv_cache.
  • model_executor/runner/base_runner.py: set up the push plane next to the fi_a2a workspace when q projection is replicated.
  • forward_mla.py: V pre-projection and the push-combine reduce in the DCP decode merge.
  • kimi_k3.py: K3.1 MLA layers opt into the V pre-projection; the gathered w_vc is refreshed on weight reload.
  • dsa_dcp_sharded.py: the prefix candidate gather.
  • environ.py: SGLANG_ENABLE_DCP_PUSH_COMBINE, SGLANG_DCP_PUSH_COMBINE_MAX_ROWS.

Tests

  • New registered multi-GPU tests:
    • test_dcp_push_combine.py (8 GPUs): the push-combine reduce against gathering every rank's partials and running the Triton combine.
    • test_dcp_collectives.py (4 / 8 GPUs): the direct exchange bit for bit through graph replay; its dispatch and fallback on B300; the request-ordered byte gather; the candidate merge's scratch reuse across graph replays.
  • Not run. Only static checks so far: pre-commit and ruff on the touched files. These tests and a Kimi-K3.1 TP8 / DCP8 run are owed.

CI States

Latest PR Test (Base): ❌ Run #42299558253
Latest PR Test (Extra): ❌ Run #42299557805
Latest PR Test (AMD ROCm 10): ❌ Run #42299558126

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

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

kpham-sgl and others added 4 commits November 6, 2026 01:28
- Rename SGLANG_DCP_PUSH_COMBINE to SGLANG_ENABLE_DCP_PUSH_COMBINE and
  default SGLANG_DCP_PUSH_COMBINE_MAX_ROWS to 1024; the GB300-specific
  default helper is not on main.
- Declare dcp_v_preproject and _dcp_v_weights on the MLA mixin and read
  them directly instead of through getattr.
- Route the absorbed path's gate + o_proj tail through
  _finish_absorb_output, so the V-preprojected exit and the regular one
  share it.
…8414's history

sgl-project#48414 dropped its unit tests (sgl-project#48464); these two come from the history
it was squashed from: the push-combine reduce against the Triton combine,
and the direct exchange, byte gather and candidate merge collectives.

Co-authored-by: Xiaoyu Zhang <[email protected]>
…s test

FlashMLA prefill token packing is not part of this port.
@kpham-sgl
kpham-sgl force-pushed the kpham/k31-dcp-reduce-perf branch from cc716be to 1452226 Compare November 6, 2026 09:29

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] A few things to fix before this can go in.

local,
lengths,
table,
all_gather=partial(group.all_gather, dim=0),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] The first reference call raises TypeError: dcp_global_topk() got an unexpected keyword argument 'all_gather', so none of the replay comparisons run. Could we use the current API and temporarily clear _CANDIDATE_ALL_GATHER for the eager reference?

max_push_size=MAX_ROWS * (H // world_size) * pc.SLOT_BYTES_PER_ROW,
)
assert not comm.disabled
pc.register_comm(comm.obj)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] After _setup() returns, only the non-owning comm.obj is retained; cyclic GC can free the push buffers and counters while later tests still launch through their pointers. Could we retain the CustomAllReduceV2 owner in the fixture and register its cleanup?

- test_dcp_collectives: dcp_global_topk takes no all_gather argument; run
  the eager reference with _CANDIDATE_ALL_GATHER cleared instead.
- test_dcp_push_combine: keep the CustomAllReduceV2 that owns the push
  buffers alive for the whole module and close it at exit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@BBuf

BBuf commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

[BBuf Review Agent] Could you add before/after numbers with hardware and workload?

The decode reduce takes the push-combine path under both the a2a and the
fi_a2a DCP backends, but the plane was allocated only inside the fi_a2a
workspace hook, so under a2a it was never set up and the reduce always
fell back to the all-to-all. Give it its own hook, gated on DCP, an a2a
or fi_a2a backend, and replicated q projection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_dcp_push_combine.py test_dcp_collectives.py test_dsa_dcp_topk_merge.py test_dsa_dcp_attention.py test_dcp_lse_combine.py test_kimi_k3_b300.py

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

🚀 8-gpu-h200 (3 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/attention/test_dcp_push_combine.py  # extra-b
cd test/ && python3 registered/kernels/ops/communication/test_dcp_collectives.py  # extra-b
cd test/ && python3 registered/kernels/ops/attention/test_dsa_dcp_topk_merge.py  # extra-b

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

cd test/ && python3 registered/kernels/ops/communication/test_dcp_collectives.py  # base-b-kernel-unit
cd test/ && python3 registered/dcp/test_dsa_dcp_attention.py  # base-b

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

cd test/ && python3 registered/kernels/ops/attention/test_dcp_lse_combine.py  # base-b

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

cd test/ && python3 registered/e2e/models/test_kimi_k3_b300.py  # extra-b

@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

Accuracy on 2 x GB300 (4 GPUs each), Kimi-K3.1, PR head a5c4ebad7e against its parent on main 27bc1a0615. Both arms ran at the same time on separate node pairs.

Arm GSM8K (200) AIME26 pass@1 (avg of 8) AIME26 majority@8 / pass@8 Truncated Mean completion tokens
main 27bc1a0615 99.0% 98.75% (SEM 0.61%) 100% / 100% 1 / 240 4951
this PR a5c4ebad7e 99.0% 100.0% 100% / 100% 0 / 240 4205

Both arms have a 0% error rate. The AIME26 gap is 3 of 240 samples on main, one of them cut off at the 100K token cap, which is within noise.

Setup:

  • Server: the cookbook GB300 2x4 Balanced recipe: --tp-size 8 --dcp-size 8 --dcp-comm-backend fi_a2a --ep-size 2 --mem-fraction-static 0.85 --max-running-requests 64, fp8 KV, SGLANG_ENABLE_DCP_PUSH_COMBINE at its default (on).
  • Image: lmsysorg/sglang nightly cu13 2026-11-05, with sgl-flash-mla==1.0.2 as main pins, and the Rust extensions rebuilt from each tree.
  • GSM8K: sgl-eval 0.1.3, 200 examples, temperature 1.0, top_p 0.95, max_tokens 16384.
  • AIME26: sgl-eval 0.1.3, --load-preset-from-model-id moonshotai/Kimi-K3 (thinking on, reasoning effort max, temperature 1.0, top_p 0.95), 8 repeats, max_tokens 100000.

What this run does and does not cover:

  • Push-combine + V pre-projection: the push plane came up on both trays (no "CustomAllReduceV2 unavailable" warning). Setup logs nothing on success, so this run does not prove the kernel ran at decode; a decode trace would.
  • Direct exchange: not exercised. GB300 reports NVIDIA GB300, so the B300 name gate keeps it off.
  • KV all-gather reorder: not exercised. It needs gathered KV of at least 64 MiB; the eval prompts average about 226 tokens.
  • No performance numbers yet.

@kpham-sgl
kpham-sgl merged commit 00c3b14 into sgl-project:main Nov 7, 2026
107 of 127 checks passed
@metamergebot

Copy link
Copy Markdown
Collaborator

Heads-up: since this PR merged, test/registered/unit/kernel_plugins/nvidia/test_megakernel_runtime.py fails on main (base-a CPU suite), so every PR's base-a-test-cpu shard that runs it goes red:

ERROR: test_preparation_failures_propagate_in_order (failed_stage='model')
  File "test/registered/unit/kernel_plugins/nvidia/test_megakernel_runtime.py", line 123, in _warmup
    base_runner.BaseRunner._warmup(runner)
  File "python/sglang/srt/model_executor/runner/base_runner.py", line 266, in _warmup
    self._pre_initialize_dcp_push_combine()
AttributeError: 'types.SimpleNamespace' object has no attribute '_pre_initialize_dcp_push_combine'

The test drives BaseRunner._warmup with a SimpleNamespace runner, which has no _pre_initialize_dcp_push_combine. Example run: https://github.com/sgl-project/sglang/actions/runs/42341406709 (job base-a-test-cpu (8)). @kpham-sgl, could you take a look?

EricKing626 added a commit to EricKing626/sglang that referenced this pull request Nov 9, 2026
Two conflicts, both against the kimi-k3.1 DCP work that landed on 11-06.

sgl-project#48739 widened the absorbed-MLA gather to skip target-verify, where a
sharded index-K now keeps its per-rank partials. The gathered-prefill
override is a different route and the two cannot both be on: the route
is planned only when index-K is replicated. Keep both, ours first, and
keep the dcp_gathered local the rest of the method reads.

sgl-project#48740 added dcp_push_combine_fits and dcp_push_combine_reduce to the
layers.dcp import in forward_mla, next to is_dsa_dcp_gathered_prefill.
Take the union.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants