Skip to content

Remove permutes around expand_copy; reject symbolic scalar inputs (#24742) - #24742

Merged
meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
pssrawat:export-D130138174
Nov 9, 2026
Merged

meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
pssrawat:export-D130138174

Conversation

@pssrawat

@pssrawat pssrawat commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

RemovePermutesAroundElementwiseOps stopped at aten.expand_copy.default, so a layout region containing a broadcast was cut in two and kept a permute pair on each side. A squeeze-and-excitation gate, a per-channel scale broadcast over the time axis and multiplied back in, puts an expand in the middle of exactly such a region.

expand_copy is now in the default permutable set, and update_expand_copy un-permutes its size argument the same way the other update_* methods remap their dims. Before reordering, it replaces each -1 with the concrete output size, keeping -1 only where that dim is symbolic: in a rank-growing expand, reordering could otherwise move a -1 onto a dim the expand adds, where -1 is invalid. With that, rank-growing expands of constants are remapped correctly and need no filter; non-constant lower-rank inputs are still rejected by the region's rank check.

The pass also crashed with AttributeError: 'SymInt' object has no attribute 'numel' when a region op took a symbolic argument, such as slice_copy with an end of y.shape[0], constant_pad_nd with a symbolic pad amount, or expand_copy with a symbolic size. The upstream walk reaches the sym_size node and calls .numel() on its SymInt value. Such inputs now reject the region. They cannot be skipped like numel-1 tensors: a sym_size can read a dim of a region tensor, which removing the permutes would change.

Authored with an AI coding assistant (Claude).

Reviewed By: mcremon-meta

Differential Revision: D130138174

@pytorch-bot

pytorch-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit c783436 with merge base 6605290 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 6, 2026
@meta-codesync

meta-codesync Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@pssrawat has exported this pull request. If you are a Meta employee, you can view the originating Diff in D130138174.

@pssrawat
pssrawat requested review from mcremon-meta and rascani and removed request for mcremon-meta November 6, 2026 18:11
@pssrawat pssrawat added the release notes: none Do not include this in the release notes label Nov 6, 2026
@meta-codesync meta-codesync Bot changed the title Remove permutes around expand_copy; reject symbolic scalar inputs Remove permutes around expand_copy; reject symbolic scalar inputs (#24742) Nov 6, 2026
pssrawat added a commit to pssrawat/executorch that referenced this pull request Nov 6, 2026
…torch#24742)

Summary:

`RemovePermutesAroundElementwiseOps` stopped at `aten.expand_copy.default`, so a layout region containing a broadcast was cut in two and kept a permute pair on each side. A squeeze-and-excitation gate, a per-channel scale broadcast over the time axis and multiplied back in, puts an expand in the middle of exactly such a region.

`expand_copy` is now in the default permutable set, and `update_expand_copy` un-permutes its size argument the same way the other `update_*` methods remap their dims. Before reordering, it replaces each `-1` with the concrete output size, keeping `-1` only where that dim is symbolic: in a rank-growing expand, reordering could otherwise move a `-1` onto a dim the expand adds, where `-1` is invalid. With that, rank-growing expands of constants are remapped correctly and need no filter; non-constant lower-rank inputs are still rejected by the region's rank check.

The pass also crashed with `AttributeError: 'SymInt' object has no attribute 'numel'` when a region op took a symbolic argument, such as `slice_copy` with an end of `y.shape[0]`, `constant_pad_nd` with a symbolic pad amount, or `expand_copy` with a symbolic size. The upstream walk reaches the `sym_size` node and calls `.numel()` on its `SymInt` value. Such inputs now reject the region. They cannot be skipped like numel-1 tensors: a `sym_size` can read a dim of a region tensor, which removing the permutes would change.

Authored with an AI coding assistant (Claude).

Differential Revision: D130138174
pssrawat added a commit to pssrawat/executorch that referenced this pull request Nov 6, 2026
…torch#24742)

Summary:

`RemovePermutesAroundElementwiseOps` stopped at `aten.expand_copy.default`, so a layout region containing a broadcast was cut in two and kept a permute pair on each side. A squeeze-and-excitation gate, a per-channel scale broadcast over the time axis and multiplied back in, puts an expand in the middle of exactly such a region.

`expand_copy` is now in the default permutable set, and `update_expand_copy` un-permutes its size argument the same way the other `update_*` methods remap their dims. Before reordering, it replaces each `-1` with the concrete output size, keeping `-1` only where that dim is symbolic: in a rank-growing expand, reordering could otherwise move a `-1` onto a dim the expand adds, where `-1` is invalid. With that, rank-growing expands of constants are remapped correctly and need no filter; non-constant lower-rank inputs are still rejected by the region's rank check.

The pass also crashed with `AttributeError: 'SymInt' object has no attribute 'numel'` when a region op took a symbolic argument, such as `slice_copy` with an end of `y.shape[0]`, `constant_pad_nd` with a symbolic pad amount, or `expand_copy` with a symbolic size. The upstream walk reaches the `sym_size` node and calls `.numel()` on its `SymInt` value. Such inputs now reject the region. They cannot be skipped like numel-1 tensors: a `sym_size` can read a dim of a region tensor, which removing the permutes would change.

Authored with an AI coding assistant (Claude).

Differential Revision: D130138174
…torch#24742)

Summary:

`RemovePermutesAroundElementwiseOps` stopped at `aten.expand_copy.default`, so a layout region containing a broadcast was cut in two and kept a permute pair on each side. A squeeze-and-excitation gate, a per-channel scale broadcast over the time axis and multiplied back in, puts an expand in the middle of exactly such a region.

`expand_copy` is now in the default permutable set, and `update_expand_copy` un-permutes its size argument the same way the other `update_*` methods remap their dims. Before reordering, it replaces each `-1` with the concrete output size, keeping `-1` only where that dim is symbolic: in a rank-growing expand, reordering could otherwise move a `-1` onto a dim the expand adds, where `-1` is invalid. With that, rank-growing expands of constants are remapped correctly and need no filter; non-constant lower-rank inputs are still rejected by the region's rank check.

The pass also crashed with `AttributeError: 'SymInt' object has no attribute 'numel'` when a region op took a symbolic argument, such as `slice_copy` with an end of `y.shape[0]`, `constant_pad_nd` with a symbolic pad amount, or `expand_copy` with a symbolic size. The upstream walk reaches the `sym_size` node and calls `.numel()` on its `SymInt` value. Such inputs now reject the region. They cannot be skipped like numel-1 tensors: a `sym_size` can read a dim of a region tensor, which removing the permutes would change.

Authored with an AI coding assistant (Claude).

Reviewed By: mcremon-meta

Differential Revision: D130138174
@meta-codesync
meta-codesync Bot merged commit dd38e81 into pytorch:main Nov 9, 2026
212 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants