Skip to content

[dtensor] migrating matrix_ops to single dim strategies - #186667

Closed
anshul-si wants to merge 6 commits into
gh/anshul-si/146/basefrom
gh/anshul-si/146/head
Closed

anshul-si wants to merge 6 commits into
gh/anshul-si/146/basefrom
gh/anshul-si/146/head

Conversation

@anshul-si

@anshul-si anshul-si commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

**Summary: ** Adds 11 single dim strategies, 2 of which were not registered before.

Test Cases

  1. pytest test/distributed/tensor/test_matrix_ops.py
  2. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_latency
  3. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_mesh_2d
  4. pytest test/distributed/tensor/test_op_strategy.py -k test_bmm_strategies

Stack from ghstack (oldest at bottom):

@anshul-si
anshul-si requested a review from weifengpy as a code owner June 8, 2026 22:56
@pytorch-bot

pytorch-bot Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 New Failure

As of commit 265ca5a with merge base 1b62beb (image):

NEW FAILURE - The following job has failed:

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

@pytorch-bot pytorch-bot Bot added ciflow/dtensor Run DTensor specific tests ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests release notes: distributed (dtensor) release notes category labels Jun 8, 2026
@anshul-si
anshul-si requested a review from pianpwk June 8, 2026 23:03
@anshul-si anshul-si added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 8, 2026

@pianpwk pianpwk left a comment •

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.

will unblock this, thanks!

**Summary: ** Adds 11 single dim strategies, 2 of which were not registered before. 

**Test Cases**
1. pytest test/distributed/tensor/test_matrix_ops.py 
2. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_latency
3. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_mesh_2d
4. pytest test/distributed/tensor/test_op_strategy.py -k test_bmm_strategies




[ghstack-poisoned]
anshul-si added a commit that referenced this pull request Jun 9, 2026
**Summary: ** Adds 11 single dim strategies, 2 of which were not registered before. 

**Test Cases**
1. pytest test/distributed/tensor/test_matrix_ops.py 
2. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_latency
3. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_mesh_2d
4. pytest test/distributed/tensor/test_op_strategy.py -k test_bmm_strategies




[ghstack-poisoned]
anshul-si added a commit that referenced this pull request Jun 10, 2026
**Summary: ** Adds 11 single dim strategies, 2 of which were not registered before. 

**Test Cases**
1. pytest test/distributed/tensor/test_matrix_ops.py 
2. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_latency
3. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_mesh_2d
4. pytest test/distributed/tensor/test_op_strategy.py -k test_bmm_strategies




[ghstack-poisoned]
anshul-si added a commit that referenced this pull request Jun 10, 2026
**Summary: ** Adds 11 single dim strategies, 2 of which were not registered before. 

**Test Cases**
1. pytest test/distributed/tensor/test_matrix_ops.py 
2. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_latency
3. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_mesh_2d
4. pytest test/distributed/tensor/test_op_strategy.py -k test_bmm_strategies




[ghstack-poisoned]
anshul-si added a commit that referenced this pull request Jun 10, 2026
**Summary: ** Adds 11 single dim strategies, 2 of which were not registered before. 

**Test Cases**
1. pytest test/distributed/tensor/test_matrix_ops.py 
2. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_latency
3. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_mesh_2d
4. pytest test/distributed/tensor/test_op_strategy.py -k test_bmm_strategies




[ghstack-poisoned]
anshul-si added a commit that referenced this pull request Jun 11, 2026
@anshul-si

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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: torchtitan-test / torchtitan-x-pytorch-test / test-osdc (torchtitan_features_integration, 1, 1, mt-l-x86aavx2-189-704-a10g-8)

Details for Dev Infra team Raised by workflow job

@anshul-si

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -f "unrelated torchtitan failure"

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

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 pushed a commit that referenced this pull request Jun 13, 2026
The single-dim strategy path inserts an implicit all-Replicate rule. SDPA efficient attention intentionally uses None output specs for philox_seed and philox_offset so those scalar tensor outputs remain local tensors, matching the previous op-strategy behavior. The inserted rule used Replicate for those outputs because meta propagation returns real scalar TensorMeta, so combining it with explicit SDPA rules on a 2D mesh could build a DTensorSpec with placements=(Replicate(), None).

This addresses a regression from #186667, which migrated matrix ops to single-dim strategies and introduced the mixed per-mesh-dim behavior for these outputs.

Preserve output positions that are None in every explicit single-dim strategy when inserting the implicit replicate rule. Also make full-mesh expansion reject mixed None/Placement entries instead of constructing invalid DTensorSpec objects.

Test Plan: Added regression tests for SDPA efficient-attention philox scalar outputs and mixed None/Placement output rejection. Ran the affected tests and lintrunner.

Authored with the assistance of an AI coding assistant.
Pull Request resolved: #187199
Approved by: https://github.com/pianpwk
jemitche1 pushed a commit to jemitche1/pytorch that referenced this pull request Jun 13, 2026
**Summary: ** Adds 11 single dim strategies, 2 of which were not registered before.

**Test Cases**
1. pytest test/distributed/tensor/test_matrix_ops.py
2. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_latency
3. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_mesh_2d
4. pytest test/distributed/tensor/test_op_strategy.py -k test_bmm_strategies

Pull Request resolved: pytorch#186667
Approved by: https://github.com/pianpwk, https://github.com/weifengpy
aditvenk added a commit to meta-pytorch/autoparallel that referenced this pull request Jun 15, 2026
PyTorch removed _mm_like_strategy when pytorch/pytorch#186667 migrated mm to single-dim strategy. Register AutoParallel's einsum strategy on the single-dim path and reuse _try_single_dim_strategy for expansion.

Pass user kwargs through to DTensor OpSchema so single-dim strategies that depend on keyword-only arguments can compute metadata correctly.

Authored with Claude.

stack-info: PR: #489, branch: aditvenk/stack/1
aditvenk added a commit to pytorch/torchtitan that referenced this pull request Jun 16, 2026
ScaledDotProductAttention.forward receives q/k/v in model layout (B, L,
H, D), then transposes them to SDPA layout (B, H, L, D). The CP wrapper
annotates q/k/v before that transpose, so the shard dimension must be
expressed in the model layout. CP splits the sequence axis, which is dim
1 in (B, L, H, D). The old code used Shard(2), annotating the head axis
instead. After the transpose, PyTorch saw Shard(1) at the SDPA op, i.e.
head sharding in (B, H, L, D), instead of the required Shard(2) sequence
sharding.

This was latent because PyTorch's old CP SDPA sharding rule appended the
CP sequence strategy to the normal SDPA base strategies, so the wrong
head-sharded metadata could match a non-CP/base head-sharded strategy
and pass propagation. pytorch/pytorch#186667
migrated these rules to single-dim strategies and the CP override now
only accepts the CP sequence strategy. That correctly exposes the bad
TorchTitan annotation as needs_redistribute=True, which triggers the CP
SDPA handler's assertion.

Use Shard(1) when wrapping the pre-transpose q/k/v tensors, so the
transpose presents Shard(2) at the actual SDPA op.

Error seen in Graph Trainer CI test "aot_fx_trace llama3 FSDP+TP+CP"
failed in
torch/distributed/tensor/experimental/_context_parallel/_attention.py
with AssertionError: "inputs need to be redistributed".
@github-actions
github-actions Bot deleted the gh/anshul-si/146/head branch July 12, 2026 02:25
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
**Summary: ** Adds 11 single dim strategies, 2 of which were not registered before.

**Test Cases**
1. pytest test/distributed/tensor/test_matrix_ops.py
2. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_latency
3. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_mesh_2d
4. pytest test/distributed/tensor/test_op_strategy.py -k test_bmm_strategies

Pull Request resolved: pytorch#186667
Approved by: https://github.com/pianpwk, https://github.com/weifengpy
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
The single-dim strategy path inserts an implicit all-Replicate rule. SDPA efficient attention intentionally uses None output specs for philox_seed and philox_offset so those scalar tensor outputs remain local tensors, matching the previous op-strategy behavior. The inserted rule used Replicate for those outputs because meta propagation returns real scalar TensorMeta, so combining it with explicit SDPA rules on a 2D mesh could build a DTensorSpec with placements=(Replicate(), None).

This addresses a regression from pytorch#186667, which migrated matrix ops to single-dim strategies and introduced the mixed per-mesh-dim behavior for these outputs.

Preserve output positions that are None in every explicit single-dim strategy when inserting the implicit replicate rule. Also make full-mesh expansion reject mixed None/Placement entries instead of constructing invalid DTensorSpec objects.

Test Plan: Added regression tests for SDPA efficient-attention philox scalar outputs and mixed None/Placement output rejection. Ran the affected tests and lintrunner.

Authored with the assistance of an AI coding assistant.
Pull Request resolved: pytorch#187199
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
**Summary: ** Adds 11 single dim strategies, 2 of which were not registered before.

**Test Cases**
1. pytest test/distributed/tensor/test_matrix_ops.py
2. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_latency
3. pytest test/distributed/tensor/test_op_strategy.py -k test_redistribute_cost_mesh_2d
4. pytest test/distributed/tensor/test_op_strategy.py -k test_bmm_strategies

Pull Request resolved: pytorch#186667
Approved by: https://github.com/pianpwk, https://github.com/weifengpy
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
The single-dim strategy path inserts an implicit all-Replicate rule. SDPA efficient attention intentionally uses None output specs for philox_seed and philox_offset so those scalar tensor outputs remain local tensors, matching the previous op-strategy behavior. The inserted rule used Replicate for those outputs because meta propagation returns real scalar TensorMeta, so combining it with explicit SDPA rules on a 2D mesh could build a DTensorSpec with placements=(Replicate(), None).

This addresses a regression from pytorch#186667, which migrated matrix ops to single-dim strategies and introduced the mixed per-mesh-dim behavior for these outputs.

Preserve output positions that are None in every explicit single-dim strategy when inserting the implicit replicate rule. Also make full-mesh expansion reject mixed None/Placement entries instead of constructing invalid DTensorSpec objects.

Test Plan: Added regression tests for SDPA efficient-attention philox scalar outputs and mixed None/Placement output rejection. Ran the affected tests and lintrunner.

Authored with the assistance of an AI coding assistant.
Pull Request resolved: pytorch#187199
Approved by: https://github.com/pianpwk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants