Skip to content

[Feat] kimi-k3.1: Let shared-expert TP span interleave prefill CP - #48713

Merged
Fridge003 merged 2 commits into
mainfrom
k31-pcp/shared-experts-tp
Nov 6, 2026
Merged

Fridge003 merged 2 commits into
mainfrom
k31-pcp/shared-experts-tp

Conversation

@Fridge003

@Fridge003 Fridge003 commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Original authors: @Fridge003

Port of #48414

Shared-expert TP across interleave prefill CP (radixark/sglang-k31#147), split from #48504. Independent of the prefill-CP stack.

Split of #48504. Stack: #48709 (core) → #48710 (MegaMoE / BCG / DFlash) → #48711 (fused kernels) → #48712 (PP × PCP BCG). Independent: #48713 (shared-expert TP across PCP), #48714 (trtllm DSA), #48715 (Linker PCP L3).

Modifications

  • --shared-experts-tp-size may divide attention TP × CP; a subgroup still never crosses attention DP replicas or PP stages. A width beyond attention TP requires --enable-prefill-cp --cp-strategy interleave, where the FFN sees equal padded token-row shards: the shared experts gather rows over CP as well as attention TP and reduce-scatter back.
  • initialize_model_parallel: rank layout [PP, attention DP, CP, attention TP], contiguous shared-expert groups.

Tests

  • test_parallel_state.py: shared-expert groups span PCP without crossing DP or PP.
  • test_kimi_mlp_parallel_groups.py: PCP8 weight shards and padded local rows against a dense reference.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ❌ Run #42190530791
Latest PR Test (Extra): ❌ Run #42190530760
Latest PR Test (AMD ROCm 10): ❌ Run #42190530697

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.

f"of attention TP size ({attn_tp_size})."
f"of attention replica size ({replica_size}, attention TP x CP)."
)
if attn_tp_size % size != 0 and not (

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Remove line235-240. Shared expert TP is not related to cp strategy

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed in adbc89d. Only the divisor check against attention TP x CP is left.

else:
allocation.assert_not_called()

def test_pcp8_weight_shards_and_padded_local_rows(self):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Remove this unit test

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed in adbc89d.

Fridge003 and others added 2 commits November 6, 2026 00:48
Port of radixark/sglang-k31#147, split out of #48504.

With interleave prefill CP the FFN sees equal padded token-row shards, so
the shared experts can gather rows over CP as well as attention TP and
reduce-scatter back. --shared-experts-tp-size may now divide attention TP x
CP (it still never crosses attention DP replicas or PP stages); a width
beyond attention TP requires --enable-prefill-cp --cp-strategy interleave.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shared-expert TP is independent of the CP strategy, so a width beyond
attention TP no longer requires --cp-strategy interleave; the divisor
check against attention TP x CP stays. The PCP8 MLP-shard unit test is
dropped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Fridge003
Fridge003 force-pushed the k31-pcp/shared-experts-tp branch from 2c7f916 to adbc89d Compare November 6, 2026 08:50
@Fridge003

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/unit/distributed/test_parallel_state.py

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/distributed/test_parallel_state.py  # base-a

@Fridge003
Fridge003 merged commit 3c0e6e9 into main Nov 6, 2026
114 of 132 checks passed
@Fridge003
Fridge003 deleted the k31-pcp/shared-experts-tp branch November 6, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant