Repository navigation
Fix all_to_all_single lowering for uneven split sizes (#1033) - #1035
Open
darthvader58 wants to merge 2 commits into
Open
darthvader58 wants to merge 2 commits into
darthvader58 wants to merge 2 commits into
Conversation
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
Fix the lowering of
all_to_all_singlewith uneven split sizes. The new lowering pads each chunk of the input to the input row count, exchanges the chunks with one evenstablehlo.all_to_all, and trims each received chunk. An AI assistant (Claude Code) helped to write this change. I reviewed the change.Related Issue
Fixes #1033
Motivation and Context
The old lowering used an
all_gatherand slices. It had three problems:[tokens, hidden], did not compile.rfrom the start of the block of each sender. The rows for rankrstart after the rows for the ranks belowr. Thus, ranks other than rank 0 received incorrect rows.input_split_sizesand operand 2 asoutput_split_sizes. The schema has the opposite order.A rank cannot calculate the correct offsets from the old layout. The offsets need the split sizes of the other ranks, and these are not known at compile time. In the new lowering, the sender uses only its
input_split_sizes, and the receiver uses only itsoutput_split_sizes. All types keep the rank of the input. All ranks must have the same input row count, as with the old lowering.This all-to-all is the token dispatch of expert-parallel MoE models in transformers (
ep_dispatch_experts). The issue listsQwen/Qwen3.6-35B-A3Bat EP=8 andQwen/Qwen3-Coder-Nextat EP=16. Even splits do not change. They still lower to onestablehlo.all_to_all.Type of Change
Testing
I updated
all-to-all-nonuniform.mlir. It covers a 2-D input with a send matrix that is not symmetric ([[1, 3], [2, 2]], rank 1), a 1-D input, and a chunk with zero rows. Before the fix, the test failed withoperand and result must have the same rank.I built in an arm64 Linux container.
WORKSPACEconfigures LLVM for X86 and NVPTX only, so I addedAArch64to the LLVM targets in a copy of the tree. This change does not affect the conversion pass.I also ran the pass output for both ranks in the StableHLO interpreter with
interpreter.run_parallelandprograms = [[@rank0, @rank1]]. Rowkof rankiholds10 * i + k, and the input shape is[4, 8]. Before the fix, the 1-D case of the issue gave[0, 1, 2, 10]on rank 1. After the fix, the 2-D case[[1, 3], [2, 2]]gives the correct rows on both ranks:[0, 10, 11]and[1, 2, 3, 12, 13].Ran locally (no Neuron hardware needed):
Ran on Neuron hardware:
Requesting Review :
@mgray07 @apoorvtintin
Checklist