Skip to content

Fix unsafe copies in EXIR and permute transforms#19873

Open
oscarandersson8218 wants to merge 1 commit into
pytorch:mainfrom
oscarandersson8218:fix_unsafe_deep_copies
Open

Fix unsafe copies in EXIR and permute transforms#19873
oscarandersson8218 wants to merge 1 commit into
pytorch:mainfrom
oscarandersson8218:fix_unsafe_deep_copies

Conversation

@oscarandersson8218
Copy link
Copy Markdown
Collaborator

@oscarandersson8218 oscarandersson8218 commented May 29, 2026

Replace deepcopy-based copies of shape lists with shallow container copies in paths that can carry torch.SymInt values from fake tensor metadata. This is safe as torch.Size is immutable, so creating a shallow list copy of it is safe: we can insert/delete elements in the new list without affecting the original shape.

This fixes symbolic-shape failures in exir.tensor.stride_from_dim_order() and in PostponePermuteOpBelowSqueezeOrUnsqueezeLikeView, where deepcopy() could crash while handling SymInt-backed shapes. The error that was produced: "RuntimeError: Cannot access data pointer of Tensor (e.g. FakeTensor, FunctionalTensor). If you're using torch.compile/export/fx, it is likely that we are erroneously tracing into a custom kernel. To fix this, please wrap the custom kernel into an opaque custom op. Please see the following for details:
https://pytorch.org/tutorials/advanced/custom_ops_landing_page.html"

Add focused regression coverage for both cases: one test for stride computation with symbolic sizes, and one dynamic-shape edge-graph test for the permute/view transform pass.

cc @digantdesai @freddan80 @per @zingo @mansnils @Sebastian-Larsson @robell @rascani

Replace deepcopy-based copies of shape lists with shallow container
copies in paths that can carry torch.SymInt values from fake tensor
metadata. This is safe as torch.Size is immutable, so creating a shallow
list copy of it is safe: we can insert/delete elements in the new list
without affecting the original shape.

This fixes symbolic-shape failures in
exir.tensor.stride_from_dim_order() and in
PostponePermuteOpBelowSqueezeOrUnsqueezeLikeView, where deepcopy() could
crash while handling SymInt-backed shapes. The error that was produced:
"RuntimeError: Cannot access data pointer of Tensor (e.g.
FakeTensor, FunctionalTensor). If you're using torch.compile/export/fx,
it is likely that we are erroneously tracing into a custom kernel. To
fix this, please wrap the custom kernel into an opaque custom op. Please
see the following for details:
https://pytorch.org/tutorials/advanced/custom_ops_landing_page.html"

Add focused regression coverage for both cases: one test for stride
computation with symbolic sizes, and one dynamic-shape edge-graph test
for the permute/view transform pass.

Signed-off-by: Oscar Andersson <oscar.andersson@arm.com>
Change-Id: I4eb2cae7b05f988edee570decb1307a671af4c2a
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 29, 2026

🔗 Helpful Links

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

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

❗ 2 Active SEVs

There are 2 currently active SEVs. If your PR is affected, please view them below:

❌ 2 New Failures, 4 Unrelated Failures

As of commit 8f91cfb with merge base b0441b5 (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following jobs 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.

@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 May 29, 2026
@oscarandersson8218 oscarandersson8218 added help wanted Extra attention is needed partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm ciflow/trunk release notes: none Do not include this in the release notes labels May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. help wanted Extra attention is needed partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant