Repository navigation
[Collective] Prevent AllReduceOptions class mutation and fix rank validation precedence - #68621
themanoj-025 wants to merge 1 commit into
Conversation
…idation precedence Signed-off-by: Manoj Jana <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request fixes several bugs in Ray's collective utility. It corrects logical errors in rank validation within create_collective_group, ensures options classes like AllReduceOptions are properly instantiated rather than mutated at the class level, adds type annotations to convert dataclass class attributes into fields, and introduces corresponding unit tests. The review feedback correctly notes that because ranks is already validated as a permutation, the non-negative check is redundant, and the rank limit check can be simplified to an O(1) length check.
| if not all(r >= 0 for r in ranks): | ||
| raise RuntimeError("Ranks must be non-negative.") | ||
| if not all(ranks) < world_size: | ||
| if not all(r < world_size for r in ranks): | ||
| raise RuntimeError("Ranks cannot be greater than world_size.") |
There was a problem hiding this comment.
Since ranks is already validated to be a permutation of range(len(ranks)) on line 220, all elements in ranks are guaranteed to be non-negative. Therefore, the check if not all(r >= 0 for r in ranks): is redundant and will never be triggered.\n\nFurthermore, because of the same permutation guarantee, the maximum rank in ranks is len(ranks) - 1. Thus, checking if any rank is greater than or equal to world_size is equivalent to checking if len(ranks) > world_size. This can be simplified to an
if len(ranks) > world_size:\n raise RuntimeError("Ranks cannot be greater than world_size.")
Description
This PR fixes two bugs in
ay.util.collective:
ot. For example with
anks = [0, 1]\ and \world_size = 1, \�ll([0, 1]) == 0, \