Refactor moe.p: gmm and a2a unsort#4170
Open
Shuwen-Fang wants to merge 1 commit into
Open
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
NuojCheng
reviewed
Jun 16, 2026
| num_ep = self.get_expert_parallelism_size() | ||
| num_experts_per_shard = self.config.num_experts // num_ep | ||
| use_truncated_buffer = self.config.use_ring_of_experts and x.shape[0] < routing.sorted_selected_experts.shape[0] | ||
| if use_truncated_buffer: |
Collaborator
There was a problem hiding this comment.
maybe we can merge line 1647 and 1648?
NuojCheng
reviewed
Jun 16, 2026
| group_offset=experts_start, | ||
| ) | ||
|
|
||
| def unsort_output_with_ra2a(intermediate_output, routing, route_metadata, output_shape, is_batch_sharded_by_expert): |
Collaborator
There was a problem hiding this comment.
This function includes both unsort and ra2a.. Maybe we should name it unsort_output_and_ra2a?
NuojCheng
reviewed
Jun 16, 2026
| output_offsets, | ||
| recv_sizes, | ||
| axis_name=self._expert_parallelism_name, | ||
| ) |
Collaborator
There was a problem hiding this comment.
emmm why ragged_all_to_all show up twice, one in a function and one outside the function?
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 is the second PR refactoring sparse_matmul to make chunking activations and future features easier to implement.
Major changes:
get_gmm_for_local_expertsTests
Verified loss and perplexity is identical on main vs refactor branch after 20 train steps: loss: 12.259, perplexity: 210794.859 for both.
commands to reproduce:
Full table of correctness test results:
| Mode | Ring of Experts | EP Size | FSDP Size | Loss (
main) | Loss (refactor) | Perp (main) | Perp (refactor) | Tok/s/Dev(
main) | Tok/s/Dev (refactor) | Command Differences ||---|---|---|---|---|---|---|---|---|---|---|
| Sparse | True | 8 | 1 | 12.259 | 12.259 | 210794.859 | 210794.859 | 134,312 | 135,845 |
sparse_matmul=True use_ring_of_experts=True ici_expert_parallelism=-1|| Sparse | False | 8 | 1 | 12.259 | 12.259 | 210800.438 | 210800.438 | 165,695 | 166,883 |
sparse_matmul=True use_ring_of_experts=False ici_expert_parallelism=-1|| Sparse | False | 1 | 8 | 12.259 | 12.259 | 210867.609 | 210867.609 | 166,802 | 179,712 |
sparse_matmul=True use_ring_of_experts=False ici_expert_parallelism=1 ici_fsdp_parallelism=-1|| Dense | False | 1 | 8 | 12.259 | 12.259 | 210843.078 | 210843.078 | 178,025 | 161,234 |
sparse_matmul=False use_ring_of_experts=False ici_expert_parallelism=1 ici_fsdp_parallelism=-1|| Dense | False | 8 | 1 | 12.259 | 12.259 | 210809.906 | 210809.906 | 177,469 | 164,076 |
sparse_matmul=False use_ring_of_experts=False ici_expert_parallelism=-1 ici_fsdp_parallelism=1|Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.