Skip to content

[Refactor] Compare token layouts instead of group sizes when selecting communicator paths - #40869

Merged
ch-wan merged 1 commit into
mainfrom
cheng/refactor/communicator-transition-table
Sep 23, 2026
Merged

ch-wan merged 1 commit into
mainfrom
cheng/refactor/communicator-transition-table

Conversation

@ch-wan

@ch-wan ch-wan commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

This PR is part of a stack (oldest at bottom):

Motivation

LayerCommunicator picks the collective for each boundary (gather, scatter, all-reduce or nothing) from three tables keyed by the source and target ScatterMode. Whether a transition is the identity was decided by comparing process-group sizes. A group size is only the product of axis sizes, so two different token layouts can have the same size, and the tables hide the mapping from modes to functions inside chains of conditions.

Modifications

  • New python/sglang/srt/layers/boundary_layout.py: TokenAxis (ATTN_DP, ATTN_CP, ATTN_TP_SCATTER) and Layout, a frozen msgspec.Struct holding the set of token axes a rank's rows are sharded over.
  • communicator.py: scatter_mode_layouts(...) derives each ScatterMode's layout from the attention DP / CP / TP sizes. CommunicateContext.layouts is computed from the context's own size fields (its constructor is unchanged), and is_same_layout compares two modes' layouts. The base communicator's three get_fn tables use it for the identity check, and the mode-to-function mappings are written as explicit tables.
  • The DSA context-parallel communicator, whose SCATTERED mode shards tokens over CP, keeps its size-based checks (process_group_sizes / is_same_group_size stay).
  • New test/registered/unit/layers/test_communicator_layout.py (builds contexts from scatter_mode_layouts directly, without process-wide parallel state).

Accuracy Tests

Selection happens at construction time; the runtime path is unchanged. An exhaustive comparison against main covers 27 topologies (attention DP / CP / TP ∈ {1, 2, 4}) × SGLANG_USE_AG_AFTER_QLORA on / off and every mode pair of the three tables: 18,144 selections, 0 differences. test/registered/unit/layers + unit/models: every existing case keeps its status; the 6 new cases pass.

Speed Tests and Profiling

N/A: the selection runs once per layer at construction.

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ❌ Run #35924006362
Latest PR Test (Extra): 🚫 Run #35924005932
Latest PR Test (AMD ROCm 10): ❌ Run #35924006190

…tor paths

CommunicateContext now records, for each ScatterMode, the token axes
(attention DP, attention CP, attention-TP scatter) that a rank's rows are
sharded over. The base communicator's selection tables use these layouts to
decide when a transition is the identity. Group sizes are only products of
axis sizes, so different layouts can share a size. The mode-to-function
mappings are written as explicit tables.

Selections are unchanged for every valid topology. The DSA context-parallel
communicator, whose SCATTERED mode shards tokens over CP, keeps its
size-based checks.
@ch-wan
ch-wan force-pushed the cheng/refactor/communicator-transition-table branch from adad6c3 to 59b5eec Compare September 23, 2026 21:41
@ch-wan
ch-wan merged commit 7dd9640 into main Sep 23, 2026
22 of 31 checks passed
@ch-wan
ch-wan deleted the cheng/refactor/communicator-transition-table branch September 23, 2026 21:42
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