Commit 65908a6
Fix unsqueeze permutation adaptation in RemovePermutesAroundElementwiseOps (#21551)
Summary:
`_adapt_permute_across_view` and `permute_subgraph` disagreed about where an
unsqueeze's new dim lands in the un-permuted layout.
When the region walker crosses an unsqueeze, it has to (a) adapt the running
permutation to the new rank and (b) later rewrite the unsqueeze's `dim` arg
into un-permuted space. `permute_subgraph` does (b) as `permute[index]`, but
`_adapt_permute_across_view` did (a) by inserting `index` -- both as the shift
threshold and as the inserted value. The two only coincide when
`permute[index] == index`.
For example with `P = [0, 2, 1]` and an unsqueeze at index 1, the rewrite emits
`dim=2` while the adaptation produces `[0, 1, 3, 2]`; the permutation
consistent with `dim=2` is `[0, 2, 3, 1]`. Downstream nodes then get remapped
against a wrong permutation and the end-permute comparison no longer matches.
In practice that shows up as a missed optimisation -- the subgraph is rejected
-- but nothing guarantees the wrong permutation cannot coincidentally match an
end permute, so this is a correctness fix, not just a missed-match fix.
The squeeze branch immediately below already did this correctly
(`squeezed_value = permute[index]`, with a comment spelling out that the
position and the value are different things); only unsqueeze was inconsistent.
Note this pass is shared: the Cadence (opt_level=2) and Arm/TOSA subclasses
inherit the fixed behaviour. Their suites are covered below.
Reviewed By: digantdesai
Differential Revision: D1145082421 parent 488a69b commit 65908a6
2 files changed
Lines changed: 42 additions & 2 deletions
File tree
- backends/transforms
- test
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
153 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
154 | 161 | | |
155 | 162 | | |
156 | 163 | | |
| |||
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1034 | 1034 | | |
1035 | 1035 | | |
1036 | 1036 | | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
1037 | 1070 | | |
1038 | 1071 | | |
1039 | 1072 | | |
| |||
0 commit comments