Skip to content

[MORI] Manage v2 CCO through the all2all manager - #6618

Merged
TennyWang1223 merged 12 commits into
mainfrom
codex/mori-v2-all2all-manager
Oct 27, 2026
Merged

TennyWang1223 merged 12 commits into
mainfrom
codex/mori-v2-all2all-manager

Conversation

@JiaoliangYu

Copy link
Copy Markdown
Contributor

Summary

  • add a mori_v2 all-to-all backend whose manager owns the shared MORI CCO communicator
  • create the communicator lazily with an explicit per-rank VMM capacity, reuse sufficient capacity, and reject unsafe in-place growth
  • cache regular MORI v2 EpDispatchCombineOp handles while exposing the manager-owned communicator to higher-level users such as MegaMoE
  • close live v2 handles before destroying the shared communicator, and avoid publishing failed collective initialization

Motivation

MORI v2 currently brings up its CCO communicator in framework integration code. Moving that lifecycle into AITER gives the v2 backend the same explicit, demand-driven ownership model as the existing all-to-all managers. MegaMoEGfx1250 remains outside the communication manager and may only borrow the communicator; this PR does not move model or expert-GEMM configuration into the distributed layer.

Testing

  • ruff check on the changed implementation and tests
  • ruff format --check on the changed Python files
  • pytest op_tests/test_mori_v2_all2all_manager.py -q (14 passed in a CPU/mock environment)

ROCm/GPU collective coverage is left to CI because the local Windows environment has no ROCm runtime.

Follow-up

After this lands, ATOM can request get_or_create_all2all_manager("mori_v2"), use get_handle(...) for the gather path, and use get_or_create_cco_communicator(...) when constructing MegaMoE.

@JiaoliangYu
JiaoliangYu requested a review from a team October 16, 2026 09:23
@github-actions

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 6618 --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.

@TennyWang1223 TennyWang1223 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.

has_mori() only checks the top-level package. With an older MoRI (no mori.cco / dispatch_combine_v2) the manager constructs fine and fails later inside get_handle. Please gate on the v2 submodules in init.

@JiaoliangYu

Copy link
Copy Markdown
Contributor Author

has_mori() only checks the top-level package. With an older MoRI (no mori.cco / dispatch_combine_v2) the manager constructs fine and fails later inside get_handle. Please gate on the v2 submodules in init.

Good catch. I’ll validate and import both mori.cco and mori.ops.dispatch_combine_v2 in MoriV2All2AllManager.init, so installations without the v2 API fail during manager construction. I’ll also add regression coverage for an older MoRI package missing these submodules.

@zufayu

zufayu commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

@TennyWang1223 Could you please take the primary communication review for the current head? This changes MORI v2 CCO management through the all-to-all manager, so the capability gate, handle lifetime, compatibility with the existing MORI path, and multi-GPU failure behavior need communication-owner sign-off. I will co-review the integration after your pass.

For reference, my preliminary co-review found two lifecycle risks:

  1. per_rank_vmm is validated locally but is not checked for agreement across ranks before ranks create the communicator with the same CCO UID. Please gather it through the participant group and require equality, or consistently select a common maximum.
  2. get_handle() can release the manager lock after obtaining the communicator, while destroy() can destroy it before the operation is created and added to _live_handles. Communicator lookup, operation creation, and live-handle registration need one lifecycle lock or an equivalent state/refcount mechanism.

The added tests are CPU/mock tests; the multi-GPU job is skipped. Please include real multi-rank initialization, partial-failure cleanup, concurrent destroy, and final cleanup coverage before approval.

@JiaoliangYu JiaoliangYu added the ci:multi-gpu Trigger multi-GPU op tests on PR label Oct 22, 2026
@JiaoliangYu

Copy link
Copy Markdown
Contributor Author

@zufayu Thanks for the lifecycle review. I revisited the requested safeguards against the actual caller and the CCO construction contract, and narrowed the implementation in 9c4f2b4.

I kept the EP-group per_rank_vmm agreement check because equal symmetric VMM capacity is a real CCO invariant. I also kept handle-before-communicator cleanup and terminal destroy semantics. A rank-0 UID error is carried in the UID broadcast itself, so it does not add another collective.

I removed the full get_handle/destroy lifecycle lock and the post-construction failure all-gathers. The manager now explicitly requires collective lifecycle calls to be issued in the same order from one control thread per rank; current callers do not create handles concurrently with teardown. More importantly, adding a status all-gather to every get_handle call makes cache hits collective, while still being unable to recover a peer that is already blocked inside collective CCO/window construction. That would add a new synchronization requirement without providing reliable partial-failure recovery.

The tests were reduced to match this contract: capacity disagreement, communicator creation/reuse, ordered final cleanup, and terminal destroy. The focused manager suite passes (18 tests), and Black/Ruff checks pass. Could you please take another look at the narrowed version?

@TennyWang1223

Copy link
Copy Markdown
Contributor

Thanks for narrowing the lifecycle contract — I agree with not making get_handle cache hits collective. A few remaining issues against that same contract:

  1. destroy() iterates a WeakSet (all2all.py:352). EpDispatchCombineOp.close() → window_deregister, which is collective, and WeakSet order is address-hash dependent, so with ≥2 handles ranks can deregister in different orders and hang. Please track handles in creation order and close in reverse.
  2. Handles are only weakly held (Cache is a WeakValueDictionary) while their arena is strongly held by comm._resources. A dropped handle leaks its VMM until comm destroy, and per-rank GC timing can make one rank re-create (collective alloc/register) while another hits the cache → hang. Please hold v2 handles strongly in the manager; this also fixes (1).
  3. Borrowers (MegaMoE): comm.destroy() silently frees their windows via close_all_resources(). Please either add a borrower close hook run before comm destroy, or document that borrowers must be closed before CudaCommunicator.destroy().
  4. Post-creation capacity growth is checked rank-locally; please document that callers must pass the same max per_rank_vmm (including MegaMoE) on all ranks.
  5. The multi-GPU test never calls get_handle. Please add a case with ≥2 real handles + a small dispatch/combine + destroy(), and confirm the multi-GPU runner actually has mori.cco installed so the test isn't silently skipped.

@JiaoliangYu

Copy link
Copy Markdown
Contributor Author

@TennyWang1223 Addressed items 1 and 2 in d083f5b.

MORI v2 now keeps every created handle in a manager-owned strong-reference list in creation order. The existing Cache remains responsible only for config/index lookup; a handle is appended to the ordered list only inside the cache-miss creation callback, after construction succeeds. This prevents rank-local GC from causing one rank to recreate collective CCO resources while another rank hits its cache.

During teardown, handles are closed in reverse creation order before the communicator is destroyed, so collective window deregistration follows the same LIFO order on every rank.

I added regression coverage that drops the caller reference and runs GC to verify the same handle remains cached, plus a two-handle teardown test that verifies handle 2 closes before handle 1 and both close before communicator destruction. The focused suite passes: 19 tests.

@TennyWang1223 TennyWang1223 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.

LGTM

@TennyWang1223
TennyWang1223 merged commit 9dc3ca0 into main Oct 27, 2026
63 checks passed
@TennyWang1223
TennyWang1223 deleted the codex/mori-v2-all2all-manager branch October 27, 2026 07:14
jhchouuu added a commit to jhchouuu/ATOM that referenced this pull request Oct 28, 2026
aiter's MoriV2All2AllManager (ROCm/aiter#6618) owns the EP group's cco
communicator and lends it through get_or_create_cco_communicator(). MegaMoE
now takes it from there instead of creating and caching one of its own:

- make_mori_v2_prepare_finalize hands the all2all manager to
  MoriV2PrepareAndFinalize, which passes it to init_mega_transport.
- The capacity is asked for in full before the communicator exists: the
  arena's required_vmm_bytes() plus the DevComm's granule.
- The communicator cannot grow, so it serves the first MegaMoE; a second,
  differently shaped one, or one on an aiter whose manager lends none, gets
  its own as before (with a warning in the first case).
- close_mega_transports() closes every MegaMoE; ModelRunner.exit calls it
  before destroy_dist_env(), so the arenas go before the manager destroys
  the communicator.

The recipe is built with aiter's nested ExpertComputeConfig, and the per-layer
recipe check and the creation log read it from recipe.compute.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
JiaoliangYu added a commit to ROCm/ATOM that referenced this pull request Oct 30, 2026
…/stage2 switches) (#2765)

* feat(moe): map mega stage1/stage2_fused to aiter, add decode combine quant

* feat(moe): build MegaMoE from an aiter MegaMoERecipe

On an aiter that has MegaMoERecipe (ROCm/aiter#6430), init_mega_transport
hands aiter a recipe instead of the stage flags: ATOM still picks the dispatch,
the combine and the wires from ATOM_MEGA_STAGE1_FUSED / ATOM_MEGA_STAGE2_FUSED /
MEGA_DISPATCH_WIRE / ATOM_MEGA_COMBINE_WIRE, the layer supplies the expert
GEMM, and whether the pairing can run is aiter's to say.

- The shared instance is keyed by (recipe, geometry).
- The communicator is sized by MegaMoEGfx1250.required_vmm_bytes(recipe,
  geometry) -- the arena exactly -- plus the granule the DevComm created right
  after takes.
- It is built with MegaMoEGfx1250.from_recipe, and the log and the per-layer
  recipe check read mega.recipe.
- Each step names its combine as a wire (combine_wire=bf16|fp8|fp4);
  combine_quant_for_step is now combine_wire_for_step.

An aiter without MegaMoERecipe keeps the flag path as it was. The Triton
experts path still drives MegaMoE's _dispatch/_combine, which aiter keeps.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* refactor(moe): MegaMoE borrows the EP all2all manager's cco communicator

aiter's MoriV2All2AllManager (ROCm/aiter#6618) owns the EP group's cco
communicator and lends it through get_or_create_cco_communicator(). MegaMoE
now takes it from there instead of creating and caching one of its own:

- make_mori_v2_prepare_finalize hands the all2all manager to
  MoriV2PrepareAndFinalize, which passes it to init_mega_transport.
- The capacity is asked for in full before the communicator exists: the
  arena's required_vmm_bytes() plus the DevComm's granule.
- The communicator cannot grow, so it serves the first MegaMoE; a second,
  differently shaped one, or one on an aiter whose manager lends none, gets
  its own as before (with a warning in the first case).
- close_mega_transports() closes every MegaMoE; ModelRunner.exit calls it
  before destroy_dist_env(), so the arenas go before the manager destroys
  the communicator.

The recipe is built with aiter's nested ExpertComputeConfig, and the per-layer
recipe check and the creation log read it from recipe.compute.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(moe): MegaMoE takes the MoRI v2 manager, closes cleanly; drop the v2 gather path

- ATOM_MORI_V2 asks for the "mori_v2" all2all manager before anything reads
  .all2all_manager, so MegaMoE borrows its cco communicator; an aiter without
  that manager keeps the default one.
- Communicators ATOM creates for MegaMoE itself are destroyed after the
  MegaMoE instances close; every close is attempted, and destroy_dist_env()
  runs even if one fails.
- Remove the unreachable v2 gather transport (init_mori_v2_op and its
  prepare/finalize); fix the stale weight-check message.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(moe): Triton experts branch passes _recv_bound only the arena rows

- MoriV2ModularKernel's triton_experts branch called _recv_bound with
  (topk_ids, arena_rows) and raised TypeError on its first forward.
- tests/model_ops/test_mori_v2_triton_experts.py drives that branch with
  MegaMoE and triton_mega_moe stand-ins, no GPU.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(moe): MegaMoE review follow-ups

- Layers share one MegaMoE by recipe and geometry; a layer with other Situv2 betas is refused
- The borrowed communicator is tracked explicitly; each DevComm closes before its communicator, in a documented order
- Ranks with different MegaMoE settings are refused at the first build
- Combine-wire support is left to aiter; recipe kinds compare as enum members
- The MegaMoE tests cover the recipe path and teardown, and run without aiter; the DeepSeek-V4 log example matches the new format

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(moe): MegaMoE communicators, settings check order, exit teardown

- Each MegaMoE that cannot borrow the manager's communicator gets its own
- The EP-rank settings check now includes the gate mode and runs before the recipe is built
- ModelRunner.exit releases the dist env, CUDA graphs, KV cache and model even when a MegaMoE close fails
- Tests cover the production communicator path, the check order and the exit teardown

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* refactor(moe): call the MoRI v2 all2all manager directly

- moe.py asks the EP device communicator for the "mori_v2" manager directly; mori_v2_all2all_manager is gone
- MegaMoE borrows the manager's cco communicator without probing for the method

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* refactor(moe): drop the pre-recipe aiter path

- MegaMoE is built from a recipe only; the stage-flag path and the per-token VMM fallback are gone
- The default bf16 combine wire is passed once
- The Situv2 betas check compares what ATOM built with

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

---------

Co-authored-by: yanboshao <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Co-authored-by: JiaoliangYu <[email protected]>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants