[PyTorch] Reduce CPU overhead on eager EP dispatch and combine - #3380
Open
phu0ngng wants to merge 7 commits into
Open
[PyTorch] Reduce CPU overhead on eager EP dispatch and combine#3380phu0ngng wants to merge 7 commits into
phu0ngng wants to merge 7 commits into
Conversation
Contributor
Greptile SummaryThe PR reduces eager expert-parallel CPU overhead by fusing prepare and dispatch at the C++ boundary, shortening autograd operand lists, and bypassing
Confidence Score: 4/5The PR is not yet safe to merge because eager expert-parallel dispatch still breaks The eager path directly invokes Files Needing Attention: transformer_engine/pytorch/ep.py Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant EP as ep_dispatch
participant Autograd as _EpPrepareAndDispatch
participant Native as ep_prepare_and_dispatch
participant Backend as NCCL EP backend
Caller->>EP: tokens, routing, EpBuffer
EP->>EP: optionally quantize MXFP8
EP->>Autograd: apply(...)
alt eager mode
Autograd->>Native: direct pybind call
Native->>Backend: prepare routing
Native->>Native: synchronize and read recv count
Native->>Native: allocate recv outputs
Native->>Backend: dispatch
else fixed-capacity mode
Autograd->>Autograd: allocate/reuse static outputs
Autograd->>Native: torch.library custom op
Native->>Backend: prepare and dispatch
end
Autograd-->>Caller: recv tokens, weights, expert counts
Reviews (3): Last reviewed commit: "[PyTorch] Call the backend directly for ..." | Re-trigger Greptile |
phu0ngng
marked this pull request as draft
August 13, 2026 21:53
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
…thon overhead Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
…all CPU overhead Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
…hon overhead Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
… cut per-call CPU overhead Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
phu0ngng
marked this pull request as ready for review
August 21, 2026 15:42
Collaborator
Author
|
/te-ci L1 pytorch |
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
Lowers the per-call CPU cost of the eager NCCL EP dispatch and combine autograd paths. Numerics and public API are unchanged. Eager ops keep the CPU near the critical path (the dispatch forward must read the per-step recv count on the host before sizing recv), so Python and dispatch overhead was exposed rather than hidden behind async GPU work.
Type of change
Changes
_EpPrepareAndDispatchand_EpCombinetake only the differentiable tensors as direct operands. The non-differentiable buffer tensors ride on theEpBufferobject, andhandle_memis stashed as a plainctxattribute instead ofsave_for_backward.torch.library: eager is not graph-capturable, so combine forward, combine backward, and dispatch backward call the backend ops directly. Non-eager paths keep thetransformer_engine_ep::*custom ops unchanged.ep_get_zero_copy()onctxinstead of re-querying it in every combine backward.Checklist: