[PyTorch] Fuse eager EP prepare and dispatch into a single op - #3380
Draft
phu0ngng wants to merge 1 commit into
Draft
[PyTorch] Fuse eager EP prepare and dispatch into a single op#3380phu0ngng wants to merge 1 commit into
phu0ngng wants to merge 1 commit into
Conversation
Contributor
Greptile SummaryThe PR fuses eager expert-parallel prepare and dispatch so the receive count can be written to pinned host memory and used to allocate outputs without a separate device-to-host copy.
Confidence Score: 4/5The PR is not yet safe to merge because eager EP dispatch still breaks or is rejected by torch.compile full-graph compilation. Eager dispatch unconditionally invokes a plain pybind function without a torch.library or fake registration, so the previously reported compilation failure remains reachable. Files Needing Attention: transformer_engine/pytorch/ep.py and transformer_engine/pytorch/csrc/extensions/ep.cpp Important Files Changed
Sequence DiagramsequenceDiagram
participant Python as ep_dispatch
participant Autograd as _EpPrepareAndDispatchEager
participant Binding as pybind extension
participant CUDA as EP backend
Python->>Autograd: apply(tokens, routing, pinned count)
Autograd->>Binding: ep_prepare_and_dispatch_eager(...)
Binding->>CUDA: prepare routing and write receive count
CUDA-->>Binding: pinned-host receive count
Binding->>Binding: synchronize and allocate outputs
Binding->>CUDA: dispatch tokens
CUDA-->>Python: receive tensors and expert counts
Reviews (2): Last reviewed commit: "[PyTorch] Fuse eager EP prepare and disp..." | Re-trigger Greptile |
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
phu0ngng
marked this pull request as draft
August 13, 2026 21:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This allows us to pin-host the recv_total_tokens, which saves the cost of D2H sync.
TODO: Do so for non-Eagermode as well.
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: