Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/171652
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (4 Unrelated Failures)As of commit 5da2897 with merge base 2776680 ( FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| # immediately return; some op doesn't have a sharding strategy. | ||
| return None | ||
| except (ImplicitRedistributionError, RuntimeError): | ||
| # I feel like we shouldn't have to catch RuntimeErrors? |
There was a problem hiding this comment.
View ops will raise if they can't be performed locally - for example if you take a sharded tensor and reshape it, its possible the resulting global tensor shape does not match with the local data and the placement types we have defined. We could make this a more specific type of error. cc @weifengpy
| self.assertEqual(out.placements, (Partial("min"),)) | ||
|
|
||
| # # index_add | ||
| # # index_put decomp errors; https://github.com/pytorch/pytorch/issues/170934 |
There was a problem hiding this comment.
any reason this is commented?
There was a problem hiding this comment.
the underlying strategy is incorrect... I might just delete this test
| out = aten.polar.default(x, y) | ||
| self.assertEqual(out.placements, (Replicate(),)) | ||
|
|
||
| # # pixel_shuffle |
There was a problem hiding this comment.
the replicate behavior was unexpected (may also remove this)
|
this PR probably should have removed a handful of xfails from test_dtensor_ops.py - did you just not look into that yet? |
just updated, turns out make_fx has this global state which isn't thread-safe, and I had to add a lock on decomposition graph tracing to make it work: pytorch/torch/fx/_symbolic_trace.py Line 1167 in 5e37bf8 Now a lot of xfails are gone, but I'm not sure if there's a better decomp shard prop alternative. I probably should add caching on graph tracing before this can be landed, so we only trace once. |
| import torch.distributed as dist | ||
|
|
||
| world_size = dist.get_world_size() if dist.is_initialized() else 2 | ||
| self.mesh = DeviceMesh(mesh_device, torch.arange(world_size)) |
There was a problem hiding this comment.
@wconstab this part is still suspect to me, I had to do this to avoid the assertion in
do you have a concept of what the device mesh should be, if we're propagating through the decomp graph with single-dim strategies?
There was a problem hiding this comment.
wondering if you hit the same issue as i ran into here: #172478
still ruminating on what the best solution is
There was a problem hiding this comment.
to answer your question more literally though,
do you have a concept of what the device mesh should be, if we're propagating through the decomp graph with single-dim strategies?
I don't think we should need to know about the device mesh when we are evaluating the single-dim portion of the single-dim rule. However when we get into expansion, we do look at the mesh, and it should be the real mesh, not some single-dim fake mesh.
There was a problem hiding this comment.
Yep, exactly that error.
Expansion is definitely on the real mesh, I'm mainly worried that this fake mesh ends up filtering out valid strategies (because say, maybe the mesh dim size is too large)
There was a problem hiding this comment.
I'm not clear about what fake mesh exists and why its size is off. In the PR I linked there was a unit test doing something with a submesh where not all ranks participate, which in itself is a bit unusual. For normal cases for decomp tracing shouldn't we just be using the runtime mesh sizes?
There was a problem hiding this comment.
Ah sorry, patching #172478 actually helps a lot.
I guess because DecompShardingInterpreter is actually calling sharding prop, there needs to be a mesh attached, and at the same time, we're trying to enumerate on single-dim. There's a couple options that seem to work for me:
- reuse the real n-d mesh, but only search over placements on one of the mesh dims, setting the others as Replicate.
- create a fake 1d mesh with real world size
- create a fake 1d mesh with size 2 (or maybe even 1?), and patch redistribute cost to avoid failing on non-participating ranks
I was worried 1) & 2) could incorrectly filter out strategies that would be valid on the real n-d mesh (for 1 we inadvertently choose a mesh dim bad for even sharding (e.g. 5); for 2 maybe the world size is larger than tensor size, and we don't shard). Option 3) seemed like a way to avoid false negatives here.
There was a problem hiding this comment.
Ok, I think we've settled on ~3: create a fake 1d mesh with size 1, but avoid using the real PG, and have all processes act like rank 0: fake_mesh = DeviceMesh(mesh.device_type, [0], _init_backend=False, _rank=0)
Previously the 0-cost for non-participating ranks was working, but returning cost = 0 for all strategies on ranks >= 1. I'm not entirely sure why this was "working" - maybe the redistribute planner was only being invoked when we definitely needed redistribution, and while some of those discovered strategies were included with incorrect 0-cost, they weren't chosen anyways because we banned implicit redistributes.
…into pianpwk/dt_decomps_init
Previously CIA ops would decompose & go through DTensor dispatch individually, now they enter the decomp flow in #171652. This caused implicit redistributes in some CIA ops with decomps (e.g. aten::linear in inference), so partially reverting this to preserve old behavior. Now we skip decomp flow if CIA decomp is present. [ghstack-poisoned]
Previously CIA ops would decompose & go through DTensor dispatch individually, now they enter the decomp flow in #171652. This caused implicit redistributes in some CIA ops with decomps (e.g. aten::linear in inference), so partially reverting this to preserve old behavior. Now we skip decomp flow if CIA decomp is present. [ghstack-poisoned]
Previously CIA ops would decompose & go through DTensor dispatch individually, now they enter the decomp flow in #171652. This caused implicit redistributes in some CIA ops with decomps (e.g. aten::linear in inference), so partially reverting this to preserve old behavior. Now we skip decomp flow if CIA decomp is present. Pull Request resolved: #174918 Approved by: https://github.com/wconstab
Following @tianyu-l's pytorch#130887 Adds support for ops with no sharding prop strategy, but a registered decomposition. Now if sharding prop sees a decomposable op, it: 1. Runs the decomposed op under a custom TorchDispatchMode, which propagates the placements as side information (initially used a make_fx implementation, but this required a threading lock as it relies on [global state](https://github.com/pytorch/pytorch/blob/2a26c9a32661ee2b4b049e3bd1b889fc3af30880/torch/fx/_symbolic_trace.py#L1167)) 2. Enumerates potential input placement combinations based on the actual input placements, on a single-dim mesh, then for each of them, propagates through torch_dispatch via sharding prop, while banning any intermediate redistributions. 3. Returns the expanded full-mesh strategy from the filtered strategies. Some caveats: - Since the dispatch mode runs sharding prop, the shard prop cache should kick in, both in the normal case (running the same op twice), and also when we recursively decompose (if op1 -> op2 -> some decomp, running op1 caches for op2). - One common failure case is decompositions calling factory methods (e.g. [torch.ones, torch.arange](https://github.com/pytorch/pytorch/blob/41f42a0fc3ea1fbfdf05b4c030d7df815bdfe19d/torch/_decomp/decompositions.py#L818-L821)). The main problem seems to be assigning placements to these tensors, and it's not so obvious what their placements should be, especially when they might take in sharded sizes, and we can't completely detect when this is the case. For now, intermediate shard prop will fail (no sharding strategy; they don't take DTensor inputs), but a potential future improvement is to permit the full-Replicate case for these graphs. - Sharding prop is currently via a `propagate_op_sharding` call, on explicit placement types. Once [single-dim strategy](pytorch#167677) coverage is broader, this should be doable on _ShardPlaceholders instead, making the enumeration & propagation process cheaper, though maybe more manual. - (Maybe hackily) uses a fake 1-rank 1d mesh to do single-dim propagation Removes the following xfails (+some more aten ops with decomp coverage, but still failing tests): ``` __rsub__ addmv addr alias_copy all any count_nonzero dist expand_copy fill floor_divide index_select linalg.vecdot masked_fill mv nn.functional.celu nn.functional.channel_shuffle nn.functional.elu nn.functional.hardsigmoid nn.functional.hardswish nn.functional.hardtanh nn.functional.leaky_relu nn.functional.logsigmoid nn.functional.margin_ranking_loss nn.functional.mish nn.functional.multilabel_soft_margin_loss nn.functional.pairwise_distance nn.functional.pixel_shuffle nn.functional.pixel_unshuffle nn.functional.prelu nn.functional.relu6 nn.functional.selu nn.functional.softplus nn.functional.softshrink nn.functional.triplet_margin_loss nn.functional.triplet_margin_with_distance_loss permute_copy rsub t_copy trace vdot view_copy ``` Pull Request resolved: pytorch#171652 Approved by: https://github.com/wconstab
Following @tianyu-l's pytorch#130887 Adds support for ops with no sharding prop strategy, but a registered decomposition. Now if sharding prop sees a decomposable op, it: 1. Runs the decomposed op under a custom TorchDispatchMode, which propagates the placements as side information (initially used a make_fx implementation, but this required a threading lock as it relies on [global state](https://github.com/pytorch/pytorch/blob/2a26c9a32661ee2b4b049e3bd1b889fc3af30880/torch/fx/_symbolic_trace.py#L1167)) 2. Enumerates potential input placement combinations based on the actual input placements, on a single-dim mesh, then for each of them, propagates through torch_dispatch via sharding prop, while banning any intermediate redistributions. 3. Returns the expanded full-mesh strategy from the filtered strategies. Some caveats: - Since the dispatch mode runs sharding prop, the shard prop cache should kick in, both in the normal case (running the same op twice), and also when we recursively decompose (if op1 -> op2 -> some decomp, running op1 caches for op2). - One common failure case is decompositions calling factory methods (e.g. [torch.ones, torch.arange](https://github.com/pytorch/pytorch/blob/41f42a0fc3ea1fbfdf05b4c030d7df815bdfe19d/torch/_decomp/decompositions.py#L818-L821)). The main problem seems to be assigning placements to these tensors, and it's not so obvious what their placements should be, especially when they might take in sharded sizes, and we can't completely detect when this is the case. For now, intermediate shard prop will fail (no sharding strategy; they don't take DTensor inputs), but a potential future improvement is to permit the full-Replicate case for these graphs. - Sharding prop is currently via a `propagate_op_sharding` call, on explicit placement types. Once [single-dim strategy](pytorch#167677) coverage is broader, this should be doable on _ShardPlaceholders instead, making the enumeration & propagation process cheaper, though maybe more manual. - (Maybe hackily) uses a fake 1-rank 1d mesh to do single-dim propagation Removes the following xfails (+some more aten ops with decomp coverage, but still failing tests): ``` __rsub__ addmv addr alias_copy all any count_nonzero dist expand_copy fill floor_divide index_select linalg.vecdot masked_fill mv nn.functional.celu nn.functional.channel_shuffle nn.functional.elu nn.functional.hardsigmoid nn.functional.hardswish nn.functional.hardtanh nn.functional.leaky_relu nn.functional.logsigmoid nn.functional.margin_ranking_loss nn.functional.mish nn.functional.multilabel_soft_margin_loss nn.functional.pairwise_distance nn.functional.pixel_shuffle nn.functional.pixel_unshuffle nn.functional.prelu nn.functional.relu6 nn.functional.selu nn.functional.softplus nn.functional.softshrink nn.functional.triplet_margin_loss nn.functional.triplet_margin_with_distance_loss permute_copy rsub t_copy trace vdot view_copy ``` Pull Request resolved: pytorch#171652 Approved by: https://github.com/wconstab
…rategies" **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 [ghstack-poisoned]
… index_reduce strategies" **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 [ghstack-poisoned]
…rategies" **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 [ghstack-poisoned]
… index_reduce strategies" **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 [ghstack-poisoned]
…rategies" **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 [ghstack-poisoned]
… index_reduce strategies" **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 [ghstack-poisoned]
…rategies" **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 [ghstack-poisoned]
… index_reduce strategies" **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 [ghstack-poisoned]
…rategies" **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 [ghstack-poisoned]
… index_reduce strategies" **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 [ghstack-poisoned]
…rategies" **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 [ghstack-poisoned]
… index_reduce strategies" **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 [ghstack-poisoned]
…rategies" **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 [ghstack-poisoned]
…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
…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
…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
…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
Following @tianyu-l's #130887
Adds support for ops with no sharding prop strategy, but a registered decomposition.
Now if sharding prop sees a decomposable op, it:
Some caveats:
propagate_op_shardingcall, on explicit placement types. Once single-dim strategy coverage is broader, this should be doable on _ShardPlaceholders instead, making the enumeration & propagation process cheaper, though maybe more manual.Removes the following xfails (+some more aten ops with decomp coverage, but still failing tests):