reshard: fix reverse-iterator direction in getGatheringAxes - #1453
Open
EylonKrause wants to merge 1 commit into
Open
reshard: fix reverse-iterator direction in getGatheringAxes#1453EylonKrause wants to merge 1 commit into
EylonKrause wants to merge 1 commit into
Conversation
The suffix scan in CollectiveInserter::getGatheringAxes started at inAxes.rbegin() and decremented the reverse_iterator (--axisRevIt), which moves toward the back (off the end) instead of toward the front. The loop therefore stopped after a single step and getGatheringAxes over-gathered the entire dimension -- including axes still present in the output sharding -- instead of only the trailing axes absent from the output, leaving currentAxes/inAxisSet inconsistent. Advance with ++axisRevIt, matching the sibling reverse scan in getAllToAllInfo and popBackFromCurrentAxes.
Author
|
Disclosure: this contribution was authored with an AI coding assistant (Claude) and reviewed before submission. |
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.
Problem
CollectiveInserter::getGatheringAxes(shardy/dialect/sdy/transforms/export/reshard_to_collectives.cc) over-gathers a dimension during reshard lowering: it can return the entire axis list (including axes still present in the output sharding) instead of only the trailing axes absent from the output.Root cause
The suffix scan starts at
inAxes.rbegin()and does--axisRevIt, which advances thestd::listreverse_iterator toward the back (off the end) rather than toward the front:For the function's own documented example (
inAxesPerDim = [[], ["x","y","z","w"]],outAxesPerDim = [["y"], []], expected["z","w"]),--stops after one step andaxisRevIt.base()lands at the front, so the tail loop gathers["x","y","z","w"]— wrongly gathering"y", which the output still needs — and leavescurrentAxes/inAxisSetinconsistent.The sibling reverse scan in
getAllToAllInfo(line ~1134) andpopBackFromCurrentAxes(line 118) both use++.Fix
Advance with
++axisRevIt.Verification
Static reasoning + consistency with the sibling scans; reproduces the documented example. No bazel build available on my machine — happy to add a lit test for a reshard that lowers to an all-gather.