Skip to content

Add expert-parallel no-sync common helpers - #738

Merged
AkshitaB merged 10 commits into
akshitab/moe-v2-corefrom
akshitab/moe-v2-ep-common
Jun 30, 2026
Merged

AkshitaB merged 10 commits into
akshitab/moe-v2-corefrom
akshitab/moe-v2-ep-common

Conversation

@AkshitaB

Copy link
Copy Markdown
Contributor

Adds the shared helpers used by the no-sync expert-parallel forward paths.

What's added

nn/moe/v2/ep_no_sync_common.py:

  • build_keep_reorder — builds the per-expert capacity-drop reorder: stably partitions routed rows into kept-then-dropped, returning the permutation, its inverse, and a keep-mask.
  • sync_tail_drop_allowed_splits_single_a2a — agrees a global tail-drop policy across expert-parallel ranks with a single all-gather of per-rank requested token counts.
  • restore_drop_unpermute_1d — inverts the capacity drop (scatters kept expert outputs back, zero-filling dropped rows) and unpermutes + combines for the 1D no-sync path.

These operate on plain tensors / a passed-in block; the EP forward families that consume them land in follow-up changes.

Notes

  • The optional nvtx import uses the _nvtx fallback so the module imports without the profiling extra.
  • The dead env-gated debug helpers were trimmed to a single labeled hook + an OLMO_TBO_VERBOSE_DEBUG_PRINT note.

Testing

src/test/nn/moe/v2/ep_no_sync_common_test.py (CPU): validates build_keep_reorder against an independent reference (partial-drop, no-drop, full-drop-some-experts) and that the reorder/inverse permutations invert each other. make checks clean.

🤖 Generated with Claude Code

AkshitaB and others added 3 commits June 29, 2026 17:39
Capacity-drop reorder (build_keep_reorder), single-all-gather tail-drop split sync
(sync_tail_drop_allowed_splits_single_a2a), and dropped-token restore+unpermute
(restore_drop_unpermute_1d) shared by the no-sync expert-parallel forward paths.

Co-authored-by: Tianhua Tao <[email protected]>

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
- Guard the optional nvtx import with the _nvtx fallback so it imports without the
  profiling extra.
- Trim the dead env-gated debug helpers (_ep_sync_debug_* + their two commented call
  sites) to a single labeled hook plus a note on the OLMO_TBO_VERBOSE_DEBUG_PRINT switch,
  matching the comm.py cleanup. Drop the now-unused os import.
- Add docstrings to the public helpers (build_keep_reorder, restore_drop_unpermute_1d).

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Validate build_keep_reorder (the per-expert capacity-drop stable partition) against an
independent reference for partial-drop, no-drop, and full-drop-some-experts cases, and check the
reorder/inverse permutations invert each other.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
@AkshitaB
AkshitaB force-pushed the akshitab/moe-v2-ep-common branch from 4dba0ee to 3ebbed7 Compare June 30, 2026 00:39
@AkshitaB

Copy link
Copy Markdown
Contributor Author

@codex review

AkshitaB and others added 7 commits June 29, 2026 17:44
Match the merged v2 leaf convention: lowercase tuple[...] / X | Y instead of typing.Tuple /
Union (the file already has 'from __future__ import annotations'), and rename the
build_keep_reorder / restore_drop_unpermute_1d nvtx labels to match their function names (they had
a spurious leading underscore).

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Add nn/moe/v2/_nvtx.py with an annotate(label, subsystem) helper that centralizes the
optional-nvtx import (the _nvtx no-op fallback) and fixes the range color per subsystem
(routing=blue, experts=purple, comm=green, tbo=orange). Convert every nvtx range in the fused MoE
modules (router, shared/routed experts, model, no_ep, fp8, ep_no_sync_common) to use it, so call
sites pick a subsystem instead of a raw color and labels follow one scheme (qualified
ClassName.method / module_function names for whole callables, snake_case phases for inner blocks).
This also removes the duplicated try/except nvtx import from each module.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
@AkshitaB
AkshitaB merged commit 8721e95 into akshitab/moe-v2-core Jun 30, 2026
102 of 116 checks passed
@AkshitaB
AkshitaB deleted the akshitab/moe-v2-ep-common branch June 30, 2026 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant