Skip to content

[Feat] dsa: Exact multicast top-k merge for DCP decode - #48588

Merged
hnyls2002 merged 11 commits into
mainfrom
lsyin/dsa-dcp-topk-merge
Nov 5, 2026
Merged

hnyls2002 merged 11 commits into
mainfrom
lsyin/dsa-dcp-topk-merge

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Original authors: @yhyang201, @Oasis-Git

Port of #48414

Under DCP, the Kimi-K3.1 Day-0 branch (#48414) shards the DSA indexer's index-K cache by token: each rank selects a local top-k and the ranks merge them into the global top-k. This PR ports the merge for decode rows: one kernel that exchanges candidates over NVLink multicast and selects the global top-k exactly. It comes with a test and has no caller yet.

Against the raw port, the context-split verify mode (split) is dropped; the merge is built with DcpTopKMerge.create(group, max_rows, topk, dcp_rank), which returns None where it cannot run and asserts that the group rank is the rank the candidates encode (the constructor and usable()'s buffer check go); it takes dcp_rank / out_slots / multicast_ptr throughout; its keys tie -0 with +0, as #48501's deterministic local top-k does, so a DCP row selects what one GPU would; and the test calls #48501's candidate top-k with dcp_size / dcp_rank / deterministic=True. Left for the sharded indexer PR: init_dcp_topk_merge and the rest of dsa_dcp_sharded.py. Left for target verify under DCP: the split mode.

Modifications

  • Merge kernel (dcp_topk_merge.cuh, dcp_topk_merge.py): one CTA per row. Each rank pushes its best 384 candidates to every rank with multimem stores, selects the k-th key among all candidates, and checks a certificate. Where a rank may hold more of the global top-k, the kernel reads that rank's full local top-k and selects again. It writes this rank's keys at or above the k-th key as widened KV slots, -1 after them. Each entry carries an 8-bit epoch tag, so no flag is needed; two parity buffers alternate.
  • DcpTopKMerge (dsa_dcp_sharded.py): create allocates the symmetric buffer and runs the rendezvous. It returns None unless there are 8 ranks (16 with the megakernel), top-k is 2048, the ranks share one NVLink domain, and multicast is available. Calls go on one stream, with the same rows in the same order on every rank.
  • PTX helpers (distributed/ptx.cuh): a relaxed 64-bit system-scope load and store, and a 64-bit multimem store.

Tests

  • test_dsa_dcp_topk_merge.py (8 GPUs): every rank's merged slots equal its share of the global top-k on random, tied, single-rank-owns-top-k (fallback), signed-zero and short rows. A CUDA graph replays three alternating inputs until the epoch tag wraps. The signed-zero case fails without the -0 / +0 tie.
  • Not covered: the test passes without deterministic=True, so it does not pin the local tie order the merge relies on; the 16-rank path has no test.

On 8 B300 GPUs at this head: 5 passed.


CI States

Latest PR Test (Base): ❌ Run #41995804555
Latest PR Test (Extra): ❌ Run #41995804533
Latest PR Test (AMD ROCm 10): ❌ Run #41995804562

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 repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_dsa_dcp_topk_merge.py

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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

cd test/ && python3 registered/kernels/ops/attention/test_dsa_dcp_topk_merge.py

@hnyls2002
hnyls2002 merged commit f353205 into main Nov 5, 2026
114 of 133 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/dsa-dcp-topk-merge branch November 5, 2026 08:54
wenkaidu added a commit to wenkaidu/sglang that referenced this pull request Nov 5, 2026
Resolve ptx.cuh conflict from sgl-project#48588 self-tagged uint64 helpers: keep the
CUDA APIs and add matching HIP overloads on the ROCm side.

Co-authored-by: Cursor <[email protected]>
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.

2 participants