Skip to content

[FlyDSL] dist: public SP APIs: PCP graph_capture, head exchange, all_to_all, MegaMoE setup errors - #7346

Open
whx-sjtu wants to merge 3 commits into
mainfrom
hexwang/sp-public-comm-api
Open

whx-sjtu wants to merge 3 commits into
mainfrom
hexwang/sp-public-comm-api

Conversation

@whx-sjtu

@whx-sjtu whx-sjtu commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Small aiter.dist and MegaMoE-TP changes so sequence-parallel callers (ROCm/ATOM#2364) stop patching around aiter and reading its privates:

  1. parallel_state.graph_capture() also enters the PCP group, as it already does DCP.
  2. CustomAllreduce gets a public registered-input view and a public four-rank head exchange (should_head_exchange / head_exchange) over the existing sp_head_exchange op.
  3. CudaCommunicator.reduce_scatter(dim=0) writes straight into its output instead of through a temporary and a copy.
  4. PyNcclCommunicator.all_to_all / CudaCommunicator.all_to_all: an equal-split dim-0 all-to-all on the current stream.
  5. MegaMoE-TP: MegaMoeSetupError for setup failures raised alike on every rank, and MegaMoeTP.prepare_all().

Motivation

  • graph_capture() enters TP/PP/DP/EP/DCP and the custom groups but not PCP, so a PCP group's custom all-reduce is never armed and its captured collectives take the eager path. ATOM worked around this by wrapping graph_capture() and reading ca_comm._IS_CAPTURING. Plain PCP with custom all-reduce has the same gap.
  • ATOM's Ulysses SP drove sp_head_exchange itself, from ca._ptr, ca._pool["input"] and pool._buffer, and had its own copy of the capture-time registration check.
  • For dim 0, the pynccl reduce-scatter reduces into a temporary and copies it out, although the scattered axis is already the output's layout.
  • ATOM hand-wrote an ncclSend / ncclRecv loop against pynccl.nccl, pynccl.comm and buffer_type for its all-to-all.
  • ATOM decided whether a MegaMoE setup failure allows a collective fallback by prefix-matching the RuntimeError text, and called launch_config(rows) for every row count to enumerate the small-engine variants before capture. Rewording one message here would have turned its fallback into a raise on every rank.

The ATOM reviewer asked for these to land in aiter and for #2364 to use them. ATOM #2364 is merged and uses all of them.

Changes

  • parallel_state.graph_capture: enter _DCP and _PCP when their world size is above 1. The DCP entry also moves out of the PP/DP/EP loop, where it was entered once per iteration (ExitStack made that harmless).
  • CustomAllreduce.registered_input_view(shape, dtype): a view of the registered input pool, or None when the communicator is disabled, the size is not a whole number of 16-byte packs, the pool is too small, or the pool has no tensor (VMM). A producer writes there and calls the collective with registered=True to skip staging.
  • CustomAllreduce.should_head_exchange(inp) / head_exchange(inp, *, registered=False): [S, H] to [S/4, 4H] on four ranks, pre-gfx1250 kernel. Under capture() a captured input is bound in place through _capture_registered, the same as the other collectives. head_exchange raises RuntimeError on a disabled communicator or on gfx1250, where the op would cast the wrong handle.
  • CudaCommunicator.reduce_scatter: when dim == 0 and output_ is contiguous, call pynccl_comm.reduce_scatter(output_, input_tensor) directly.
  • PyNcclCommunicator.all_to_all(output, input): one grouped ncclSend / ncclRecv per peer over same-shape contiguous tensors, dim 0 divisible by the world size. CudaCommunicator.all_to_all uses it, else all_to_all_single.
  • MegaMoeSetupError(RuntimeError) in aiter.ops.communication, re-exported by aiter.ops.flydsl.mega_moe_tp. Raised on every rank for: MORI failing to import on any rank (SdmaComm now gathers the import result before raising), MORI SDMA setup, the symmetric arena's IPC mapping, and warmup timeouts. The last three already raised RuntimeError on every rank and keep their messages, so except RuntimeError still catches them.
  • MegaMoeTP.prepare_all(tail=False, tail_bf16=False, warmup=True): prepare() one token count per launch variant of 1 .. max_local_tokens, so no batch in range compiles while serving or inside graph capture.
  • CI (.github/scripts/aiter_test.sh): test_sp_head_exchange.py runs through pytest, and test_parallel_groups.py runs again with --tp 2 --pcp 2 --dp 1 after its default layout, which has no PCP group.

Existing calls keep their behaviour, except that a MORI import failure now raises on every rank (see Behavior and intent). The reduce-scatter result is the same values in the same layout.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

On 4x MI355X (gfx950), at d1df819 (this head, on main f705d6b):

  • pytest op_tests/multigpu_tests/test_sp_head_exchange.py: 4 passed.
    • The head-exchange case checks the three entry paths against a reference, exactly: a producer writing registered_input_view then head_exchange(registered=True); a staged input; and a captured input bound in place, rewritten after capture and replayed. It also checks that head_exchange raises on a disabled communicator.
    • The all-to-all case checks all_to_all exactly, eagerly and as a captured graph replayed on three fresh inputs.
  • python op_tests/multigpu_tests/test_parallel_groups.py and ... --tp 2 --pcp 2 --dp 1: ALL PASS, including the new assert that graph_capture() arms the PCP group's custom all-reduce. The same test file run against main without this change fails it: AssertionError: Rank 0: graph_capture() missed PCP.
  • test_mega_moe_tp.py --models m3 --modes ag_rs -t 256 -r random --seeds 0: 15/15 passed. This file stays skipped in CI, as on main (Skip MegaMoE TP multigpu test #6933).
  • Positive controls: with head_exchange temporarily binding the registered pool instead of the captured input, the capture case fails (512/512 elements off by one), while the previous version of the case still passed. With _is_gfx1250 forced on an enabled communicator, head_exchange raises on all four ranks.
  • ATOM [Feature]: AITER MLA ps mode support for q/kv head ratio of 8, mtp=4 for MI355 #2364 (MiniMax-M3 MXFP4, SP4) runs end to end on these APIs, with its own collectives, admission checks and error parsing removed. With MORI hidden on every rank, all four ranks raised MegaMoeSetupError and fell back to the native MoE alike.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None in aiter. SdmaComm() without MORI now raises MegaMoeSetupError on every rank, instead of ImportError on the ranks that lack it. Nothing in aiter catches the ImportError.

PR Self-Review

Reviewed revision

d1df819

Behavior and intent

  • graph_capture() now arms PCP's custom all-reduce, so PCP collectives inside a captured graph take the custom path (registered or staged), as the TP/DCP ones already do.
  • The dim-0 reduce-scatter result is unchanged, minus a temporary and a copy.
  • MegaMoE setup failures keep their messages and stay RuntimeErrors. A MORI import failure on some ranks now raises MegaMoeSetupError on all of them, where before only the failing ranks raised ImportError and the rest went on into the arena's collectives.
  • The rest is new API.

Validation and unverified scope

See Testing. Not verified on hardware: the gfx1250 and symm_mem transports. should_head_exchange refuses gfx1250 and head_exchange raises there (checked by forcing the flag on gfx950), and registered_input_view returns None when the pool has no tensor. Not run on MI300X.

PR-specific question

The only CI change is in .github/scripts/aiter_test.sh, which the existing Aiter Test jobs already run from the PR checkout inside the test container. No workflow, trigger, permission, secret or token changes. The new lines add test_sp_head_exchange.py to the pytest list and run test_parallel_groups.py a second time with fixed arguments. The file path comes from the same repository file list as every other case and reaches bash -c as a positional argument, not as script text, and no PR title, body, branch name or other PR text is read. So fork PR code reaches nothing it could not reach before: it already runs in these pull_request jobs, and the Tests step passes only MULTIGPU=TRUE into the container.

Changed op tests

  • op_tests/multigpu_tests/test_sp_head_exchange.py: covers the communicator wrappers: the head exchange's three entry paths and its guard, and all_to_all eager and replayed. Before this PR both new cases fail with AttributeError. The existing cases drive the raw op with their own buffers, so they cannot catch a wrong pool pointer, stage flag or capture binding in the wrapper, nor a wrong peer offset in the all-to-all. The file has no __main__, so CI now runs it through pytest.
  • op_tests/multigpu_tests/test_parallel_groups.py: one assert that graph_capture() arms PCP's custom all-reduce; on main it fails with graph_capture() missed PCP. Nothing else covers which groups graph_capture() enters. CI ran this file only at its default layout, which has no PCP group, so it now also runs with --tp 2 --pcp 2 --dp 1.

🤖 Generated with Claude Code

@whx-sjtu
whx-sjtu requested a review from a team November 2, 2026 17:53
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7346 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@aiter-bot

aiter-bot commented Nov 2, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision d1df81939d02 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

- `graph_capture()` now arms PCP's custom all-reduce, so PCP collectives inside a captured graph take the custom path (registered or staged), as the TP/DCP ones already do.
- The dim-0 reduce-scatter result is unchanged, minus a temporary and a copy.
- MegaMoE setup failures keep their messages and stay `RuntimeError`s. A MORI import failure on some ranks now raises `MegaMoeSetupError` on all of them, where before only the failing ranks raised `ImportError` and the rest went on into the arena's collectives.
- The rest is new API.

Validation and unverified scope

See Testing. Not verified on hardware: the gfx1250 and symm_mem transports. `should_head_exchange` refuses gfx1250 and `head_exchange` raises there (checked by forcing the flag on gfx950), and `registered_input_view` returns `None` when the pool has no tensor. Not run on MI300X.

PR-specific question

The only CI change is in `.github/scripts/aiter_test.sh`, which the existing `Aiter Test` jobs already run from the PR checkout inside the test container. No workflow, trigger, permission, secret or token changes. The new lines add `test_sp_head_exchange.py` to the pytest list and run `test_parallel_groups.py` a second time with fixed arguments. The file path comes from the same repository file list as every other case and reaches `bash -c` as a positional argument, not as script text, and no PR title, body, branch name or other PR text is read. So fork PR code reaches nothing it could not reach before: it already runs in these `pull_request` jobs, and the Tests step passes only `MULTIGPU=TRUE` into the container.

Changed op tests

- `op_tests/multigpu_tests/test_sp_head_exchange.py`: covers the communicator wrappers: the head exchange's three entry paths and its guard, and `all_to_all` eager and replayed. Before this PR both new cases fail with `AttributeError`. The existing cases drive the raw op with their own buffers, so they cannot catch a wrong pool pointer, stage flag or capture binding in the wrapper, nor a wrong peer offset in the all-to-all. The file has no `__main__`, so CI now runs it through pytest.
- `op_tests/multigpu_tests/test_parallel_groups.py`: one assert that `graph_capture()` arms PCP's custom all-reduce; on main it fails with `graph_capture() missed PCP`. Nothing else covers which groups `graph_capture()` enters. CI ran this file only at its default layout, which has no PCP group, so it now also runs with `--tp 2 --pcp 2 --dp 1`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • FAIL — Aiter Test Gate: failed
  • Required CI failed; fix it before requesting human review.

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@whx-sjtu whx-sjtu added the ci:multi-gpu Trigger multi-GPU op tests on PR label Nov 2, 2026
whx-sjtu added a commit to ROCm/ATOM that referenced this pull request Nov 2, 2026
- Drop the FP4 pre-gather wire and its fused_moe dispatch predictor; the
  PCP/SP split pass packs routed_rows_wire again, so plain PCP matches main.
- Dispatch SP MegaMoE from FusedMoE.forward_impl behind the existing
  moe_forward op. Remove the comm-fused op, supports(), the
  sp_mega_moe_enabled config field and its compile-hash factor; M3 marks its
  MoE with allow_sp_mega_moe instead of enable_comm_fused.
- Import fused_qk_rmsnorm_per_token_quant directly and raise on shapes the
  FP32-norm quant path cannot take.
- Use ROCm/aiter#7346: graph_capture() enters PCP, CustomAllreduce exposes
  registered_input_view/head_exchange, and dim-0 reduce_scatter writes in
  place. Delete sp_graph_capture, sp_registered_buffer, the private
  CustomAllreduce reads and reduce_scatter_tokens.
- One custom all-gather check (token_transport.custom_gather_ok) shared by
  indexer_cp and the V4.1 mono runner.
- Delete sp_pad_len, the SP group aliases and kv_head_shards; use the PCP
  helpers and attn_head_shard_size().
- Graphs and eager read the SP token shard as a view of
  forward_vars["input_ids"]; refuse max_num_batched_tokens not divisible
  by the SP size.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot changed the title dist: arm PCP in graph_capture, public CustomAllreduce head exchange, in-place dim-0 reduce_scatter [FlyDSL] dist: arm PCP in graph_capture, public CustomAllreduce head exchange, in-place dim-0 reduce_scatter Nov 3, 2026
@github-actions github-actions Bot added the FlyDSL label Nov 3, 2026
@whx-sjtu whx-sjtu changed the title [FlyDSL] dist: arm PCP in graph_capture, public CustomAllreduce head exchange, in-place dim-0 reduce_scatter [FlyDSL] dist: public SP APIs: PCP graph_capture, head exchange, all_to_all, quick reduce-scatter, MegaMoE setup errors Nov 3, 2026
whx-sjtu added a commit to ROCm/ATOM that referenced this pull request Nov 3, 2026
- Use AITER's public SP APIs (ROCm/aiter#7346): device_communicator
  all_gatherv / all_to_all, QuickAllReduce's reduce-scatter admission,
  MegaMoeSetupError and MegaMoeTP.prepare_all. Drop gather_tokens,
  all_to_all_into, quick_reduce_scatter.py, the MORI probe and the
  setup-failure string matching.
- SPModelWrapper shards, runs and gathers the model like UBatchWrapper,
  so eager, TR_HYBRID, capture and full_forward share one call.
- Move the SP attention op and its FP8 output path to
  model_ops/sp_attention.py; distributed keeps the exchange.
- gather_heads pads inside its send buffer instead of torch.cat.
- pcp_is_enabled -> pcp_stripes_tokens, pcp_stripe_count(),
  local_num_kv_heads(), group_min.
- Revert the topK.py non-EP fast path and the graph_capture re-wrap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
whx-sjtu added a commit to ROCm/ATOM that referenced this pull request Nov 3, 2026
- Drop the FP4 pre-gather wire and its fused_moe dispatch predictor; the
  PCP/SP split pass packs routed_rows_wire again, so plain PCP matches main.
- Dispatch SP MegaMoE from FusedMoE.forward_impl behind the existing
  moe_forward op. Remove the comm-fused op, supports(), the
  sp_mega_moe_enabled config field and its compile-hash factor; M3 marks its
  MoE with allow_sp_mega_moe instead of enable_comm_fused.
- Import fused_qk_rmsnorm_per_token_quant directly and raise on shapes the
  FP32-norm quant path cannot take.
- Use ROCm/aiter#7346: graph_capture() enters PCP, CustomAllreduce exposes
  registered_input_view/head_exchange, and dim-0 reduce_scatter writes in
  place. Delete sp_graph_capture, sp_registered_buffer, the private
  CustomAllreduce reads and reduce_scatter_tokens.
- One custom all-gather check (token_transport.custom_gather_ok) shared by
  indexer_cp and the V4.1 mono runner.
- Delete sp_pad_len, the SP group aliases and kv_head_shards; use the PCP
  helpers and attn_head_shard_size().
- Graphs and eager read the SP token shard as a view of
  forward_vars["input_ids"]; refuse max_num_batched_tokens not divisible
  by the SP size.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
whx-sjtu added a commit to ROCm/ATOM that referenced this pull request Nov 3, 2026
- Use AITER's public SP APIs (ROCm/aiter#7346): device_communicator
  all_gatherv / all_to_all, QuickAllReduce's reduce-scatter admission,
  MegaMoeSetupError and MegaMoeTP.prepare_all. Drop gather_tokens,
  all_to_all_into, quick_reduce_scatter.py, the MORI probe and the
  setup-failure string matching.
- SPModelWrapper shards, runs and gathers the model like UBatchWrapper,
  so eager, TR_HYBRID, capture and full_forward share one call.
- Move the SP attention op and its FP8 output path to
  model_ops/sp_attention.py; distributed keeps the exchange.
- gather_heads pads inside its send buffer instead of torch.cat.
- pcp_is_enabled -> pcp_stripes_tokens, pcp_stripe_count(),
  local_num_kv_heads(), group_min.
- Revert the topK.py non-EP fast path and the graph_capture re-wrap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
whx-sjtu added a commit to ROCm/ATOM that referenced this pull request Nov 3, 2026
- Drop the FP4 pre-gather wire and its fused_moe dispatch predictor; the
  PCP/SP split pass packs routed_rows_wire again, so plain PCP matches main.
- Dispatch SP MegaMoE from FusedMoE.forward_impl behind the existing
  moe_forward op. Remove the comm-fused op, supports(), the
  sp_mega_moe_enabled config field and its compile-hash factor; M3 marks its
  MoE with allow_sp_mega_moe instead of enable_comm_fused.
- Import fused_qk_rmsnorm_per_token_quant directly and raise on shapes the
  FP32-norm quant path cannot take.
- Use ROCm/aiter#7346: graph_capture() enters PCP, CustomAllreduce exposes
  registered_input_view/head_exchange, and dim-0 reduce_scatter writes in
  place. Delete sp_graph_capture, sp_registered_buffer, the private
  CustomAllreduce reads and reduce_scatter_tokens.
- One custom all-gather check (token_transport.custom_gather_ok) shared by
  indexer_cp and the V4.1 mono runner.
- Delete sp_pad_len, the SP group aliases and kv_head_shards; use the PCP
  helpers and attn_head_shard_size().
- Graphs and eager read the SP token shard as a view of
  forward_vars["input_ids"]; refuse max_num_batched_tokens not divisible
  by the SP size.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
whx-sjtu added a commit to ROCm/ATOM that referenced this pull request Nov 3, 2026
- Use AITER's public SP APIs (ROCm/aiter#7346): device_communicator
  all_gatherv / all_to_all, QuickAllReduce's reduce-scatter admission,
  MegaMoeSetupError and MegaMoeTP.prepare_all. Drop gather_tokens,
  all_to_all_into, quick_reduce_scatter.py, the MORI probe and the
  setup-failure string matching.
- SPModelWrapper shards, runs and gathers the model like UBatchWrapper,
  so eager, TR_HYBRID, capture and full_forward share one call.
- Move the SP attention op and its FP8 output path to
  model_ops/sp_attention.py; distributed keeps the exchange.
- gather_heads pads inside its send buffer instead of torch.cat.
- pcp_is_enabled -> pcp_stripes_tokens, pcp_stripe_count(),
  local_num_kv_heads(), group_min.
- Revert the topK.py non-EP fast path and the graph_capture re-wrap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
whx-sjtu added a commit to ROCm/ATOM that referenced this pull request Nov 3, 2026
- Drop the FP4 pre-gather wire and its fused_moe dispatch predictor; the
  PCP/SP split pass packs routed_rows_wire again, so plain PCP matches main.
- Dispatch SP MegaMoE from FusedMoE.forward_impl behind the existing
  moe_forward op. Remove the comm-fused op, supports(), the
  sp_mega_moe_enabled config field and its compile-hash factor; M3 marks its
  MoE with allow_sp_mega_moe instead of enable_comm_fused.
- Import fused_qk_rmsnorm_per_token_quant directly and raise on shapes the
  FP32-norm quant path cannot take.
- Use ROCm/aiter#7346: graph_capture() enters PCP, CustomAllreduce exposes
  registered_input_view/head_exchange, and dim-0 reduce_scatter writes in
  place. Delete sp_graph_capture, sp_registered_buffer, the private
  CustomAllreduce reads and reduce_scatter_tokens.
- One custom all-gather check (token_transport.custom_gather_ok) shared by
  indexer_cp and the V4.1 mono runner.
- Delete sp_pad_len, the SP group aliases and kv_head_shards; use the PCP
  helpers and attn_head_shard_size().
- Graphs and eager read the SP token shard as a view of
  forward_vars["input_ids"]; refuse max_num_batched_tokens not divisible
  by the SP size.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
whx-sjtu added a commit to ROCm/ATOM that referenced this pull request Nov 3, 2026
- Use AITER's public SP APIs (ROCm/aiter#7346): device_communicator
  all_gatherv / all_to_all, QuickAllReduce's reduce-scatter admission,
  MegaMoeSetupError and MegaMoeTP.prepare_all. Drop gather_tokens,
  all_to_all_into, quick_reduce_scatter.py, the MORI probe and the
  setup-failure string matching.
- SPModelWrapper shards, runs and gathers the model like UBatchWrapper,
  so eager, TR_HYBRID, capture and full_forward share one call.
- Move the SP attention op and its FP8 output path to
  model_ops/sp_attention.py; distributed keeps the exchange.
- gather_heads pads inside its send buffer instead of torch.cat.
- pcp_is_enabled -> pcp_stripes_tokens, pcp_stripe_count(),
  local_num_kv_heads(), group_min.
- Revert the topK.py non-EP fast path and the graph_capture re-wrap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
whx-sjtu added a commit to ROCm/ATOM that referenced this pull request Nov 5, 2026
- Drop the FP4 pre-gather wire and its fused_moe dispatch predictor; the
  PCP/SP split pass packs routed_rows_wire again, so plain PCP matches main.
- Dispatch SP MegaMoE from FusedMoE.forward_impl behind the existing
  moe_forward op. Remove the comm-fused op, supports(), the
  sp_mega_moe_enabled config field and its compile-hash factor; M3 marks its
  MoE with allow_sp_mega_moe instead of enable_comm_fused.
- Import fused_qk_rmsnorm_per_token_quant directly and raise on shapes the
  FP32-norm quant path cannot take.
- Use ROCm/aiter#7346: graph_capture() enters PCP, CustomAllreduce exposes
  registered_input_view/head_exchange, and dim-0 reduce_scatter writes in
  place. Delete sp_graph_capture, sp_registered_buffer, the private
  CustomAllreduce reads and reduce_scatter_tokens.
- One custom all-gather check (token_transport.custom_gather_ok) shared by
  indexer_cp and the V4.1 mono runner.
- Delete sp_pad_len, the SP group aliases and kv_head_shards; use the PCP
  helpers and attn_head_shard_size().
- Graphs and eager read the SP token shard as a view of
  forward_vars["input_ids"]; refuse max_num_batched_tokens not divisible
  by the SP size.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
whx-sjtu added a commit to ROCm/ATOM that referenced this pull request Nov 5, 2026
- Use AITER's public SP APIs (ROCm/aiter#7346): device_communicator
  all_gatherv / all_to_all, QuickAllReduce's reduce-scatter admission,
  MegaMoeSetupError and MegaMoeTP.prepare_all. Drop gather_tokens,
  all_to_all_into, quick_reduce_scatter.py, the MORI probe and the
  setup-failure string matching.
- SPModelWrapper shards, runs and gathers the model like UBatchWrapper,
  so eager, TR_HYBRID, capture and full_forward share one call.
- Move the SP attention op and its FP8 output path to
  model_ops/sp_attention.py; distributed keeps the exchange.
- gather_heads pads inside its send buffer instead of torch.cat.
- pcp_is_enabled -> pcp_stripes_tokens, pcp_stripe_count(),
  local_num_kv_heads(), group_min.
- Revert the topK.py non-EP fast path and the graph_capture re-wrap.

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

Copy link
Copy Markdown
Contributor

Review: #7346 — Public SP APIs (PCP graph_capture, head exchange, all_to_all, quick RS, MegaMoE errors)

Verdict: ⚠️ Not ready to approve. The code logic looks correct, but CI does not test the new code. Fix the items below and this can be approved.

What it does

  • graph_capture() now also arms the PCP group's custom all-reduce, as it already did for DCP.
  • New public CustomAllreduce methods: registered_input_view, should_head_exchange, head_exchange
  • reduce_scatter(dim=0) writes straight into the output, with no temporary and no copy.
  • New all_to_all (grouped NCCL send/recv, graph-capturable)
  • should_quick_reduce_scatter / quick_reduce_scatter (INT4, gfx950 TP4, ≥24 MiB, opt-in)
  • MegaMoE: MegaMoeSetupError raised on every rank, plus prepare_all() and sdma_available()

Must fix

  1. CI never runs the new tests (verified)
    • test_sp_head_exchange.py has no __main__. CI runs it as python3 file, so it "passes" in 0.99 s without executing a single case.
    • test_parallel_groups.py runs in CI with pcp=1, so the new PCP assert is always true.
    • test_mega_moe_tp.py is skipped in CI.
    • Ask: run test_sp_head_exchange.py through pytest in aiter_test.sh, add a --pcp 2 CI run, and attach the 4×MI355X logs.
  2. The capture test cannot detect a wrong buffer binding (verified)
    • The test replays with the same x that the previous staged call already left in the pool, so it passes whichever buffer the capture bound.
    • Ask: write new values into x after capture, then replay and check against them.

Should fix

  1. head_exchange() has no guard of its own (verified): on gfx1250 or a disabled communicator, the C++ op reinterpret_casts the wrong or null handle (UB or a segfault). Ask: raise when disabled or _is_gfx1250.
  2. Needs a rebase (verified): the diff no longer git applys on current main ([HIP] fea: impl lamport allreduce on gfx9 #7452, [HIP] [FlyDSL] [Bugfix] Size the custom allreduce pool from per-op AR/AG/RS max-size env vars #7433 and [FlyDSL] [CI] One stage and two-stage ring all-reduce kernels for PCIe interconnects #5461 touched the same files). A 3-way merge is clean, but CI ran on the old base. Ask: rebase and rerun the Multi-GPU job.

Note

  1. Perf claims cannot be reproduced (inferred): the 24 MiB INT4 floor ("+19% at 24 MiB, +2% at 6 MiB") and the "TTFT/TPOT on par" claims have no benchmark behind them. Ask: INT4 vs BF16 reduce-scatter timings at 6, 24 and 64 MiB.

Checked, no issues

  • The APIs the new code relies on still exist on current main.
  • prepare_all() covers every launch config, including the tail variants.
  • Double entry into capture() when groups share a communicator is harmless.
  • The dim-0 reduce_scatter result is unchanged.
  • CI: no failing checks (all pass or skipped).

Validation and perf were not run locally: running the tests needs a JIT build inside the checkout.

If you want it as a shareable page instead, I can publish it as an artifact

valarLip pushed a commit to ROCm/ATOM that referenced this pull request Nov 6, 2026
…mmunication (#2364)

* feat(sp): add Ulysses sequence parallelism with MegaMoE prefill MoE

Add `--sequence-parallel-size`, riding the PCP process group as an axis
independent of TP: non-attention layers run on T/W tokens, and an
exchange around attention trades the sequence for a head slice (GQA KV
heads and an indexer tail are replicated to the ranks whose queries use
them). MoE gathers the SP shards, runs this rank's expert slice and
reduce-scatters the partial sums; large MXFP4 batches route and quantize
before the gather.

ATOM_SP_MOE_MEGA (default on) runs eligible SP MXFP4 prefill MoE blocks
through AITER's MegaMoeTP, with the native norm, gate and top-k in front
of it. Ineligible configs, layers or a failed runtime setup keep the
native MoE. ATOM_TP_REPLICATED_O_PROJ (experimental, default off) keeps
o_proj replicated under TP and exchanges heads instead of all-reducing.
Both are generic and opted into per model; MiniMax-M3 is the first user.

Ported onto the request/token graph runner (#2688) and the
route-before-gather MoE (#2725): SP graphs capture this rank's token
shard at a fixed address, gathered SP rows place their experts after the
gather and skip the per-rank row count, and SP keeps its own
reduce-scatter instead of the PCP-merge all-reduce.

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

* feat(sp): replay TR_HYBRID token graphs under sequence parallelism

Under SP a decode token graph is keyed by this rank's shard of the
batch, while the capture skip and the step's replay check compared the
global row count, so SP decode never found its graph and ran eagerly.

Compare the local shard (sp_local_len) on both sides, and keep the
TR_HYBRID ladder on multiples of the SP width so each local bucket maps
to one batch size.

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

* test: skip the quick reduce-scatter dispatch test without AITER

The SP4 dispatch's arch gate imports AITER's chip_info lazily, so the
test cannot patch it on the CPU CI runner, where the module import
failed collection and interrupted the whole non-GPU suite.

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

* Fold SP head exchange into ulysses_sp and fix MegaMoE transport to FP8

The four-rank head exchange is Ulysses transport, so it moves next to
_swap_heads; the AITER op is resolved lazily to keep the module importable
without AITER. Drop ATOM_SP_MOE_MEGA_COMM_DTYPE: MegaMoeTP always moves
tokens as FP8.

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

* Address review: MegaMoE timeout and fallback, SP refusals, LM-head gather

- sp_mega_moe: raise when the MegaMoE timeout flag is set (read one step
  late, no host sync), and agree the native fallback across SP ranks.
- SP: refuse attention layers that apply RoPE outside the attention impl
  or use sinks or ALiBi, indexer heads SP can neither shard nor replicate,
  and KV-transfer connectors.
- ModelRunner: clamp the SP token-graph capture ladder to max_bs instead
  of dropping rounded-up sizes; set sp_mega_moe after any runner's model
  build, so RapidServe's decode runner has it too.
- LM head: under SP, prefill gathers only each prompt's last row instead
  of all-gathering every token's hidden state.
- Compiler: flatten nested inputs for every cache-backed artifact, not
  only torch >= 2.10.
- SP Triton kernels: int64 row offsets.
- Name the QuickRS and head-exchange thresholds.

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

* Address review: one routed-row MoE gather, token transport, MegaMoE hook

- MoE under SP and the replicated o_proj token group: route the local rows
  on their owner, then gather hidden states, top-k weights and ids (and
  MXFP4 scales when fused_moe would prequantize) in one all_gatherv, the
  pack_routed_rows/gather_rows path DP and PCP already use. Drops the
  separate route-then-gather branch, its M3-shaped gates and the
  32768-row threshold.
- Prequant prediction resolves the 2-stage config as fused_moe does for
  MXFP4 input with scales: Opus-sorted a4w4 override, EP mask, no inline
  sort; FP8 activations never prequantize.
- reassign_gathered_shared_ids returns early without EP, where every row
  carries the same prefilled shared ids.
- atom/distributed/token_transport.py holds the token and head transport
  shared by Ulysses SP, the replicated o_proj and the MoE gathers.
- MegaMoE finds a model's MoE layers through the registry
  (sp_mega_moe_layers); FusedMoE.sp_mega_moe holds the backend, and
  MiniMax-M3 runs one decoder loop with or without it.
- TP1: Gemma RMSNorm + per-token FP8 quant takes the fused kernel when no
  all-reduce is pending.
- Decode-padding test: SP prefill passes the local shard to compute_logits.

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

* Address review: non-SP norm numerics, MegaMoE setup, replicated o_proj

- MiniMax-M3: the one-kernel Gemma RMSNorm + per-token FP8 quant runs only
  under SP and the replicated o_proj (gemma_rms_norm_quant's `fused`).
  Plain TP and TP1 quantize the BF16-rounded norm again, as on main, so
  mono's stages match.
- sp_mega_moe: the epoch-reset budget counts the launches forward_block
  runs for the uncapped local shard. Setup refuses without the fused Gemma
  RMSNorm FP8 kernel, and only the imports and a MORI probe fall back on
  ImportError, before any collective.
- Replicated o_proj: with an unfused shared expert, gather the local rows
  once before the gate for the routed and shared experts. The capture
  ladder rounds to batch sizes whose rows split evenly over TP
  (split_rows_graph_ladder, speculative q lengths included), so decode
  graphs do not pad. The BF16 scale is new_empty, padding uses
  pcp_pad_dense, and a padded residual is not cloned.
- SP no longer counts as PCP striping: the runner reads
  Config.pcp_striping_size and pcp_is_enabled() is False under SP.
  ModelRunner.world_size is the TP width again; the KV-head math divides
  by kv_head_shards = tp * sp.
- The graph-bucket memory guard MIN-reduces free memory over the DP, TP
  and PCP groups.
- MoE: the MXFP4 prequant wire is chosen for the rows after the simulated
  DP repeat.
- token_transport: the PyNccl reduce-scatter calls reduce_scatterv, which
  checks the split.
- GemmaRMSNorm's BF16 path and MegaMoE's _norm_input share
  gemma_rms_norm_unquantized.
- Docs: ATOM_TP_REPLICATED_O_PROJ, ATOM_SP_MOE_MEGA and
  --sequence-parallel-size / -sp.

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

* Address review: refuse SP with pipeline parallelism

- Ulysses SP refuses --pipeline-parallel-size > 1 at configuration time;
  the combination is not validated. The guides list -pp 1 next to -tp 1.

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

* Resolve the MXFP4 gather wire on first use

- Mxfp4MoEMethod resolved `_fp4_rows_wire` in `__init__`, which reads
  `moe.in_dtype`/`hidden_dim`; main's MXFP4 method tests build the method
  from a stub config without them and failed. It is a cached property now,
  read only when a gather is prequantized.

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

* Address review: refuse SP with expert parallelism

- SP + EP has never run on GPU, so `_init_sequence_parallel` now raises
  for `--enable-expert-parallel`, and the guides list it next to `-tp 1`
  and `-pp 1`. The SP-only EP pieces go with it: SP token shards in the
  MoE EP/all2all selection, the local-shard all2all capacity, and the
  shared-expert fusion fallback for non-MXFP4 SP + EP. They return with
  the follow-up that adapts SP to EP.

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

* Address review: state SP's only validated model in the guides

- The configuration and distributed guides now say SP has been validated
  only on MiniMax-M3 MXFP4; no other model or quantization has run under
  SP on GPU.

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

* Address review: pass the post-attention eps into SP MegaMoE

- sp_mega_moe_block takes the post-attention norm's own eps instead of
  assuming the fused tail's eps; the tail still runs fused only when the
  next norm's eps matches it.
- The configuration and distributed guides say SP has run only at SP4 and
  that KV replication (fewer KV heads than SP ranks) has not run end to end.

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

* Address review: SP MegaMoE agreement, vocab-sharded SP LM head, drop riders

- SP MegaMoE: route through tgemm.mm; read the error bits group-wide before
  resetting them; agree the all-or-nothing fallback with tp_agree and warn
  on it; launch the fallback as one untailed tile without a BF16 scale.
- Ulysses SP decode projects each rank's vocab slice and gathers the slices
  instead of running the full LM head on every rank.
- Drop the EP routed-scale and EP compile-hash changes; the SP hash factor
  only appears when SP is on.
- Refuse SP with --enable-dp-attention, in DP-isolated RLHF workers and for
  MiniMax-M3 image input; say so in the docs and -sp help.
- Log the first INT4 quick reduce-scatter; explain the 2 MiB all-gather
  threshold and reuse custom_gather_ok for the head exchange.
- Restore main's running_tokens_across_dp and fix the stale sparse-decode
  comment.

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

* Test the MXFP4 gathered-rows wire against AITER fused_moe

On MiniMax-M3's SP MoE shape, rows the method gathers in MXFP4 must come out
of apply as their BF16 originals do. Skips without AITER or gfx950.

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

* Address review: move the TP replicated o_proj to its own PR

- Remove the experimental TP replicated o_proj (ATOM_TP_REPLICATED_O_PROJ,
  its config field, validation and hash factor, the custom ops module, the
  MoE token_group gather, the capture-ladder and capacity branches, docs and
  tests); the SP code paths are unchanged.
- Keep the FP8 head-exchange flag on the owning M3 attention module, so
  _minimax_m3_attend_and_project takes that module and reads one flag.
- The final norm now has one exit besides the SP MegaMoE tail.

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

* Address review: one routed-rows gather for SP and PCP

SP's MoE gather and PCP_MOE_MERGE's gather in _run_experts now share
gather_routed_rows: one grouped all_gatherv of the packed rows, then the
shared-expert id reassignment.

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

* Address review: SP refusals, MegaMoE warmup and step accounting

- Refuse what bypasses the SP token split: RLHF hidden-state export,
  ATOM_FWD_DUMP_DIR forward hooks under SP MegaMoE, and RapidServe with
  -pcp or -sp; LLMEngine rechecks DP after the legacy DP kwargs land.
- Fall back to the native MoE when a MegaMoeTP big-M warmup wait timed
  out on any rank, instead of failing the second step.
- Count launches and copy MegaMoE error bits only on steps whose rows take
  MegaMoE; supports() asks fused_moe's own activation dtype resolver at
  the gathered M, shared with the MXFP4 prequant predictor, whose cache is
  keyed on the padded M.
- Move the CPU-group agreement to atom/distributed/group_agreement.py;
  mono re-exports it as tp_agree.
- Share the vocab-slice GEMM between the SP and DP sharded LM heads; SP
  gathers the slices with all_gather(dim=-1).
- Remove dead code: the unreachable SP prefill token graph refusal, the lcm
  over q buckets (SP refuses speculative decoding), and MiniMaxM3MoE's
  x_scale argument.
- Test the rows wire at the SP4 intermediate (768); restore device="cpu"
  in the memory guard; docs for the SP index and the PCP dimension.

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

* SP: run MegaMoE as a comm-fused MoE backend; drop the side paths

Review 5731266938:
- SP MegaMoE is a CommFusedMoeBackend reached through
  forward_maybe_comm_fused. The per-model custom op, the registry table,
  the FusedMoE attributes, M3's second forward branch, _router_logits and
  the fused next-norm tail are gone; small batches fall back to the
  layer's native forward.
- One PCP split branch in _run_experts serves PCP merge and SP: the wire
  comes from gathered_rows_wire and pcp_reduce_scatter tries the quick
  reduce-scatter first. sp_moe_reduce_scatter is removed.
- sp_mega_buffers.py and its test are removed (copy_ covers them);
  gemma_norm_fp8.py is folded into layernorm.gemma_rms_norm_quant,
  renamed quantize_fp32_norm and dropped from the TP all-reduce helper.
- MORI is probed only when the local tile reaches the big-M kernel, and
  the runtime is closed when an agreed setup failure aborts prepare().
- The refusal lists keep only what Config cannot see (EPLB, dtype,
  gfx950, ATOM_FWD_DUMP_DIR); the multimodal refusal in llm_engine goes.
- The SP decode graph records the token gather and the LM head, as TP1
  does. ModelRunner asserts no token-graph builder runs under SP, the
  precondition sp_attention_fp8 now states.
- fp8_head_exchange passes STRIDE and RANK at run time: one build.
- MiniMax-M3's FlyDSL row limit counts KV heads per attn_head_shard_size().

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

* Address review: keep PCP merge on the exact reduce-scatter; zero-row norm guard

- pcp_reduce_scatter takes the INT4 QuickReduce reduce-scatter only under SP;
  PCP merge alone keeps main's exact BF16 reduce-scatter.
- GemmaRMSNorm.forward_cuda skips the launch on zero rows again, as
  gemma_rms_norm_quant does (lost when gemma_rms_norm_unquantized was inlined).

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

* Skip the PCP reduce-scatter dispatch test where aiter is absent

pcp_utils imports aiter at load, so the non-GPU CI cannot import it; skip
through import_guard as the other aiter-backed tests do.

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

* Return empty outputs from gemma_rms_norm_quant before any zero-row launch

AITER's per-token HIP quant has no rows==0 guard either, so the unfused path
left the same invalid-configuration error for the next kernel as the fused
one did. Guard once at entry so both paths skip every launch.

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

* SP: address review round 13, use aiter public comm APIs

- Drop the FP4 pre-gather wire and its fused_moe dispatch predictor; the
  PCP/SP split pass packs routed_rows_wire again, so plain PCP matches main.
- Dispatch SP MegaMoE from FusedMoE.forward_impl behind the existing
  moe_forward op. Remove the comm-fused op, supports(), the
  sp_mega_moe_enabled config field and its compile-hash factor; M3 marks its
  MoE with allow_sp_mega_moe instead of enable_comm_fused.
- Import fused_qk_rmsnorm_per_token_quant directly and raise on shapes the
  FP32-norm quant path cannot take.
- Use ROCm/aiter#7346: graph_capture() enters PCP, CustomAllreduce exposes
  registered_input_view/head_exchange, and dim-0 reduce_scatter writes in
  place. Delete sp_graph_capture, sp_registered_buffer, the private
  CustomAllreduce reads and reduce_scatter_tokens.
- One custom all-gather check (token_transport.custom_gather_ok) shared by
  indexer_cp and the V4.1 mono runner.
- Delete sp_pad_len, the SP group aliases and kv_head_shards; use the PCP
  helpers and attn_head_shard_size().
- Graphs and eager read the SP token shard as a view of
  forward_vars["input_ids"]; refuse max_num_batched_tokens not divisible
  by the SP size.

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

* SP: address review round 14

- Use AITER's public SP APIs (ROCm/aiter#7346): device_communicator
  all_gatherv / all_to_all, QuickAllReduce's reduce-scatter admission,
  MegaMoeSetupError and MegaMoeTP.prepare_all. Drop gather_tokens,
  all_to_all_into, quick_reduce_scatter.py, the MORI probe and the
  setup-failure string matching.
- SPModelWrapper shards, runs and gathers the model like UBatchWrapper,
  so eager, TR_HYBRID, capture and full_forward share one call.
- Move the SP attention op and its FP8 output path to
  model_ops/sp_attention.py; distributed keeps the exchange.
- gather_heads pads inside its send buffer instead of torch.cat.
- pcp_is_enabled -> pcp_stripes_tokens, pcp_stripe_count(),
  local_num_kv_heads(), group_min.
- Revert the topK.py non-EP fast path and the graph_capture re-wrap.

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

* SP: sort the pcp_utils imports after the pcp_stripes_tokens rename

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

* SP: address review round 15

- run_model: SP takes model_output[:scheduled_tokens] like every other path.
- Config refuses -pcp > 1 with -sp > 1; ulysses_sp reads the SP width from
  the current config.
- Attention impls declare their fused-qkv fields (qkv_fields); one column
  table drives the head exchange and the pack kernel.
- sp_head_shards() for head sharding; the legacy DP kwargs build
  ParallelConfig before Config.
- do_not_specialize the runtime sizes of the SP Triton kernels; the head
  exchange communicator is chosen at layer build.
- check_aiter_sp_api() names the missing AITER APIs at startup.
- SPModelWrapper hands the model this rank's rows of inputs_embeds, so a
  multimodal prefill runs under SP.
- SP tests load ATOM through tests/aiter_stubs.py where AITER is absent;
  so does the top-k routing rows test.
- Move sp_mega_moe.py to model_ops/fused_moe/; drop the unused index_q_size
  kwarg M3 passed to Attention.

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

* SP: read the SP width through an explicit optional config

get_current_atom_config_or_none() returns None where no config is set;
get_current_atom_config() keeps its assertion on top of it. ulysses_sp
reads the SP width through it instead of catching the AssertionError.

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

* tests: keep scaled_table's values and scales on separate pages

The 1 MiB scale buffer comes off the heap once malloc's mmap threshold has
grown, so the small values tensor could share its first page; both were
then registered as one run and the scripted second refusal never came
(test_a_refused_shared_registration_falls_back_to_a_copy, Pre Checkin).
Both now sit in one buffer, two pages apart.

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

* Address review round 16

- Keep decode logits out of graphs when the SP head would gather over RCCL
  (ATOM_USE_CUSTOM_ALL_GATHER=0).
- Skip-top-k sparse layers exchange only q/k/v under Ulysses SP.
- Note that SP and plain -tp 1 quantize the M3 norm at different points.
- Pass device="cpu" to the group agreement tensor.
- Tests: patch attn_head_shard_size in the DCP builder test, pin the AOT
  artifact's unflattened inputs, and check the real AITER resolver's
  MegaMoE threshold.

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

* vLLM plugin: derive the MiniMax-M3 index_q_size like the native impl

The M3 layer no longer passes index_q_size to Attention, and the vLLM
sparse layer refused to build without it. It now takes
num_kv_heads * index_head_dim, as the native impl does when indexer CP
is off, which plugin mode always is.

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

* SP MegaMoE: close the runtime at exit; rename count_step to before_step

ModelRunner.exit() closes the shared MegaMoeTP runtime next to
close_mega_transports(): its close is collective over the SP group,
which destroy_dist_env() destroys. count_step did more than count, so it
is before_step, and its docstring says what it does: the async timeout
check, the launch count, and every RESET_LAUNCHES the agreed host sync
and collective reset; capture warmups go uncounted. The exit test now
sets structured_compile_executor, without which exit() raised before
any close on an AITER host.

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

* SP MegaMoE: ask AITER whether the GPU has the kernel

mega_moe_tp_supported() is the MegaMoeTP constructor's own check, which
raises ValueError rather than MegaMoeSetupError, so it stays a
pre-check; it ships in the same module as MegaMoeTP, so the import's
ImportError fallback covers both.

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

* SPModelWrapper: drop the inputs_embeds branch

Nothing passes inputs_embeds under SP: SP takes MHA models only, the
one MHA VL model (MiniMax-M3) refuses images under SP, and SP refuses
PP. A future MHA VL model gets a TypeError instead of a silent path.

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

* SP: mark every pass pcp_split in SPModelWrapper; FusedMoE reads only that

FusedMoE no longer asks sp_is_enabled() per layer. Plain PCP is
unchanged: its setters never mark a dummy pass split.

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

* ModelRunner: drop TP from the capture memory guard; restore main's capture loop

The guard min-reduces free memory over DP and PCP, as before SP; the
capture loop slices input_ids inline again, as main does.

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

* MiniMax-M3: mono matches TP4, not -tp 1; fix the quantization comment

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

* Move the custom all-gather admission out of the SP head transport

custom_gather_ok and the communicator lookup it needs now live in
atom/distributed/custom_gather.py, so indexer CP and the DeepSeek-V4.1
mono runner no longer import an SP module to ask whether AITER's
registered-buffer all-gather takes a payload. Behaviour is unchanged.

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

* Shard the SP LM head only where the custom all-gather takes it

The vocab-sharded SP head now runs only when AITER's custom all-gather
admits the per-rank logit slice (env on, a usable ca_comm, an even split
and 16-byte rows). Otherwise every SP rank runs the whole replicated head,
which needs no collective, so decode logits stay capturable and
logits_in_graph is back to `self.world_size == 1`.

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

* compile: keep a split op's getitems in its own piece

split_graph put the getitems that unpack a tuple-returning split op
(sp_attention_fp8's (output, scale)) into the next compiled piece, so that
piece took the tuple as one input. A reloaded standalone artifact cannot
unpack it, which the loader worked around by flattening the call arguments.

Port vLLM's fix (vllm-project/vllm#28533): a getitem joins its producer's
piece, so the split op's piece returns the tensors and no compiled piece
takes a tuple. The loader goes back to calling the artifact as is. Graphs
whose split ops return one tensor partition as before.

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

* SP: drop the INT4 QuickReduce reduce-scatter

With MegaMoE running, the native expert reduce-scatter only sees decode
batches under 256 global rows (under 3 MiB at M3's hidden size), far below
AITER's 24 MiB QuickReduce threshold, so the branch never ran in the
deployment SP is validated on. Go back to the exact reduce_scatter and
stop requiring QuickAllReduce.quick_reduce_scatter from AITER.

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

* norm: drop the zero-row guards

Every SP rank runs ceil(N / SP) >= 1 rows, padding included, and no forward
runs with zero tokens, so the GemmaRMSNorm and gemma_rms_norm_quant guards
never fired. GemmaRMSNorm.forward_cuda is back to main's form.

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

* tests: one AITER stub module, shared MoE fixtures in a conftest

Fold tests/aiter_stubs.py into tests/aiter_stub.py, whose docstring now
says which helper to use when; the two cleanup rules stay as they are.

Move the atom_modules and sp_modules fixtures into
tests/model_ops/conftest.py, so the SP MoE tests no longer import
fixtures across files or call a fixture's __wrapped__. The directory
gets an __init__.py, as tests/attentions/deepseek_v41 has: a conftest
outside a package is imported as `conftest` and would shadow
tests/conftest.py for every `from conftest import ...` collected after it.

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

* SP: keep -pcp's value under SP; size the PCP group by max(pcp, sp)

SP no longer rewrites prefill_context_parallel_size. Config.pcp_group_size
(max of the two) sizes AITER's PCP process group, which SP runs over, and
every rank count derived from it: the runner's device span and both
init_dist_env calls, EngineCore's worker count, CoreManager's RPC ranks and
EngineCapabilities.workers_per_engine.

With -pcp at 1 under SP, generic PCP code needs no SP special case, so
pcp_stripes_tokens / pcp_stripe_count go back to base's pcp_is_enabled and
config reads. The RapidServe refusal moves into SP's validation, so plain
-pcp with RapidServe is accepted again as on main.

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

* SP: refuse RLHF weight updates under Ulysses SP

SPModelWrapper holds the model as a child, so every name a trainer sent
missed and the sync was a warned no-op that kept the old weights. All three
update entry points resolve their target through _sync_target_model before
writing anything; it now raises on the SP wrapper instead of peeling it,
since reloading SP's MegaMoE experts in place is unverified. The worker
capability report stops advertising fp8_weight_update under SP.

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

* tests: back out the engram scaled_table fixture change

It fixes a flake in main's test and does not belong in the SP PR.

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

* moe: keep the dummy-pass guard for plain PCP

Only SP splits its dummy and captured passes; plain PCP with
ATOM_PCP_MOE_MERGE again runs no PCP collective on a dummy pass.

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

* config: refuse --level 1 under Ulysses SP

fullgraph cannot trace the SP decode token gather (AITER's
custom_all_gatherv), so the server would fail at the first decode
warmup.

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

* model_runner: size the TR_HYBRID memory guard on SP-local rows

The token graph records the inner model on a rank's local rows, so the
capture memory guard takes the same local count as the dedup key.

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

* SP: size the PCP process group through one helper

Config, the capabilities report and the RPC fan-out all take the
group size from pcp_group_size_of(), and the sampled-id broadcast
comment now says why SP needs it too.

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

* llm_engine: keep main's legacy DP kwargs, recheck SP after them

Restore main's post-construction assignment of the loose DP kwargs and
refuse Ulysses SP against the final DP size there instead.

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

* attention: route to Ulysses on the layer's SP columns

The layer builds sp_columns only under SP, so the per-step split op
checks that attribute instead of looking the SP size up in the config.

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

* mono, engram: call group_agree directly

Drop the tp_agree alias and route engram's UVA vote through group_agree.

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

* moe: gate sp megamoe on --moe-backend mega, raise when unsupported

Drop ATOM_SP_MOE_MEGA and the per-model opt-in. Under -sp, mega needs no EP
and keeps the standard MXFP4 method; SP without it runs the native MoE.

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

* moe: skip the collective sp megamoe close after a timeout

A rank that raised on a timed-out wait exits through ModelRunner.exit; its
peers are still in the step, so the close() barrier would hold it ~30 min.

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

* moe: count only the real rows of a gathered sp moe pass

SP shards are contiguous, so the gather keeps the step's real rows first
and the sort can skip the trailing pads, as on padded pure-TP graphs.

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

* minimax_m3: keep main's bf16-rounded norm quant under sp

Drop the fused FP32-norm quantization SP used and its layernorm helper;
SP now quantizes the same BF16-rounded norm output as TP 1.

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

* token_transport: match the all-gather threshold comment to its value

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

* ulysses_sp: say trailing ranks may hold only pad rows

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

* token_transport: pad with pcp_pad_dense

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

* sp_attention: one gather_heads ladder for bf16 and fp8 outputs

The FP8 output now takes the same alignment check, size cap, rows and
head-exchange communicator as BF16; only the long-row wire format differs.
ulysses_attention returns the padded length instead of taking a transform,
and the head all-to-all reuses ulysses_sp's.

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

* attention: hand an fp8 o_proj per-token fp8 under sp

Attention takes `per_token_fp8_out` and returns `(out, scale)` from
`sp_attention_fp8`, which now writes the scale into a caller buffer and
returns one tensor, so the backend needs no getitem rule.

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

* pcp: keep pcp_is_enabled() false under Ulysses SP

SP still runs over AITER's PCP group; its sampled-id broadcast is gated
explicitly, and mono / comm-fused MoE refuse on the group size.

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

* model_runner: drop the unreachable SP prefill-token-graph guard

No MHA backend SP accepts records prefill token graphs.

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

* region_graph: list SP token graphs under the step's rows

The SP recording unit runs one rank's shard, so its key is local; the
wrapper names the step's rows and captured_sizes reports those.

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

* ulysses_sp: read the SP size from the required atom config

Every entry point sets the config before a layer is built, so a missing
one is a bug, not SP=1. Drops get_current_atom_config_or_none().

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

* rollout: refuse Ulysses SP once, in the RLHF runner constructor

Replaces the capability, weight-update, hidden-state export and
DP-isolation guards, so an RLHF engine fails at startup instead.

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

* config: refuse multimodal checkpoints under Ulysses SP

SPModelWrapper does not shard inputs_embeds. MiniMax-M3 is not refused:
it builds no vision tower under SP and serves text.

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

* sp: let AITER choose the all-gather path

Drop atom/distributed/custom_gather.py. The SP all-gathers call
device_communicator.all_gather, which takes the custom all-gather when
AITER can and otherwise falls back to pynccl. indexer_cp.py and the
DeepSeek V4.1 mono runner go back to main.

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

* moe: read pcp_split only on PCP-merge or SP passes

vLLM plugin passes have no ATOM forward context, so _run_experts must
not touch it unless PCP merge or SP is on, as on main.

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

* sp: drop admission checks AITER already makes

MegaMoeTP refuses a non-gfx950 GPU, non-contiguous weights and non-BF16
activations itself, on every rank alike, so the startup plan no longer
repeats those checks or votes across the SP group. The head exchange
leaves the GPU, dtype and size admission to AITER's
should_head_exchange; ATOM_USE_CUSTOM_ALL_GATHER remains the opt-out.

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

* moe: decide the split pass from pcp_merge first

A layer without PCP merge never splits, so check it before asking whether
SP is enabled; that query needs the atom config, which a bare layer (and
its unit test) does not have.

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

* Fold token_transport.py into its users

What remained were two constants and two head-exchange helpers, each with
one user: the all-gather cap moves to ulysses_sp.py, the head-exchange row
floor and the communicator / staging-view helpers to sp_attention.py.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
whx-sjtu and others added 3 commits November 6, 2026 04:51
…reduce_scatter

graph_capture() entered TP/PP/DP/EP/DCP and the custom groups but not
PCP, so a PCP group's custom all-reduce was never armed for capture and
callers had to wrap the context and read ca_comm._IS_CAPTURING themselves.
Enter _PCP next to _DCP (the DCP entry also moves out of the PP/DP/EP loop,
where it was entered once per group).

CustomAllreduce gains the public surface sequence-parallel callers need
instead of reading _pool / _ptr / _IS_CAPTURING:
- registered_input_view(shape, dtype): a view of the registered input pool
  a producer can write before a collective called with registered=True.
- should_head_exchange(inp) / head_exchange(inp, registered=...): the
  four-rank [S, H] -> [S/4, 4H] exchange over sp_head_exchange, binding a
  captured input in place like the other collectives.

CudaCommunicator.reduce_scatter with dim=0 and a contiguous output now
scatters straight into output_ instead of through a temporary and a copy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eSetupError, prepare_all

- PyNcclCommunicator.all_to_all and CudaCommunicator.all_to_all (falls back
  to all_to_all_single without PyNccl).
- QuickAllReduce.should_quick_reduce_scatter / quick_reduce_scatter.
- MegaMoeSetupError, raised alike on every rank for SDMA setup, arena
  mapping, warmup timeout and MORI import failures; SdmaComm all-gathers
  the import error so no rank proceeds alone.
- MegaMoeTP.prepare_all() prepares every launch variant once.
- sdma_available() for callers that only need the MORI check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Drop QuickAllReduce.should_quick_reduce_scatter / quick_reduce_scatter
  and sdma_available(): their only caller (ATOM's SP path) no longer uses
  them.
- CustomAllreduce.head_exchange raises when the communicator is disabled
  or on the gfx1250 kernel, instead of passing the op a handle it would
  cast to the wrong type.
- test_sp_head_exchange: write new values into the input after capture
  and check the replay against them; the pool still holds the staged
  copy, so a capture bound to the wrong buffer now fails. Check that a
  disabled communicator's head_exchange raises.
- test_parallel_groups: with pcp > 1, require PCP's custom all-reduce to
  exist and be armed by graph_capture().
- aiter_test.sh: run test_sp_head_exchange.py through pytest (it has no
  script entry point), and run test_parallel_groups.py again with
  --tp 2 --pcp 2 --dp 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@whx-sjtu
whx-sjtu force-pushed the hexwang/sp-public-comm-api branch from 1992233 to d1df819 Compare November 6, 2026 11:07
@github-actions github-actions Bot changed the title [FlyDSL] dist: public SP APIs: PCP graph_capture, head exchange, all_to_all, quick reduce-scatter, MegaMoE setup errors [FlyDSL] [CI] dist: public SP APIs: PCP graph_capture, head exchange, all_to_all, quick reduce-scatter, MegaMoE setup errors Nov 6, 2026
@github-actions github-actions Bot added the CI label Nov 6, 2026
@whx-sjtu whx-sjtu changed the title [FlyDSL] [CI] dist: public SP APIs: PCP graph_capture, head exchange, all_to_all, quick reduce-scatter, MegaMoE setup errors [FlyDSL] dist: public SP APIs: PCP graph_capture, head exchange, all_to_all, MegaMoE setup errors Nov 6, 2026
@whx-sjtu

whx-sjtu commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed in d1df819, rebased onto main f705d6b:

  1. CI. .github/scripts/aiter_test.sh now runs test_sp_head_exchange.py through pytest (added to the pytest list). It also runs test_parallel_groups.py twice, at its default layout and then with --tp 2 --pcp 2 --dp 1, so the PCP assert has a real PCP group. test_mega_moe_tp.py stays skipped, as on main (Skip MegaMoE TP multigpu test #6933). The 4x MI355X logs for all three are below.
  2. Capture binding. After capture, the wrapper case now adds 1 to x, replays, and checks the result against expected + 1 (test_sp_head_exchange.py). As a positive control, I made a temporary local edit so the capture path bound the registered pool instead of x. The new check failed with 512/512 elements off by one, and the previous check still passed.
  3. Guard. CustomAllreduce.head_exchange now raises RuntimeError when the communicator is disabled or _is_gfx1250. The test checks this on a one-rank (disabled) communicator. I also checked it locally by forcing _is_gfx1250 on an enabled 4-rank communicator, and all four ranks raised.
  4. Rebase. The branch is rebased onto f705d6b, which includes [HIP] fea: impl lamport allreduce on gfx9 #7452, [HIP] [FlyDSL] [Bugfix] Size the custom allreduce pool from per-op AR/AG/RS max-size env vars #7433 and [FlyDSL] [CI] One stage and two-stage ring all-reduce kernels for PCIe interconnects #5461. The rebase was clean, and the Multi-GPU job runs on the new head.
  5. Perf claims. I removed should_quick_reduce_scatter / quick_reduce_scatter and sdma_available(), along with their test and their text in the description. Their only caller, ATOM [Feature]: AITER MLA ps mode support for q/kv head ratio of 8, mtp=4 for MI355 #2364, no longer uses them. The TTFT/TPOT statements are also gone, so the description no longer makes any perf claim.
4x MI355X (gfx950), d1df819 on main f705d6b
$ pytest -v op_tests/multigpu_tests/test_sp_head_exchange.py
PASSED op_tests/multigpu_tests/test_sp_head_exchange.py::test_sp_all_to_all
PASSED op_tests/multigpu_tests/test_sp_head_exchange.py::test_sp_head_exchange[None]
PASSED op_tests/multigpu_tests/test_sp_head_exchange.py::test_sp_head_exchange[staged]
PASSED op_tests/multigpu_tests/test_sp_head_exchange.py::test_sp_head_exchange[registered]
========================= 4 passed in 63.58s (0:01:03) =========================

$ python3 op_tests/multigpu_tests/test_parallel_groups.py
  [PASS] Group sizes + PCP topology match expected values.
  [PASS] pcp=1 5D layout is identical to the old 4D TP/PP/DP/EP.
  [ALL PASS] tp=2, dp=2, pp=1, ep=4

$ python3 op_tests/multigpu_tests/test_parallel_groups.py --tp 2 --pcp 2 --dp 1
  Rank 0: TP[0, 1]  EP[0, 1, 2, 3]  DP[0]  PP[0]  PCP[0, 2]
  Rank 1: TP[0, 1]  EP[0, 1, 2, 3]  DP[1]  PP[1]  PCP[1, 3]
  Rank 2: TP[2, 3]  EP[0, 1, 2, 3]  DP[2]  PP[2]  PCP[0, 2]
  Rank 3: TP[2, 3]  EP[0, 1, 2, 3]  DP[3]  PP[3]  PCP[1, 3]
  [PASS] Group sizes + PCP topology match expected values.
  [ALL PASS] tp=2, dp=1, pp=1, ep=4

$ torchrun --nproc_per_node=4 op_tests/multigpu_tests/test_mega_moe_tp.py --models m3 --modes ag_rs -t 256 -r random --seeds 0
| m3      | ag_rs  | varying m          | gfx950 |   0.0377042 |        | PASS     |
| m3      | ag_rs  | new / freed layers | gfx950 |   0.0376655 |        | PASS     |
| m3      | ag_rs  | out=               | gfx950 |   0.0375367 |        | PASS     |
| m3      | ag_rs  | big-M              | gfx950 |   0.0856088 |        | PASS     |
| m3      | ag_rs  | cuda graph         | gfx950 | nan         |        | PASS     |
| m3      | ag_rs  | dynamic            | gfx950 |   0.0374941 |        | PASS     |
| m3      | ag_rs  | dynamic LB         | gfx950 |   0.0268387 |        | PASS     |
| m3      | ag_rs  | masked ids         | gfx950 |   0.0374222 |        | PASS     |
| m3      | ag_rs  | m=0                | gfx950 | nan         |        | PASS     |
| m3      | ag_rs  | fused tail         | gfx950 |   0.0265001 |        | PASS     |
| m3      | ag_rs  | host validation    | gfx950 | nan         |        | PASS     |
| m3      | ag_rs  | cross-rank checks  | gfx950 | nan         |        | PASS     |
[aiter] MegaMoE TP: 15/15 passed

# Positive control: capture binds the registered pool instead of x (local edit, not committed)
$ pytest "op_tests/multigpu_tests/test_sp_head_exchange.py::test_sp_head_exchange[None]"
E           torch.testing.assert_close(out.cpu(), expected + 1, rtol=0, atol=0)
E       AssertionError: Tensor-likes are not equal!
E       Mismatched elements: 512 / 512 (100.0%)
E       Greatest absolute difference: 1.0 at index (0, 0)
============================== 1 failed in 9.59s ===============================
# the same edit against the previous version of the case:
PASSED ::test_sp_head_exchange[None]
============================== 1 passed in 9.46s ===============================

# Guard with _is_gfx1250 forced on an enabled 4-rank communicator
rank 0: gfx1250 guard raised: head_exchange needs an enabled custom allreduce on the pre-gfx1250 kernel; check should_head_exchange first
(same on ranks 1-3)

@zufayu zufayu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AITER SOP code review on current head d1df819:

Verified blocker: CustomAllreduce.head_exchange() is a public API, but it only checks disabled/gfx1250 and does not enforce the constraints already encoded by should_head_exchange(): world_size == 4, 2-D contiguous input, rows divisible by 4, and 16-byte alignment. A direct TP2 or invalid-shape call can still launch a four-rank-semantics kernel and produce wrong output or a device fault.

Primary reviewer: @TennyWang1223 (communication/all-reduce owner); @coderfeli can co-review the FlyDSL MegaMoE portion.

Author action: enforce the complete contract inside head_exchange(), add TP2/non-divisible/non-aligned rejection tests, and rebase current main. The current red FlyDSL test does not have a demonstrated causal link to this patch, but the stale conflict must still be resolved before merge.

@TennyWang1223

Copy link
Copy Markdown
Contributor

Re-review of d1df819

Thanks @whx-sjtu. I checked all five points from my earlier review against d1df819, and they are all fixed:

  1. CI runs the new tests. test_sp_head_exchange.py now runs through pytest, and test_parallel_groups.py also runs with --tp 2 --pcp 2 --dp 1, so the PCP assert sees a real PCP group. The Multi-GPU (8 GPU) job passed on this head.
  2. The capture test can now catch a wrong binding. It does x.add_(1) after capture and compares the replay against expected + 1. Your positive control shows the new check fails when the capture binds the pool, where the old one passed.
  3. head_exchange() guards disabled and gfx1250. It raises RuntimeError, and the test covers the disabled case.
  4. Rebase. This was done, but see below: the PR conflicts with main again.
  5. Perf claims. The quick reduce-scatter path and sdma_available() are gone, along with the perf text in the description.

On @zufayu's blocker (full contract in head_exchange): the C++ op already rejects these inputs before launch. csrc/kernels/sp_head_exchange.cu:44-69 checks world_size_ == 4, 2-D contiguous input and output, size(0) % 4, row_bytes % 16, 16-byte alignment of input, output and the staged buffer, and the pool size. Each check is an AITER_CHECK, which throws std::runtime_error. So a TP2 call or a bad shape raises an error; it does not produce wrong output or a device fault. I still agree with the ask as hardening, because it's cheap and makes the error clear on the Python side:

  • In head_exchange(), check the same shape conditions as should_head_exchange() (world_size, dim() == 2, contiguous, rows % 4, row bytes % 16) and raise ValueError or RuntimeError before allocating out. Note that the pool-size check should only apply on the staged path: a registered input bound during capture doesn't have to fit in the pool, so calling should_head_exchange() as-is would reject valid captured inputs.
  • Add rejection tests for a TP2 communicator, rows not divisible by 4, and a row width that isn't a multiple of 16 bytes.

Still blocking merge:

  • Conflicts with main in .github/scripts/aiter_test.sh, aiter/dist/device_communicators/custom_all_reduce.py and aiter/ops/flydsl/kernels/mega_moe_tp/mega_moe_tp.py. Please rebase.
  • Red Aiter Test Gate. Shard 2 failed in op_tests/test_flydsl_moe_aux.py with NameError: DROPPED_ROUTE_ROW. This comes from the old base: moe_contiguous_psum.py is missing an import, which main fixed in [FlyDSL] Fix main CI: missing DROPPED_ROUTE_ROW import in moe_contiguous_psum #7583, and this PR doesn't touch that file. The rebase should clear it.

Once the rebase is in, the guard and tests above are added, and CI (including Multi-GPU) is green, I'll approve.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:multi-gpu Trigger multi-GPU op tests on PR CI FlyDSL stale The PR hasn't been updated in 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants