Guard empty sharding group in findCommonSharding - #1473
Open
EylonKrause wants to merge 1 commit into
Open
Conversation
ShardingGroupMap sizes shardingGroupToValues by group-id value, so a non-contiguous sharding_group id leaves empty gap slots. syncGroupMemberShardings enumerates every slot and calls findCommonSharding on the empty ones, which only special-cases the size-1 case and falls through to groupMembers.front() -- UB on an empty ValueRange. group_id is an unconstrained I64Attr, so a group starting at id 1 is valid input to the standalone propagation passes (the full pipeline canonicalizes ids via ShardingGroupImportPass first, but the passes are registered and tested independently). Return an empty result for an empty group; the caller already skips groups with no common sharding.
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
Running a propagation pass standalone on a module with a non-contiguous
sdy.sharding_groupid crashes —findCommonShardingcallsgroupMembers.front()on an emptyValueRange. For example,sdy_opt -sdy-basic-propagateon a group whose id starts at 1 (no group 0):Root cause
ShardingGroupMapsizes itsshardingGroupToValuesvector by group-id value (resize(max(getGroupId() + 1, size))), so a non-contiguous id leaves empty gap slots.syncGroupMemberShardingsthen enumerates every slot — including the gaps — and callsfindCommonSharding(groupId, {}).findCommonShardingonly special-cases the size-1 case, so an empty range falls through togroupMembers.front(), which is undefined behavior.group_idis a plainI64Attrwith no verifier constraining it to a contiguous0..Nrange, so a group starting at id 1 is valid input. The full-sdy-propagation-pipelinecanonicalizes ids viaShardingGroupImportPassfirst, but the propagation passes are independently registered and run directly onsharding_groupops (as in the propagation tests).Fix
Return an empty result for an empty group; the caller already skips groups with no common sharding (
if (!sharding) continue;).Test
non_contiguous_sharding_group_idinsharding_group_propagation.mlir: a group with id 1 and no id 0 now propagates without crashing.Disclosure: this contribution was authored with an AI coding assistant (Claude) and reviewed before submission.