Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions megatron/core/transformer/moe/token_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ def set_shared_experts(self, shared_experts):
self.cudagraph_attrs.append('shared_experts.gate_score')
self.cudagraph_attrs.append('shared_experts.cached_fc1_input')

def _local_expert_chunk_sort_is_identity(self) -> bool:
"""Return true when permutation 2 would only copy already grouped local chunks."""
return self.tp_size == 1 and self.ep_size == 1
Comment on lines +493 to +495

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 PR description is empty / still the default template

The PR was submitted with the original template content and no author-written description. There is no "What does this PR do?" summary, no linked issue, and all pre-check boxes remain unchecked. Please fill in at minimum a one-line overview of the motivation and confirm the pre-checks.

Context Used: Only comment if the PR description is unchanged fr... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


def preprocess(self, routing_map: torch.Tensor) -> torch.Tensor:
"""
Preprocesses the token routing map for All-to-All communication and token permutation.
Expand Down Expand Up @@ -745,7 +749,7 @@ def dispatch_postprocess(self, global_input_tokens, global_probs):
self.tokens_per_expert = self._maybe_dtoh_and_synchronize(
"before_permutation_2", self.tokens_per_expert
)
if self.num_local_experts > 1:
if self.num_local_experts > 1 and not self._local_expert_chunk_sort_is_identity():
if self.drop_and_pad:
global_input_tokens = (
global_input_tokens.view(
Expand Down Expand Up @@ -791,7 +795,7 @@ def combine_preprocess(self, hidden_states):
parallel dimension.
"""
# Unpermutation 2: Unsort tokens by local expert.
if self.num_local_experts > 1:
if self.num_local_experts > 1 and not self._local_expert_chunk_sort_is_identity():
if self.drop_and_pad:
hidden_states = (
hidden_states.view(
Expand Down
Loading