Skip to content

[DTensor] Preserve placement for aten.clone.default - #182730

Closed
fegin wants to merge 15 commits into
gh/fegin/350/basefrom
gh/fegin/350/head
Closed

fegin wants to merge 15 commits into
gh/fegin/350/basefrom
gh/fegin/350/head

Conversation

@fegin

@fegin fegin commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set. The existing register_op_strategy registration in _tensor_ops.py (propagate_single_input_strategy, a 1:1 placement passthrough) then takes effect, preserving Partial / Replicate / Shard alike. clone is fundamentally an identity op and should never redistribute.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented May 6, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/182730

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 2 Unclassified Failures

As of commit 0708f68 with merge base 9c77719 (image):

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pianpwk

pianpwk commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

I think @anshul-si will eventually migrate the tensor_ops rule to single_dim_strategy too, fwiw

[ghstack-poisoned]
@fegin fegin added the ciflow/trunk Trigger trunk jobs on your pull request label May 7, 2026
@fegin

fegin commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@pytorch-auto-revert

Copy link
Copy Markdown

@pytorchbot revert -m "Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable" -c autorevert

This PR is attributed to have caused regression in:

Note: This revert was accelerated by the AI advisor: AI advisor: revert (confidence=0.90)

Please investigate and fix the issues.
@claude Can you please read this revert comment, follow the links and read the errors, to then give a brief diagnostics on the cause of the error? If you judge the error to be legitimate reason for a revert, please provide brief guidance on how the author could fix it.

@claude

claude Bot commented May 8, 2026 •

Copy link
Copy Markdown

Claude finished @pytorch-auto-revert[bot]'s task in 4m 9s —— View job


Revert Diagnostics for PR #182730

  • Read the failing test and error logs
  • Examine the PR changes to understand the regression
  • Provide diagnostics and fix guidance

Root Cause

The failing test is TestLocalDTensorOpsCPU::test_dtensor_op_db_nn_functional_cosine_similarity_cpu_float32. The error:

RuntimeError: aten.clamp_min_.Tensor: in-place operations that require placement changes 
are not supported. The input has placement (_NormPartial(2),), but no valid strategy 
preserves this placement.

Sharding propagation failed for aten.clamp_min_.Tensor(Spec(f32[4, 1](_NormP(2))), 
Spec(f32[](R))) on DeviceMesh((4,), 'cpu', stride=(1,)))

How This PR Caused It

The PR changed aten.clone.default from the pointwise auto-registration (which only generates Replicate/Shard strategies) to propagate_single_input_strategy (which is a 1:1 placement passthrough preserving any placement).

nn.functional.cosine_similarity internally computes norms, which produce tensors with _NormPartial(2) placement. The call chain is approximately:

  1. Norm computation produces a tensor with _NormPartial(2) placement
  2. clone is called on that tensor
  3. Before PR: clone's pointwise strategy only had Replicate/Shard, so it would implicitly redistribute _NormPartial away
  4. After PR: clone preserves _NormPartial(2) as-is (since it now passes through all placements)
  5. aten.clamp_min_.Tensor is called in-place on the result, but it has no valid strategy for _NormPartial(2), causing the failure

Is This a Legitimate Revert?

Yes. The revert is legitimate. The PR correctly preserves standard Partial(sum/avg/max/min) placements through clone, but it also inadvertently preserves internal _NormPartial placements that downstream ops cannot handle.

Fix Guidance

The author has a few options:

  1. Add _NormPartial to clamp_min_.Tensor's strategy - complex and likely not the right approach since _NormPartial is an internal detail.

  2. Filter preserved placements in clone's strategy - modify the propagate_single_input_strategy for clone to only preserve standard Partial types (sum, avg, max, min) and redistribute _NormPartial variants. This could be done by wrapping/customizing the strategy function in _tensor_ops.py.

  3. Add xfail for nn_functional_cosine_similarity in TestLocalDTensorOpsCPU - this test class (TestLocalDTensorOpsCPU) exercises ops with diverse placements including _NormPartial. If _NormPartial passthrough is not intended to work end-to-end for all composite ops, xfailing the test is acceptable.

  4. Preferred approach: Option 2 is the cleanest fix - make clone's strategy preserve only user-facing Partial types while redistributing internal ones like _NormPartial. This aligns with the PR's stated goal ("clone should never redistribute") while avoiding breakage from internal placement types that aren't fully supported through all ops.


@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

pytorchmergebot added a commit that referenced this pull request May 8, 2026
This reverts commit dc2f599.

Reverted #182730 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](#182730 (comment)))
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@fegin your PR has been successfully reverted.

@pytorchmergebot pytorchmergebot added Reverted ci-no-td Do not run TD on this PR labels May 8, 2026
[ghstack-poisoned]
)(propagate_single_input_strategy)


def _is_user_facing_placement(p: Placement) -> bool:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type should a TypeIs[Union] since we know exactly what subtypes would make P be True

[ghstack-poisoned]
fegin added a commit that referenced this pull request May 13, 2026
We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set, and register a custom strategy for aten.clone.default in _tensor_ops.py that wraps propagate_single_input_strategy. The wrapper preserves user-facing placements (Replicate, Shard, _StridedShard, plain Partial(sum/avg/max/min)) and demotes internal Partial subclasses (_NormPartial, _MaskPartial, etc.) to Replicate. This avoids leaking _NormPartial through clone to downstream ops that lack a strategy for it (e.g. aten.clamp_min_.Tensor inside nn.functional.cosine_similarity), which caused the prior version of this PR to be reverted.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).

ghstack-source-id: 93fe0c0
Pull-Request: #182730
[ghstack-poisoned]
fegin added a commit that referenced this pull request May 13, 2026
We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set, and register a custom strategy for aten.clone.default in _tensor_ops.py that wraps propagate_single_input_strategy. The wrapper preserves user-facing placements (Replicate, Shard, _StridedShard, plain Partial(sum/avg/max/min)) and demotes internal Partial subclasses (_NormPartial, _MaskPartial, etc.) to Replicate. This avoids leaking _NormPartial through clone to downstream ops that lack a strategy for it (e.g. aten.clamp_min_.Tensor inside nn.functional.cosine_similarity), which caused the prior version of this PR to be reverted.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).

ghstack-source-id: a8b3e35
Pull-Request: #182730
[ghstack-poisoned]
fegin added a commit that referenced this pull request May 14, 2026
We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set, and register a custom strategy for aten.clone.default in _tensor_ops.py that wraps propagate_single_input_strategy. The wrapper preserves user-facing placements (Replicate, Shard, _StridedShard, plain Partial(sum/avg/max/min)) and demotes internal Partial subclasses (_NormPartial, _MaskPartial, etc.) to Replicate. This avoids leaking _NormPartial through clone to downstream ops that lack a strategy for it (e.g. aten.clamp_min_.Tensor inside nn.functional.cosine_similarity), which caused the prior version of this PR to be reverted.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).

ghstack-source-id: 8811e4a
Pull-Request: #182730
[ghstack-poisoned]
fegin added a commit that referenced this pull request May 14, 2026
We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set, and register a custom strategy for aten.clone.default in _tensor_ops.py that wraps propagate_single_input_strategy. The wrapper preserves user-facing placements (Replicate, Shard, _StridedShard, plain Partial(sum/avg/max/min)) and demotes internal Partial subclasses (_NormPartial, _MaskPartial, etc.) to Replicate. This avoids leaking _NormPartial through clone to downstream ops that lack a strategy for it (e.g. aten.clamp_min_.Tensor inside nn.functional.cosine_similarity), which caused the prior version of this PR to be reverted.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).

ghstack-source-id: 54f31d0
Pull-Request: #182730
[ghstack-poisoned]
fegin added a commit that referenced this pull request May 14, 2026
We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set, and register a custom strategy for aten.clone.default in _tensor_ops.py that wraps propagate_single_input_strategy. The wrapper preserves user-facing placements (Replicate, Shard, _StridedShard, plain Partial(sum/avg/max/min)) and demotes internal Partial subclasses (_NormPartial, _MaskPartial, etc.) to Replicate. This avoids leaking _NormPartial through clone to downstream ops that lack a strategy for it (e.g. aten.clamp_min_.Tensor inside nn.functional.cosine_similarity), which caused the prior version of this PR to be reverted.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).

ghstack-source-id: 9a2d966
Pull-Request: #182730
[ghstack-poisoned]
fegin added a commit that referenced this pull request May 14, 2026
We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set, and register a custom strategy for aten.clone.default in _tensor_ops.py that wraps propagate_single_input_strategy. The wrapper preserves user-facing placements (Replicate, Shard, _StridedShard, plain Partial(sum/avg/max/min)) and demotes internal Partial subclasses (_NormPartial, _MaskPartial, etc.) to Replicate. This avoids leaking _NormPartial through clone to downstream ops that lack a strategy for it (e.g. aten.clamp_min_.Tensor inside nn.functional.cosine_similarity), which caused the prior version of this PR to be reverted.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).

ghstack-source-id: b656e9f
Pull-Request: #182730
[ghstack-poisoned]
fegin added a commit that referenced this pull request May 15, 2026
We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set, and register a custom strategy for aten.clone.default in _tensor_ops.py that wraps propagate_single_input_strategy. The wrapper preserves user-facing placements (Replicate, Shard, _StridedShard, plain Partial(sum/avg/max/min)) and demotes internal Partial subclasses (_NormPartial, _MaskPartial, etc.) to Replicate. This avoids leaking _NormPartial through clone to downstream ops that lack a strategy for it (e.g. aten.clamp_min_.Tensor inside nn.functional.cosine_similarity), which caused the prior version of this PR to be reverted.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).

ghstack-source-id: 8b15dd6
Pull-Request: #182730
[ghstack-poisoned]
fegin added a commit that referenced this pull request May 15, 2026
We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set, and register a custom strategy for aten.clone.default in _tensor_ops.py that wraps propagate_single_input_strategy. The wrapper preserves user-facing placements (Replicate, Shard, _StridedShard, plain Partial(sum/avg/max/min)) and demotes internal Partial subclasses (_NormPartial, _MaskPartial, etc.) to Replicate. This avoids leaking _NormPartial through clone to downstream ops that lack a strategy for it (e.g. aten.clamp_min_.Tensor inside nn.functional.cosine_similarity), which caused the prior version of this PR to be reverted.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).

ghstack-source-id: 7354a66
Pull-Request: #182730
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set. The existing register_op_strategy registration in _tensor_ops.py (propagate_single_input_strategy, a 1:1 placement passthrough) then takes effect, preserving Partial / Replicate / Shard alike. clone is fundamentally an identity op and should never redistribute.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).
Pull Request resolved: pytorch#182730
Approved by: https://github.com/pianpwk
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
…182730)"

This reverts commit dc2f599.

Reverted pytorch#182730 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#182730 (comment)))
[ghstack-poisoned]
fegin added a commit that referenced this pull request May 15, 2026
We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set, and register a custom strategy for aten.clone.default in _tensor_ops.py that wraps propagate_single_input_strategy. The wrapper preserves user-facing placements (Replicate, Shard, _StridedShard, plain Partial(sum/avg/max/min)) and demotes internal Partial subclasses (_NormPartial, _MaskPartial, etc.) to Replicate. This avoids leaking _NormPartial through clone to downstream ops that lack a strategy for it (e.g. aten.clamp_min_.Tensor inside nn.functional.cosine_similarity), which caused the prior version of this PR to be reverted.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).

ghstack-source-id: 1fd496f
Pull-Request: #182730
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set. The existing register_op_strategy registration in _tensor_ops.py (propagate_single_input_strategy, a 1:1 placement passthrough) then takes effect, preserving Partial / Replicate / Shard alike. clone is fundamentally an identity op and should never redistribute.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).
Pull Request resolved: pytorch#182730
Approved by: https://github.com/pianpwk
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
…182730)"

This reverts commit dc2f599.

Reverted pytorch#182730 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#182730 (comment)))
@github-actions

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
If you want the bot to never mark this PR stale again, add the no-stale label.
Stale pull requests will automatically be closed after 30 days of inactivity.

@github-actions github-actions Bot added the Stale label Jul 15, 2026
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set. The existing register_op_strategy registration in _tensor_ops.py (propagate_single_input_strategy, a 1:1 placement passthrough) then takes effect, preserving Partial / Replicate / Shard alike. clone is fundamentally an identity op and should never redistribute.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).
Pull Request resolved: pytorch#182730
Approved by: https://github.com/pianpwk
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…182730)"

This reverts commit dc2f599.

Reverted pytorch#182730 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#182730 (comment)))
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
We registered clone op twice, one in _tensor_ops.py and another in _pointwise_ops.py. The former one is correct. This PR removes the later one.

aten.clone.default is tagged torch.Tag.pointwise and was getting auto-registered with the default pointwise single-dim strategy, which only enumerates Replicate/Shard placements. A Partial input was silently redistributed to Replicate via implicit all-reduce.

Skip clone from the pointwise auto-registration via a new _pointwise_skip_ops set. The existing register_op_strategy registration in _tensor_ops.py (propagate_single_input_strategy, a 1:1 placement passthrough) then takes effect, preserving Partial / Replicate / Shard alike. clone is fundamentally an identity op and should never redistribute.

Adds test_clone_preserves_partial covering Partial(sum/avg/max/min).
Pull Request resolved: pytorch#182730
Approved by: https://github.com/pianpwk
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…182730)"

This reverts commit dc2f599.

Reverted pytorch#182730 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#182730 (comment)))
@github-actions github-actions Bot closed this Aug 14, 2026
@github-actions
github-actions Bot deleted the gh/fegin/350/head branch September 14, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/dtensor Run DTensor specific tests ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: distributed (dtensor) release notes category Reverted Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants