Skip to content

[DTensor] skip decomposition for CIA ops - #174918

Closed
pianpwk wants to merge 4 commits into
gh/pianpwk/84/basefrom
gh/pianpwk/84/head
Closed

pianpwk wants to merge 4 commits into
gh/pianpwk/84/basefrom
gh/pianpwk/84/head

Conversation

@pianpwk

@pianpwk pianpwk commented Feb 12, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

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.

@pytorch-bot

pytorch-bot Bot commented Feb 12, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (7 Unrelated Failures)

As of commit 3614e21 with merge base b323a6e (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:

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

pianpwk added a commit that referenced this pull request Feb 12, 2026
ghstack-source-id: 0381570
Pull Request resolved: #174918
pianpwk added a commit that referenced this pull request Feb 13, 2026
ghstack-source-id: c3b7caa
Pull Request resolved: #174918
@pianpwk
pianpwk requested review from wconstab and zpcore February 13, 2026 08:41
def test_custom_recursive_decomp(self):
"""
op1 decomps -> op2, which decomps -> matmul
op1 decomps -> op2, which decomps -> mm

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you explain the before/after for this- op2 used to call @, which then decomposed into ..., and now ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

op1(x, y) := op2(x, y) * 1.0

before, op2(x, y) := x @ y, which calls aten::matmul which is CIA, so there's a weird interaction there

after, op2(x, y) := torch.mm(x, y), which calls aten::mm.

I still need to figure out the decomp/CIA interaction, but this test case is just synthetic.

self.assertTrue(op not in sharding_prop.op_single_dim_strategy_funcs)
self.assertTrue(op not in sharding_prop.op_to_rules)

# binary_cross_entropy_with_logits

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these test cases are removed because previously we accidentally supported them via CIA decomp path and now we don't support them? or, do we support them but we support them by decomposing above dtensor and redispatching to dtensors on their decomp's ops?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

these are confirmed to not be CIA, but I think they decompose to CIA (e.g. glu -> tensor_split), and there's a weird interaction there that I need to figure out.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should these be 'xfail' instead of not tested then?

do we get a nice error saying something about CIA+Decomps when we try to do this, or is that hard?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

that is currently hard... i'll xfail with "no sharding strategy"

)

with torch.inference_mode(): # call aten::linear
out = torch.nn.functional.linear(x, w)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

guess we didn't have a test for this path before? how did you notice the regression, out of curiousity?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah, I noticed in torchtitan DTensor eager inference, that linear was unnecessarily redistributing to RxR->R (another thing I need to figure out for decomps).

I think this revert should be safe-ish, we should restore old behavior for CIA ops, add correct rule support for a large number of ops, and for some ops maybe we're still comm-inefficient.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this revert should be safe-ish,

in what way might it not be safe?

we should restore old behavior for CIA ops,

that's what this PR does, is that your point?

add correct rule support for a large number of ops, and for some ops maybe we're still comm-inefficient.

explain this part more?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh i see, using the CIA path can lead to more comms than using the decomp path? though the initial example triggering the reversion of this PR is that linear incurs more comms with decomps than with CIA wasn't it?

@pianpwk pianpwk Feb 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in what way might it not be safe?

I think the only issue is, since the decomp work regressed aten::linear, for some previously uncovered ops it might only produce the full replicate rule, so we just get inefficient coverage..

that's what this PR does, is that your point?

yepp

explain this part more?

this is the response above; for some ops the decomp work might not help much.

I think it's likely related to views handling... i'll look into this more

op_strategy = None
if DecompShardingStrategy.has_decomp(op_schema.op):
has_cia = torch._C._dispatch_has_kernel_for_dispatch_key(
op_schema.op.name(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should comment the logic here. or above. i think at one point i added a docstring about what precedence order we dispatched things

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]
pianpwk added a commit that referenced this pull request Feb 13, 2026
ghstack-source-id: e32f408
Pull Request resolved: #174918
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]
pianpwk added a commit that referenced this pull request Feb 13, 2026
ghstack-source-id: 959d029
Pull Request resolved: #174918
@pianpwk

pianpwk commented Feb 14, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Feb 14, 2026
@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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: linux-aarch64 / linux-jammy-aarch64-py3.10 / test (openreg, 1, 1, linux.arm64.m8g.4xlarge)

Details for Dev Infra team Raised by workflow job

@pianpwk

pianpwk commented Feb 14, 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

pianpwk added a commit that referenced this pull request Feb 20, 2026
…ibutes in decomposition 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]
pianpwk added a commit that referenced this pull request Feb 20, 2026
…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]
pytorchmergebot pushed a commit that referenced this pull request Feb 20, 2026
#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
norx1991 pushed a commit that referenced this pull request Feb 24, 2026
#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
@github-actions
github-actions Bot deleted the gh/pianpwk/84/head branch March 17, 2026 02:21
EmanueleCoradin pushed a commit to EmanueleCoradin/pytorch that referenced this pull request Mar 30, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: distributed (dtensor) release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants