Skip to content

[EP] add initial support for NVSHMEM-based all-to-all #1569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tianyu-l
Copy link
Contributor

As titled. This PR also does some refactoring around grouped_mm calling, as NVSHMEM-based all-to-all takes num_tokens_per_expert and prepares offsets.

What works

  • when num_local_experts == 1

What doesn't work and needs debugging

  • when num_local_experts > 1

other TODOs

  • let multiple MoE layers share the same input / output buffer
  • add NVSHMEM-based ExpertTensorParallel support (currently only supports ETP=1)

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 14, 2025
Comment on lines +92 to +93
# TODO: why do we need this clone?
return out.clone()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try removing this clone after we added out_buffer.detach() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still erroring out if removing this clone

RuntimeError: Output 0 of AllToAllVDev2dBackward is a view and its base or another view of its base has been modified inplace. This view was created inside a custom Function (or because an input was returned as-is) and the autograd logic to handle view+inplace would override the custom backward associated with the custom Function, leading to incorrect gradients. This behavior is forbidden. You can fix this by cloning the output of the custom Function.

self.output_splits = None

# performing all-to-all dispatch on the input
def _token_dispatch(self, mod, inputs, device_mesh):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this new implementation will get rid of the need of torch._dynamo.config.capture_scalar_outputs, avoiding the need to handle unbacked symints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants