Repository navigation
[moe] Overlap shared experts with the routed combine - #5937
MissingPompeii wants to merge 1 commit into
Conversation
Add an optional CombineReadyEvent publisher to EP token dispatchers and run shared experts on a side stream from the combine start. Default off; no input fork is needed because DenseFeedForward uses one w13 projection.
|
Hi @MissingPompeii! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
1 similar comment
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary (human-written)
Enable shared experts overlapped with routed experts' MoE combine.
Why
Shared experts execute after the routed combine returns. For EP dispatch the
combine is a communication phase; the shared-expert GEMMs have no dependency on
it, so the device sits idle for its duration.
Today (AllToAll/DeepEP, with shared experts):
With
combine_ready_event:There is no way for the MoE to start shared experts at the routed-compute /
combine boundary. This adds that handoff as an optional dispatcher publisher.
What changed
torchtitan/models/common/moe/token_dispatcher.py:CombineReadyEvent(record/take of one
torch.Event), optionalBaseEPTokenDispatcher.Config.combine_ready_event: CombineReadyEvent.Config | None = None, and recording at the start ofcombineinAllToAllTokenDispatcher,TorchAOTokenDispatcher(EP=1 path),DeepEPTokenDispatcher, andHybridEPTokenDispatcher.LocalTokenDispatcherdoes not publish.
torchtitan/models/common/moe/moe.py:MoEkeeps the publisher, runs sharedexperts on a device side stream after the routed experts, and waits before
adding. The default path (no publisher) is unchanged. There is no
_forward_splitor input fork:DenseFeedForwarduses onew13projection,so there is no gate/up gradient join to move.
MoE.Configrejects a publisher withoutshared_experts;DeepEPTokenDispatcher.Configrejectscombine_ready_eventtogether withcuda_graph_compatible=True.torchtitan/models/common/moe/README.md: usage, timing diagram, eager/graphlimitations, and the
TokenDispatcherTransformcaveat.tests/unit_tests/cpu/distributed/test_expert_parallel.py: opt-in wiring andthe DeepEP graph conflict.
Alternatives considered
begin/takemethods: semanticallycloser to the MoE, but splits the protocol in two and adds per-forward state.
enable_shared_overlapboolean: upstream config rules require optionalcomponents as
X.Config | Noneand no newenable_*booleans.User-facing changes
combine_ready_event=CombineReadyEvent.Config()runs them on a side stream from combine startcombine_ready_eventfield, defaultNone; no behavior changeTesting
Run here:
ast.parseon the three touched Python files,git diff --check,added-line ASCII and 120-column checks.
Not run here:
pytest,pre-commit,pyrefly(no torch/toolchain). New CPUtest, when run:
pytest tests/unit_tests/cpu/distributed/test_expert_parallel.pycovers the opt-in wiring and the
cuda_graph_compatibleconflict.GPU validation still needed: AllToAll/DeepEP/HybridEP paths, compile and graph
trainer, batch-invariant, activation remat, PP and multiple microbatches.
Known issues / follow-ups
CombineReadyEvent.recordraises undertorch.compileand non-strict tracing. Strict
torch.exportand accelerator graph capture arenot covered; recipes must keep the option off.
relies on
wait_event/wait_stream, but layers and microbatches serializetheir shared-expert work.
TokenDispatcherTransformrebuilds the dispatcher config from structuralfields; pass
combine_ready_eventthrough itskwargs.