Repository navigation
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/178350
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 10b19ae with merge base 9bd2eff ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
**Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation [ghstack-poisoned]
|
@claude review this pr |
|
Claude finished @anshul-si's task in 1m 40s —— View job PR Review: fixing index single_dim_strategies for contiguous indices
SummaryThis PR fixes an incorrect values-dim-to-self-dim mapping in The core insight is correct: PyTorch's advanced indexing has two different behaviors for where the broadcast shape appears in the output:
The old code always assumed the non-contiguous layout, which broke when Correctness VerificationI traced through the key scenarios to verify the new mapping logic: Example 1:
Example 2:
Example 3:
All cases check out. Code ReviewImplementation ( The logic at lines 1138-1154 is sound. A few observations:
Tests (
Potential Concerns
VerdictThe fix is correct, well-motivated, and the test coverage targets the exact failure mode described in the PR. The code is clean and the comments explain the contiguous vs. non-contiguous distinction well. No blocking issues. |
**Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation [ghstack-poisoned]
**Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation [ghstack-poisoned]
wconstab
left a comment
There was a problem hiding this comment.
first i want to understand the testing gap. how was the old index_put strategy landed without catching this? Is it because it didn't go through strategy_validation / opinfo testing, or becuase those tests didn't have sufficient test vectors?
Then, when did we start using decomps for index_add? What testing happened at the time this path was enabled?
| The exception is broadcasted value dimensions (size 1) - we require Replicate, but can shard self. | ||
| - Additionally, we allow the full Partial rule on non-indexing tensors. | ||
|
|
||
| TODO(pianpwk): support non-contiguous indexed dims (None gaps in indices tuple, |
There was a problem hiding this comment.
uh, is this TODO related, is it fixed now?
There was a problem hiding this comment.
This TODO is unrelated, my fix has to do with problems in contiguous indexed dims, where None is in front of broadcasted dims.
| # values shape = (*non_indexed_before, *broadcast_shape, *non_indexed_after) | ||
| # Non-contiguous (e.g., (idx0, None, idx1)): broadcast goes to front. | ||
| # values shape = (*broadcast_shape, *non_indexed_dim_sizes) | ||
| indexed_dims_sorted = sorted(indexed_dims) |
There was a problem hiding this comment.
i was confused why we need to sort indexed_dims. i think it's just because it's a set, and we want it in the order we built it in as if it were a list
index_put has different OpInfo than index_add, so strategy validation passes on it. OpInfo for index_put always uses index = 0, whereas index_add has atleast one example where index = 1, exposing this issue |
… indices" **Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation [ghstack-poisoned]
… indices" **Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation [ghstack-poisoned]
|
@pytorchbot merge |
… indices" **Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation [ghstack-poisoned]
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…178456) **Summary:** Added strategy for index_reduce which has no decompositions. index_fill does have a decomposition that fails because part of its decomposition includes scalar_tensor, a factory function. See #171652 for a deeper explanation on why these fail. **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_fill 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_reduce Pull Request resolved: #178456 Approved by: https://github.com/wconstab ghstack dependencies: #178350
The strategy computation for aten.index_put had two remaining issues blocking models like Falcon-7b that use list indexing (e.g. tensor[..., [-1], :]): 1. aten.index_put_.default (in-place variant, generated by autograd in the backward of aten.index.Tensor) was not registered in the single-dim strategy system. 2. _get_num_tensor_inputs counted None children in TupleStrategy, but args_strategy drops them, causing a count mismatch for ops with List[Optional[Tensor]] arguments. The values-dim-to-self-dim mapping fix for consecutive indexed dims was already landed in #178350; this commit adds the missing op registration, the infra bug fix, updated docstrings, and additional test coverage for None indices, in-place index_put_, non-contiguous indexed dims, and mid-tensor indexing. Authored with Claude. Fixes meta-pytorch/autoparallel#348 <!-- ps-id: 3fc0ba49-8b82-4c1d-b532-2ba111099dc3 -->
…ytorch#178350) **Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation Pull Request resolved: pytorch#178350 Approved by: https://github.com/wconstab
…dices (pytorch#178350)" This reverts commit 684f506. Reverted pytorch#178350 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#178350 (comment)))
…ytorch#178350) **Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation Pull Request resolved: pytorch#178350 Approved by: https://github.com/wconstab
…ytorch#178456) **Summary:** Added strategy for index_reduce which has no decompositions. index_fill does have a decomposition that fails because part of its decomposition includes scalar_tensor, a factory function. See pytorch#171652 for a deeper explanation on why these fail. **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_fill 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_reduce Pull Request resolved: pytorch#178456 Approved by: https://github.com/wconstab ghstack dependencies: pytorch#178350
The strategy computation for aten.index_put had two remaining issues blocking models like Falcon-7b that use list indexing (e.g. tensor[..., [-1], :]): 1. aten.index_put_.default (in-place variant, generated by autograd in the backward of aten.index.Tensor) was not registered in the single-dim strategy system. 2. _get_num_tensor_inputs counted None children in TupleStrategy, but args_strategy drops them, causing a count mismatch for ops with List[Optional[Tensor]] arguments. The values-dim-to-self-dim mapping fix for consecutive indexed dims was already landed in #178350; this commit adds the missing op registration, the infra bug fix, updated docstrings, and additional test coverage for None indices, in-place index_put_, non-contiguous indexed dims, and mid-tensor indexing. Authored with Claude. Fixes meta-pytorch/autoparallel#348 <!-- ps-id: 3fc0ba49-8b82-4c1d-b532-2ba111099dc3 -->
The strategy computation for aten.index_put had two remaining issues blocking models like Falcon-7b that use list indexing (e.g. tensor[..., [-1], :]): 1. aten.index_put_.default (in-place variant, generated by autograd in the backward of aten.index.Tensor) was not registered in the single-dim strategy system. 2. _get_num_tensor_inputs counted None children in TupleStrategy, but args_strategy drops them, causing a count mismatch for ops with List[Optional[Tensor]] arguments. The values-dim-to-self-dim mapping fix for consecutive indexed dims was already landed in #178350; this commit adds the missing op registration, the infra bug fix, updated docstrings, and additional test coverage for None indices, in-place index_put_, non-contiguous indexed dims, and mid-tensor indexing. Authored with Claude. Fixes meta-pytorch/autoparallel#348 Pull Request resolved: #179217 Approved by: https://github.com/pianpwk
…ytorch#178350) **Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation Pull Request resolved: pytorch#178350 Approved by: https://github.com/wconstab
…dices (pytorch#178350)" This reverts commit 684f506. Reverted pytorch#178350 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#178350 (comment)))
…ytorch#178350) **Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation Pull Request resolved: pytorch#178350 Approved by: https://github.com/wconstab
…dices (pytorch#178350)" This reverts commit 684f506. Reverted pytorch#178350 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#178350 (comment)))
…ytorch#178350) **Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation Pull Request resolved: pytorch#178350 Approved by: https://github.com/wconstab
…dices (pytorch#178350)" This reverts commit 684f506. Reverted pytorch#178350 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#178350 (comment)))
…ytorch#178350) **Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation Pull Request resolved: pytorch#178350 Approved by: https://github.com/wconstab
…ytorch#178456) **Summary:** Added strategy for index_reduce which has no decompositions. index_fill does have a decomposition that fails because part of its decomposition includes scalar_tensor, a factory function. See pytorch#171652 for a deeper explanation on why these fail. **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_fill 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_reduce Pull Request resolved: pytorch#178456 Approved by: https://github.com/wconstab ghstack dependencies: pytorch#178350
…79217) The strategy computation for aten.index_put had two remaining issues blocking models like Falcon-7b that use list indexing (e.g. tensor[..., [-1], :]): 1. aten.index_put_.default (in-place variant, generated by autograd in the backward of aten.index.Tensor) was not registered in the single-dim strategy system. 2. _get_num_tensor_inputs counted None children in TupleStrategy, but args_strategy drops them, causing a count mismatch for ops with List[Optional[Tensor]] arguments. The values-dim-to-self-dim mapping fix for consecutive indexed dims was already landed in pytorch#178350; this commit adds the missing op registration, the infra bug fix, updated docstrings, and additional test coverage for None indices, in-place index_put_, non-contiguous indexed dims, and mid-tensor indexing. Authored with Claude. Fixes meta-pytorch/autoparallel#348 Pull Request resolved: pytorch#179217 Approved by: https://github.com/pianpwk
…ytorch#178350) **Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation Pull Request resolved: pytorch#178350 Approved by: https://github.com/wconstab
…dices (pytorch#178350)" This reverts commit 684f506. Reverted pytorch#178350 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#178350 (comment)))
…ytorch#178350) **Summary:** When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly. <img width="972" height="269" alt="image" src="https://github.com/user-attachments/assets/1a57679a-9d7d-4f0a-8eea-b731ab18f410" /> Example of How Current Code is Wrong **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_ops_leading_none_dim_mapping 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_copy_partial_propagation 3. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_add_partial_propagation Pull Request resolved: pytorch#178350 Approved by: https://github.com/wconstab
…ytorch#178456) **Summary:** Added strategy for index_reduce which has no decompositions. index_fill does have a decomposition that fails because part of its decomposition includes scalar_tensor, a factory function. See pytorch#171652 for a deeper explanation on why these fail. **Test Cases** 1. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_fill 2. pytest test/distributed/tensor/test_tensor_ops.py -k test_index_reduce Pull Request resolved: pytorch#178456 Approved by: https://github.com/wconstab ghstack dependencies: pytorch#178350
…79217) The strategy computation for aten.index_put had two remaining issues blocking models like Falcon-7b that use list indexing (e.g. tensor[..., [-1], :]): 1. aten.index_put_.default (in-place variant, generated by autograd in the backward of aten.index.Tensor) was not registered in the single-dim strategy system. 2. _get_num_tensor_inputs counted None children in TupleStrategy, but args_strategy drops them, causing a count mismatch for ops with List[Optional[Tensor]] arguments. The values-dim-to-self-dim mapping fix for consecutive indexed dims was already landed in pytorch#178350; this commit adds the missing op registration, the infra bug fix, updated docstrings, and additional test coverage for None indices, in-place index_put_, non-contiguous indexed dims, and mid-tensor indexing. Authored with Claude. Fixes meta-pytorch/autoparallel#348 Pull Request resolved: pytorch#179217 Approved by: https://github.com/pianpwk
Summary: When running strategy_validator on aten.index_add and aten.index_copy, it found incorrect rules produced by their decomposition to aten.index_put. The old index_put strategy assumes the broadcast shape always occupies the leading dimensions of values, which is only true when indexed dims are non-contiguous. When indexed dims are contiguous (as they always are for index_add/index_copy, which index a single dim), PyTorch replaces them in-place, so values layout is (*non_indexed_before, *broadcast, *non_indexed_after). The old code skips the first broadcast_ndim dims of values, misidentifying the actual non-indexed dims as broadcast and vice versa, which produces strategies that allow sharding the broadcast dim of values (e.g. S(0), R, S(1) -> S(0)). At runtime this causes a shape mismatch since each rank holds a slice of index selections rather than a slice of data. The fix checks whether indexed dims are contiguous and computes the correct values-dim-to-self-dim mapping accordingly.
Test Cases
Stack from ghstack (oldest at bottom):