Skip to content

[DTensor] support _StridedShard redistribution for arbitrary split_factor - #178735

Closed
weifengpy wants to merge 18 commits into
gh/weifengpy/103/basefrom
gh/weifengpy/103/head
Closed

weifengpy wants to merge 18 commits into
gh/weifengpy/103/basefrom
gh/weifengpy/103/head

Conversation

@weifengpy

@weifengpy weifengpy commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

we have two source of _StridedShard

  • FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
  • view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

On a 1D mesh, _StridedShard causes shard_order=None which forces the
graph-based planner. The graph-based planner can't decode split_factor
into a shard order with only one mesh dimension, crashing with ValueError.

Skip graph-based planning for 1D mesh _StridedShard so the greedy path's
1D shortcut creates a direct transform, and the existing execution handler
calls _StridedShard._to_replicate_tensor().

Authored with Claude.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Mar 30, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 3 New Failures, 2 Cancelled Jobs, 1 Unrelated Failure

As of commit b04496a with merge base e899f15 (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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 Mar 30, 2026
@weifengpy
weifengpy marked this pull request as draft March 30, 2026 06:19
On a 1D mesh, _StridedShard causes shard_order=None which forces the
graph-based planner. The graph-based planner can't decode split_factor
into a shard order with only one mesh dimension, crashing with ValueError.

Skip graph-based planning for 1D mesh _StridedShard so the greedy path's
1D shortcut creates a direct transform, and the existing execution handler
calls _StridedShard._to_replicate_tensor().

Authored with Claude.

[ghstack-poisoned]
weifengpy added a commit that referenced this pull request Mar 30, 2026
On a 1D mesh, _StridedShard causes shard_order=None which forces the
graph-based planner. The graph-based planner can't decode split_factor
into a shard order with only one mesh dimension, crashing with ValueError.

Skip graph-based planning for 1D mesh _StridedShard so the greedy path's
1D shortcut creates a direct transform, and the existing execution handler
calls _StridedShard._to_replicate_tensor().

Authored with Claude.

ghstack-source-id: 37d21c7
Pull Request resolved: #178735
On a 1D mesh, _StridedShard causes shard_order=None which forces the
graph-based planner. The graph-based planner can't decode split_factor
into a shard order with only one mesh dimension, crashing with ValueError.

Skip graph-based planning for 1D mesh _StridedShard so the greedy path's
1D shortcut creates a direct transform, and the existing execution handler
calls _StridedShard._to_replicate_tensor().

Authored with Claude.

[ghstack-poisoned]
weifengpy added a commit that referenced this pull request Mar 30, 2026
On a 1D mesh, _StridedShard causes shard_order=None which forces the
graph-based planner. The graph-based planner can't decode split_factor
into a shard order with only one mesh dimension, crashing with ValueError.

Skip graph-based planning for 1D mesh _StridedShard so the greedy path's
1D shortcut creates a direct transform, and the existing execution handler
calls _StridedShard._to_replicate_tensor().

Authored with Claude.

ghstack-source-id: 9a33bfd
Pull Request resolved: #178735
On a 1D mesh, _StridedShard causes shard_order=None which forces the
graph-based planner. The graph-based planner can't decode split_factor
into a shard order with only one mesh dimension, crashing with ValueError.

Skip graph-based planning for 1D mesh _StridedShard so the greedy path's
1D shortcut creates a direct transform, and the existing execution handler
calls _StridedShard._to_replicate_tensor().

Authored with Claude.

[ghstack-poisoned]
weifengpy added a commit that referenced this pull request Mar 30, 2026
On a 1D mesh, _StridedShard causes shard_order=None which forces the
graph-based planner. The graph-based planner can't decode split_factor
into a shard order with only one mesh dimension, crashing with ValueError.

Skip graph-based planning for 1D mesh _StridedShard so the greedy path's
1D shortcut creates a direct transform, and the existing execution handler
calls _StridedShard._to_replicate_tensor().

Authored with Claude.

ghstack-source-id: db8d52b
Pull Request resolved: #178735
we have two source of _StridedShard in DTensor
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning



[ghstack-poisoned]
weifengpy added a commit that referenced this pull request Mar 30, 2026
On a 1D mesh, _StridedShard causes shard_order=None which forces the
graph-based planner. The graph-based planner can't decode split_factor
into a shard order with only one mesh dimension, crashing with ValueError.

Skip graph-based planning for 1D mesh _StridedShard so the greedy path's
1D shortcut creates a direct transform, and the existing execution handler
calls _StridedShard._to_replicate_tensor().

Authored with Claude.

ghstack-source-id: 0823b66
Pull Request resolved: #178735
@weifengpy weifengpy changed the title [DTensor] support _StridedShard redistribution on 1D mesh [DTensor] support _StridedShard redistribution for arbitrary split_factor Mar 30, 2026
@weifengpy
weifengpy requested review from wconstab and zpcore March 30, 2026 07:45
@weifengpy
weifengpy marked this pull request as ready for review March 30, 2026 07:46
…ry split_factor"


we have two source of _StridedShard in DTensor
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement



[ghstack-poisoned]
…ry split_factor"


we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement



[ghstack-poisoned]
…ry split_factor"


we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement



[ghstack-poisoned]
…ry split_factor"


we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement



[ghstack-poisoned]
…ry split_factor"


we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement



[ghstack-poisoned]

@zpcore zpcore 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.

Discussed offline, this is good as a temporary fix. We will make follow up.

@weifengpy

weifengpy commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor Author

the CI error is from broken trunk: test/inductor/test_fp8.py::TestFP8LoweringCPU::test_rowwise_scaling_acceptable_input_dims_M_1024_K_32_N_16_persistent_matmul_False_cpu https://hud.pytorch.org/pytorch/pytorch/commit/edda74bb2bd946d18612f62ecb2f1337056523c8

@weifengpy

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge -i

IvanKobzarev pushed a commit to IvanKobzarev/pytorch that referenced this pull request Apr 3, 2026
…ctor (pytorch#178735)

we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

Pull Request resolved: pytorch#178735
Approved by: https://github.com/zpcore
IvanKobzarev pushed a commit to IvanKobzarev/pytorch that referenced this pull request Apr 3, 2026
…ctor (pytorch#178735)

we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

Pull Request resolved: pytorch#178735
Approved by: https://github.com/zpcore
weifengpy added a commit that referenced this pull request Apr 7, 2026
…ctor (#178735)

we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

Pull Request resolved: #178735
Approved by: https://github.com/zpcore
nklshy-aws pushed a commit to nklshy-aws/pytorch that referenced this pull request Apr 7, 2026
…ctor (pytorch#178735)

we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

Pull Request resolved: pytorch#178735
Approved by: https://github.com/zpcore
nklshy-aws pushed a commit to nklshy-aws/pytorch that referenced this pull request Apr 7, 2026
…ctor (pytorch#178735)

we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

Pull Request resolved: pytorch#178735
Approved by: https://github.com/zpcore
bobrenjc93 pushed a commit to bobrenjc93/pytorch that referenced this pull request Apr 9, 2026
…ctor (pytorch#178735)

we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

Pull Request resolved: pytorch#178735
Approved by: https://github.com/zpcore
bobrenjc93 pushed a commit to bobrenjc93/pytorch that referenced this pull request Apr 9, 2026
…ctor (pytorch#178735)

we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

Pull Request resolved: pytorch#178735
Approved by: https://github.com/zpcore
pytorchmergebot pushed a commit that referenced this pull request Apr 9, 2026
…179208)

View ops (flatten) produce literal _StridedShard placements with use_strided_shard_as_shard_order=False. Previously, downstream ops could auto-detect this flag incorrectly due to `use_strided_shard_as_shard_order` not getting correctly propagate into downstream DTensorSpec.

This change:
- Adds _propagate_use_strided_shard_flag in the sharding propagator as a centralized post-processing step for all OpStrategy results, ensuring use_strided_shard_as_shard_order is always inherited from input specs.
- Adds a guard in view ops to error on inputs with use_strided_shard_as_shard_order=True (shard-order-encoded _StridedShard would be misinterpreted by dimension mapping).
- Improves __post_init__ auto-detection to actually attempt shard order decoding before setting the flag to True.
- Revert temporary fix in #178735.

Authored with Claude.
Pull Request resolved: #179208
Approved by: https://github.com/weifengpy
bobrenjc93 pushed a commit to bobrenjc93/pytorch that referenced this pull request Apr 10, 2026
…ctor (pytorch#178735)

we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

Pull Request resolved: pytorch#178735
Approved by: https://github.com/zpcore
bobrenjc93 pushed a commit to bobrenjc93/pytorch that referenced this pull request Apr 10, 2026
…ctor (pytorch#178735)

we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

Pull Request resolved: pytorch#178735
Approved by: https://github.com/zpcore
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ctor (pytorch#178735)

we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

Pull Request resolved: pytorch#178735
Approved by: https://github.com/zpcore
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ctor (pytorch#178735)

we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

Pull Request resolved: pytorch#178735
Approved by: https://github.com/zpcore
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ytorch#179208)

View ops (flatten) produce literal _StridedShard placements with use_strided_shard_as_shard_order=False. Previously, downstream ops could auto-detect this flag incorrectly due to `use_strided_shard_as_shard_order` not getting correctly propagate into downstream DTensorSpec.

This change:
- Adds _propagate_use_strided_shard_flag in the sharding propagator as a centralized post-processing step for all OpStrategy results, ensuring use_strided_shard_as_shard_order is always inherited from input specs.
- Adds a guard in view ops to error on inputs with use_strided_shard_as_shard_order=True (shard-order-encoded _StridedShard would be misinterpreted by dimension mapping).
- Improves __post_init__ auto-detection to actually attempt shard order decoding before setting the flag to True.
- Revert temporary fix in pytorch#178735.

Authored with Claude.
Pull Request resolved: pytorch#179208
Approved by: https://github.com/weifengpy
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ctor (pytorch#178735)

we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

Pull Request resolved: pytorch#178735
Approved by: https://github.com/zpcore
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ctor (pytorch#178735)

we have two source of _StridedShard
* FSDP2 + TP sharding on same dim, split_factor can be interpreated with a device order
* view, split_factor may not be interpreated with a device order

when split_factor cannot be interpreated with a device order, graph-based planner fails, falling back to greedy planning. It treats _StridedShard as a opague placement

Pull Request resolved: pytorch#178735
Approved by: https://github.com/zpcore
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ytorch#179208)

View ops (flatten) produce literal _StridedShard placements with use_strided_shard_as_shard_order=False. Previously, downstream ops could auto-detect this flag incorrectly due to `use_strided_shard_as_shard_order` not getting correctly propagate into downstream DTensorSpec.

This change:
- Adds _propagate_use_strided_shard_flag in the sharding propagator as a centralized post-processing step for all OpStrategy results, ensuring use_strided_shard_as_shard_order is always inherited from input specs.
- Adds a guard in view ops to error on inputs with use_strided_shard_as_shard_order=True (shard-order-encoded _StridedShard would be misinterpreted by dimension mapping).
- Improves __post_init__ auto-detection to actually attempt shard order decoding before setting the flag to True.
- Revert temporary fix in pytorch#178735.

Authored with Claude.
Pull Request resolved: pytorch#179208
Approved by: https://github.com/weifengpy
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants