Skip to content

[Inductor][TP] Fuse slice-cat TP collective patterns - #184911

Closed
sanketpurandare wants to merge 1 commit into
mainfrom
sanketpurandare/stack/15
Closed

sanketpurandare wants to merge 1 commit into
mainfrom
sanketpurandare/stack/15

Conversation

@sanketpurandare

@sanketpurandare sanketpurandare commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Stacked PRs:


[Inductor][TP] Fuse slice-cat TP collective patterns

Graph-level chunking can expose tensor-parallel collective values through simple slice/cat reassembly before a matmul, or can feed reduce-scatter from an equivalent slice/cat form after a matmul. The existing micro-pipeline TP matcher only recognized the direct all-gather/matmul and matmul/reduce-scatter patterns, so these semantically equivalent graphs missed fusion.

Teach the all-gather and reduce-scatter matchers to recognize slice/cat forms that reassemble a single collective value without changing the TP communication contract. The replacement and erase logic remains scoped to the matched nodes, and the matmul multi-user guard still rejects users outside the matched reassembly.

Fixes #184833

Test Plan:

python test/distributed/tensor/parallel/test_micro_pipeline_tp.py MicroPipelineTPTest.test_find_all_gather_patterns MicroPipelineTPTest.test_find_reduce_scatter_patterns MicroPipelineTPTest.test_fuse_all_gather_matmul_slice_cat MicroPipelineTPTest.test_fuse_all_gather_matmul_slice_cat_trim MicroPipelineTPTest.test_fuse_matmul_reduce_scatter_slice_cat -v

lintrunner --config=.lintrunner.toml torch/_inductor/fx_passes/micro_pipeline_tp.py test/distributed/tensor/parallel/test_micro_pipeline_tp.py

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

@pytorch-bot

pytorch-bot Bot commented May 22, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 932b565 with merge base 90e9fa9 (image):

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 module: inductor release notes: distributed (pipeline) release notes category labels May 22, 2026
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/15 branch from ad37664 to 078fbe2 Compare May 22, 2026 17:32
sanketpurandare added a commit that referenced this pull request May 22, 2026
Graph-level chunking can expose tensor-parallel collective values through simple slice/cat reassembly before a matmul, or can feed reduce-scatter from an equivalent slice/cat form after a matmul. The existing micro-pipeline TP matcher only recognized the direct all-gather/matmul and matmul/reduce-scatter patterns, so these semantically equivalent graphs missed fusion.

Teach the all-gather and reduce-scatter matchers to recognize slice/cat forms that reassemble a single collective value without changing the TP communication contract. The replacement and erase logic remains scoped to the matched nodes, and the matmul multi-user guard still rejects users outside the matched reassembly.

Fixes #184833

Test Plan:

python test/distributed/tensor/parallel/test_micro_pipeline_tp.py MicroPipelineTPTest.test_find_all_gather_patterns MicroPipelineTPTest.test_find_reduce_scatter_patterns MicroPipelineTPTest.test_fuse_all_gather_matmul_slice_cat MicroPipelineTPTest.test_fuse_all_gather_matmul_slice_cat_trim MicroPipelineTPTest.test_fuse_matmul_reduce_scatter_slice_cat -v

lintrunner --config=.lintrunner.toml torch/_inductor/fx_passes/micro_pipeline_tp.py test/distributed/tensor/parallel/test_micro_pipeline_tp.py

stack-info: PR: #184911, branch: sanketpurandare/stack/15
@sanketpurandare
sanketpurandare marked this pull request as draft May 22, 2026 19:26
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/14 to main May 22, 2026 19:26
@pytorch-bot pytorch-bot Bot added the release notes: distributed (dtensor) release notes category label May 22, 2026
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/15 branch from 078fbe2 to f059ca5 Compare May 22, 2026 19:27
sanketpurandare added a commit that referenced this pull request May 22, 2026
Graph-level chunking can expose tensor-parallel collective values through simple slice/cat reassembly before a matmul, or can feed reduce-scatter from an equivalent slice/cat form after a matmul. The existing micro-pipeline TP matcher only recognized the direct all-gather/matmul and matmul/reduce-scatter patterns, so these semantically equivalent graphs missed fusion.

Teach the all-gather and reduce-scatter matchers to recognize slice/cat forms that reassemble a single collective value without changing the TP communication contract. The replacement and erase logic remains scoped to the matched nodes, and the matmul multi-user guard still rejects users outside the matched reassembly.

Fixes #184833

Test Plan:

python test/distributed/tensor/parallel/test_micro_pipeline_tp.py MicroPipelineTPTest.test_find_all_gather_patterns MicroPipelineTPTest.test_find_reduce_scatter_patterns MicroPipelineTPTest.test_fuse_all_gather_matmul_slice_cat MicroPipelineTPTest.test_fuse_all_gather_matmul_slice_cat_trim MicroPipelineTPTest.test_fuse_matmul_reduce_scatter_slice_cat -v

lintrunner --config=.lintrunner.toml torch/_inductor/fx_passes/micro_pipeline_tp.py test/distributed/tensor/parallel/test_micro_pipeline_tp.py

stack-info: PR: #184911, branch: sanketpurandare/stack/15
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/14 May 22, 2026 19:27
@sanketpurandare
sanketpurandare marked this pull request as ready for review May 22, 2026 19:27
@sanketpurandare
sanketpurandare marked this pull request as draft May 22, 2026 19:42
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/14 to main May 22, 2026 19:42
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/15 branch from f059ca5 to bd96437 Compare May 22, 2026 19:42
sanketpurandare added a commit that referenced this pull request May 22, 2026
Graph-level chunking can expose tensor-parallel collective values through simple slice/cat reassembly before a matmul, or can feed reduce-scatter from an equivalent slice/cat form after a matmul. The existing micro-pipeline TP matcher only recognized the direct all-gather/matmul and matmul/reduce-scatter patterns, so these semantically equivalent graphs missed fusion.

Teach the all-gather and reduce-scatter matchers to recognize slice/cat forms that reassemble a single collective value without changing the TP communication contract. The replacement and erase logic remains scoped to the matched nodes, and the matmul multi-user guard still rejects users outside the matched reassembly.

Fixes #184833

Test Plan:

python test/distributed/tensor/parallel/test_micro_pipeline_tp.py MicroPipelineTPTest.test_find_all_gather_patterns MicroPipelineTPTest.test_find_reduce_scatter_patterns MicroPipelineTPTest.test_fuse_all_gather_matmul_slice_cat MicroPipelineTPTest.test_fuse_all_gather_matmul_slice_cat_trim MicroPipelineTPTest.test_fuse_matmul_reduce_scatter_slice_cat -v

lintrunner --config=.lintrunner.toml torch/_inductor/fx_passes/micro_pipeline_tp.py test/distributed/tensor/parallel/test_micro_pipeline_tp.py

stack-info: PR: #184911, branch: sanketpurandare/stack/15
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/14 May 22, 2026 19:42
@sanketpurandare
sanketpurandare marked this pull request as ready for review May 22, 2026 19:42
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/15 branch from 873deee to ff08758 Compare May 27, 2026 04:34
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/10 May 27, 2026 04:34
@sanketpurandare
sanketpurandare marked this pull request as ready for review May 27, 2026 04:34
@sanketpurandare
sanketpurandare marked this pull request as draft June 4, 2026 19:00
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/10 to main June 4, 2026 19:00
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/15 branch from ff08758 to fd55259 Compare June 4, 2026 19:00
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/10 June 4, 2026 19:01
@sanketpurandare
sanketpurandare marked this pull request as ready for review June 4, 2026 19:01
@sanketpurandare
sanketpurandare marked this pull request as draft June 4, 2026 19:06
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/10 to main June 4, 2026 19:06
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/10 June 4, 2026 19:07
@sanketpurandare
sanketpurandare marked this pull request as ready for review June 4, 2026 19:07
@sanketpurandare
sanketpurandare deleted the sanketpurandare/stack/15 branch June 4, 2026 20:53
@sanketpurandare
sanketpurandare restored the sanketpurandare/stack/15 branch June 4, 2026 20:54
@sanketpurandare
sanketpurandare changed the base branch from gh/sanketpurandare/1/head to sanketpurandare/stack/10 June 4, 2026 20:54
@sanketpurandare
sanketpurandare marked this pull request as draft June 4, 2026 22:31
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/10 to main June 4, 2026 22:31
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/15 branch from fd55259 to 03cd299 Compare June 4, 2026 22:32
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/10 June 4, 2026 22:32
@sanketpurandare
sanketpurandare marked this pull request as ready for review June 4, 2026 22:32
pytorchmergebot pushed a commit that referenced this pull request Jun 5, 2026
Stacked PRs:
 * #183838
 * #186255
 * #183839
 * #183840
 * #183837
 * #184911
 * __->__#183545

--- --- ---

### [DTensor] Use explicit hints for unbacked sharding

DTensor sharding falls back to conservative behavior when a shard size is
unbacked because divisibility and sharding metadata often require Python
decisions. That is correct for arbitrary symbolic sizes, but it is too
conservative for tracing paths that explicitly override optimization hints and
know that a sharded dimension or strict-view split factor is stable.

This change only trusts explicit optimization hint overrides for those Python
decisions. When a hint selects a no-padding or shardable branch, the traced graph
still emits the symbolic torch._check for the correctness predicate, so runtime
values that satisfy the predicate continue to work and values that violate it
fail closed. The hint chooses the trace-time policy branch; it is not baked in as
a concrete tensor extent.

For _StridedShard, view propagation now preserves a symbolic split_factor when
the split factor came from symbolic shape propagation. The C++ placement still
needs an int64_t unroll count for list-based lowering, so the Python wrapper
stores the symbolic split factor separately and uses the explicit hint only as a
guarded unroll count. The equality assertion is deferred instead of directly
calling torch._check(symbol == hint), because the direct check immediately
refines the ShapeEnv replacement and destroys the symbolic split_factor
metadata we need to preserve.

Assisted by Codex.

Fixes #183678

Test Plan:

```bash
python -m pytest -q test/distributed/tensor/test_placement_types.py test/distributed/tensor/test_view_ops.py::TestViewOps::test_view_groups_unbacked_sharding_propagation
```

```bash
lintrunner --config=.lintrunner.toml torch/distributed/tensor/placement_types.py torch/distributed/tensor/_ops/_view_ops.py torch/distributed/tensor/_ops/utils.py test/distributed/tensor/test_placement_types.py test/distributed/tensor/test_view_ops.py
```

Pull Request resolved: #183545
Approved by: https://github.com/pianpwk
@sanketpurandare
sanketpurandare marked this pull request as draft June 5, 2026 20:59
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/10 to main June 5, 2026 20:59
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/15 branch from 03cd299 to e4899da Compare June 5, 2026 20:59
Graph-level chunking can expose tensor-parallel collective values through simple slice/cat reassembly before a matmul, or can feed reduce-scatter from an equivalent slice/cat form after a matmul. The existing micro-pipeline TP matcher only recognized the direct all-gather/matmul and matmul/reduce-scatter patterns, so these semantically equivalent graphs missed fusion.

Teach the all-gather and reduce-scatter matchers to recognize slice/cat forms that reassemble a single collective value without changing the TP communication contract. The replacement and erase logic remains scoped to the matched nodes, and the matmul multi-user guard still rejects users outside the matched reassembly.

Fixes #184833

Test Plan:

python test/distributed/tensor/parallel/test_micro_pipeline_tp.py MicroPipelineTPTest.test_find_all_gather_patterns MicroPipelineTPTest.test_find_reduce_scatter_patterns MicroPipelineTPTest.test_fuse_all_gather_matmul_slice_cat MicroPipelineTPTest.test_fuse_all_gather_matmul_slice_cat_trim MicroPipelineTPTest.test_fuse_matmul_reduce_scatter_slice_cat -v

lintrunner --config=.lintrunner.toml torch/_inductor/fx_passes/micro_pipeline_tp.py test/distributed/tensor/parallel/test_micro_pipeline_tp.py

stack-info: PR: #184911, branch: sanketpurandare/stack/15
@sanketpurandare

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

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 module: inductor release notes: distributed (dtensor) release notes category release notes: distributed (pipeline) release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Inductor][TP] Micro-pipeline TP fusion misses slice/cat collective patterns

3 participants