Fix IndexError in RemovePermutesAroundElementwiseOps for rank-mismatched views (#19713)#19713
Fix IndexError in RemovePermutesAroundElementwiseOps for rank-mismatched views (#19713)#19713mcremon-meta wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19713
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ You can merge normally! (2 Unrelated Failures), 1 Unclassified FailureAs of commit 8b56e75 with merge base da01860 ( UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@mcremon-meta has exported this pull request. If you are a Meta employee, you can view the originating Diff in D105787161. |
This PR needs a
|
…hed views (#19713) Summary: Fix an IndexError crash in the RemovePermutesAroundElementwiseOps compiler pass that occurs when a squeeze/unsqueeze view_copy node is included in a subgraph via upstream traversal with a permutation whose rank does not match the view input tensor rank. The bug manifests as `IndexError: tuple index out of range` in `update_view_copy` at the line: ``` unpermuted_in = [in_shape[inverse_permute[i]] for i in range(len(in_shape))] ``` because `inverse_permute` contains indices from a rank-N permutation but `in_shape` has fewer than N dimensions. The fix adds a validation guard at the top of `permute_subgraph()` that checks all view_copy nodes for rank consistency between their `node_start_permute` and their input tensor shape. If a mismatch is found, the entire subgraph optimisation is skipped, preserving graph correctness. The return type of `permute_subgraph` is changed from `None` to `bool` so the caller only marks the graph as modified when the subgraph was actually transformed. Also adds a regression test that constructs the exact graph pattern (upstream unsqueeze view_copy with a 2D constant feeding into a 3D permuted add) that triggered the crash. Reviewed By: ethansfng Differential Revision: D105787161
64d5570 to
8b56e75
Compare
Summary:
Fix an IndexError crash in the RemovePermutesAroundElementwiseOps
compiler pass that occurs when a squeeze/unsqueeze view_copy node is
included in a subgraph via upstream traversal with a permutation whose
rank does not match the view input tensor rank.
The bug manifests as
IndexError: tuple index out of rangeinupdate_view_copyat the line:because
inverse_permutecontains indices from a rank-N permutationbut
in_shapehas fewer than N dimensions.The fix adds a validation guard at the top of
permute_subgraph()thatchecks all view_copy nodes for rank consistency between their
node_start_permuteand their input tensor shape. If a mismatch isfound, the entire subgraph optimisation is skipped, preserving graph
correctness. The return type of
permute_subgraphis changed fromNonetoboolso the caller only marks the graph as modified when thesubgraph was actually transformed.
Also adds a regression test that constructs the exact graph pattern
(upstream unsqueeze view_copy with a 2D constant feeding into a 3D
permuted add) that triggered the crash.
Reviewed By: ethansfng
Differential Revision: D105787161