Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/175194
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (3 Unrelated Failures)As of commit 8e65853 with merge base 704b8d3 ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
BROKEN TRUNK - The following job failed but was present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
[ghstack-poisoned]
[ghstack-poisoned]
| if output_sharding.needs_redistribute: # pyrefly: ignore [missing-attribute] | ||
| raise RuntimeError(f"Decomposition requires redistribution for {func}") | ||
| if ( | ||
| output_sharding.needs_redistribute # pyrefly: ignore [missing-attribute] |
There was a problem hiding this comment.
asked claude to explain the status-quo of view-ops needs_redistribute handling to me:
View ops don't set needs_redistribute directly. The flow is:
- Strategy creation (_view_ops.py): reshape_strategy calls propagate_shape_and_sharding to determine target input/output placements. If a shard can't be preserved through the view (e.g., Shard(1) through a
flatten), the target input placement becomes Replicate(). The resulting OpSpec records input_specs (desired placements) and redistribute_cost. - Strategy selection (_sharding_prop.py:600-686): ShardingPropagator picks the lowest-cost strategy, then compares each input's actual placements to the strategy's desired placements. If they differ,
needs_redistribute = True and a suggestion_schema (the redistribute_schema) is built. - Shape/stride adjustment: For view ops specifically, there's a second reason to set needs_redistribute = True — when the output is sharded, the shape/stride arguments (not the tensors) need adjustment to
reflect local sizes. This sets use_val_from_redistribute_schema = True so the dispatch layer reads non-tensor args from the schema too. - Dispatch (_dispatch.py:275-283): When needs_redistribute is True, redistribute_local_args redistributes tensors whose placements differ and optionally replaces shape/stride args.
| redistribute_schema | ||
| := output_sharding.redistribute_schema # pyrefly: ignore [missing-attribute] | ||
| ) | ||
| is not None |
There was a problem hiding this comment.
according to claude, redistribute_schema is non-none even for the view case, but it is a trivial schema that matches the inputs and incurs a no-op redistribute. is this a lie? should we instead be checking use_val_from_redistribute_schema here?
There was a problem hiding this comment.
no, I think that's correct, but we want to allow that path (no-op redistribute, use_val_from_redistribute_schema is True)
There was a problem hiding this comment.
My point was that schema!=None should be an invariant anyway so you learn nothing by checking it here. Instead you should be checking the other flag mentioned above?
There was a problem hiding this comment.
Oh, never mind. I guess your way works too- checking that the redistribute is a no-op.
My way is a shortcut- the other flag tells us this is the view special case and we can then assume redistribution is a no op. But actually I'm not sure if that flat implies only view- it could apply to reshape too for all I know? Anyway looks fine this way, stamping.
…osition flow" #174918 skipped the decomposition flow for CIA ops, because we found it wasn't able to find non-replicate strategies for aten::linear. This turned out to be view handling related; the decomposition flow bans internal redistributes, but the `.needs_redistribute` semantics is too broad; for views it includes when DTensor dispatch needs to convert from global -> local tensor ops: https://github.com/pytorch/pytorch/blob/c238e6ed935df371f208b72becb206858a0cf087/torch/distributed/tensor/_sharding_prop.py#L638-L653 For example, `DTensor(shape=[8, 8], placements=[Shard(0)]).view(8, 4, 2)` on a size-4 mesh, will recalculate and run `.view(2, 4, 2)` in local compute. The decomposition flow doesn't need this handling, as it always deals with global tensors. This PR changes redistribution semantics to only be placement based, and reverts the CIA skip, allowing CIA ops to go through the decomposition flow again. [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 |
#175194) #174918 skipped the decomposition flow for CIA ops, because we found it wasn't able to find non-replicate strategies for aten::linear. This turned out to be view handling related; the decomposition flow bans internal redistributes, but the `.needs_redistribute` semantics is too broad; for views it includes when DTensor dispatch needs to convert from global -> local tensor ops: https://github.com/pytorch/pytorch/blob/c238e6ed935df371f208b72becb206858a0cf087/torch/distributed/tensor/_sharding_prop.py#L638-L653 For example, `DTensor(shape=[8, 8], placements=[Shard(0)]).view(8, 4, 2)` on a size-4 mesh, will recalculate and run `.view(2, 4, 2)` in local compute. The decomposition flow doesn't need this handling, as it always deals with global tensors. This PR changes redistribution semantics to only be placement based, and reverts the CIA skip, allowing CIA ops to go through the decomposition flow again. Pull Request resolved: #175194 Approved by: https://github.com/wconstab
pytorch#175194) pytorch#174918 skipped the decomposition flow for CIA ops, because we found it wasn't able to find non-replicate strategies for aten::linear. This turned out to be view handling related; the decomposition flow bans internal redistributes, but the `.needs_redistribute` semantics is too broad; for views it includes when DTensor dispatch needs to convert from global -> local tensor ops: https://github.com/pytorch/pytorch/blob/c238e6ed935df371f208b72becb206858a0cf087/torch/distributed/tensor/_sharding_prop.py#L638-L653 For example, `DTensor(shape=[8, 8], placements=[Shard(0)]).view(8, 4, 2)` on a size-4 mesh, will recalculate and run `.view(2, 4, 2)` in local compute. The decomposition flow doesn't need this handling, as it always deals with global tensors. This PR changes redistribution semantics to only be placement based, and reverts the CIA skip, allowing CIA ops to go through the decomposition flow again. Pull Request resolved: pytorch#175194 Approved by: https://github.com/wconstab
Stack from ghstack (oldest at bottom):
#174918 skipped the decomposition flow for CIA ops, because we found it wasn't able to find non-replicate strategies for aten::linear. This turned out to be view handling related; the decomposition flow bans internal redistributes, but the
.needs_redistributesemantics is too broad; for views it includes when DTensor dispatch needs to convert from global -> local tensor ops:pytorch/torch/distributed/tensor/_sharding_prop.py
Lines 638 to 653 in c238e6e
For example,
DTensor(shape=[8, 8], placements=[Shard(0)]).view(8, 4, 2)on a size-4 mesh, will recalculate and run.view(2, 4, 2)in local compute. The decomposition flow doesn't need this handling, as it always deals with global tensors.This PR changes redistribution semantics to only be placement based, and reverts the CIA skip, allowing CIA ops to go through the decomposition flow again.