Skip to content

[PyTorch] Fuse eager EP prepare and dispatch into a single op - #3380

Draft
phu0ngng wants to merge 1 commit into
NVIDIA:mainfrom
phu0ngng:ep-pyt
Draft

[PyTorch] Fuse eager EP prepare and dispatch into a single op#3380
phu0ngng wants to merge 1 commit into
NVIDIA:mainfrom
phu0ngng:ep-pyt

Conversation

@phu0ngng

@phu0ngng phu0ngng commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

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

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Change A
  • Change B

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@phu0ngng
phu0ngng requested a review from ksivaman as a code owner August 13, 2026 18:26
@greptile-apps

greptile-apps Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

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

  • Adds a fused C++/pybind eager prepare-and-dispatch operation.
  • Routes eager BF16 and MXFP8 dispatch through a new autograd wrapper.
  • Moves eager receive-count storage to pinned host memory.
  • Adds MXFP8 eager dispatch backward coverage.

Confidence Score: 4/5

The 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

Filename Overview
transformer_engine/pytorch/ep.py Adds the fused eager autograd path, but its direct pybind forward call leaves the previously reported torch.compile incompatibility outstanding.
transformer_engine/pytorch/csrc/extensions/ep.cpp Implements and binds the fused pinned-host receive-count, allocation, and dispatch sequence.
transformer_engine/pytorch/csrc/extensions.h Declares the new fused eager dispatch binding consistently with its C++ implementation.
tests/pytorch/distributed/run_ep.py Adds eager MXFP8 forward/backward gradient coverage but does not exercise torch.compile.

Sequence Diagram

sequenceDiagram
  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
Loading

Reviews (2): Last reviewed commit: "[PyTorch] Fuse eager EP prepare and disp..." | Re-trigger Greptile

Comment thread transformer_engine/pytorch/ep.py
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
@phu0ngng
phu0ngng marked this pull request as draft August 13, 2026 21:53
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