Repository navigation
Commit cc9acaa
authored
Emit Conv1d output layout copies after their squeeze (#24256)
Summary:
On the explicit-layout pass list, a Conv1d is lowered as a Conv2d with a unit height. `CortexMReplaceOpsWithChannelsLastVariants` wrapped each convolution output in a rank-4 NHWC-to-NCHW layout copy, followed by the squeeze that `ConvertConv1dToConv2dPass` adds to get back to rank 3. `RemovePermutesAroundElementwiseOps` cannot match a rank-3 region against a rank-4 copy behind a squeeze, so in residual or chained Conv1d blocks the layout copies between convolutions survived as transposes.
`CortexMReplaceOpsWithChannelsLastVariants` now emits such an output as a squeeze followed by a rank-3 layout copy (`[0, 2, 1]`), reusing the existing squeeze node. It does this only when the convolution's sole user is a `squeeze_copy.dim(conv, 2)` with a rank-3 result; every other output keeps the rank-4 copy.
One side effect: when user code transposes a Conv1d output around elementwise ops, the layout copy and the user's `transpose(1, 2)` are now directly adjacent. `RemovePermutesAroundElementwiseOps` cannot merge adjacent permutes and cancels the user's two transposes against each other instead, so both layout copies survive: Conv1d -> transpose -> relu -> transpose -> Conv1d gets four transposes instead of two. The next change fixes this by running `FuseCascadedTransposeOrPermuteOps` before `RemovePermutesAroundElementwiseOps`.
A Conv1d -> tanh -> Conv1d -> add -> relu -> Conv1d chain now lowers with only the two boundary transposes instead of six.
This makes more regions reachable for `RemovePermutesAroundElementwiseOps`, including regions with lower-rank constants, such as a `[C, L]` or `[L]` buffer added to two Conv1d outputs. The pass's compensation for those constants is fixed separately in the shared pass, and this change depends on that fix.
Authored with an AI coding assistant (Claude).
Differential Revision: D128001279
Pull Request resolved: #242561 parent 8d34671 commit cc9acaa
2 files changed
Lines changed: 103 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | | - | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
77 | 90 | | |
78 | 91 | | |
79 | 92 | | |
| |||
100 | 113 | | |
101 | 114 | | |
102 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
103 | 140 | | |
104 | 141 | | |
105 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| |||
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
91 | 106 | | |
92 | 107 | | |
93 | 108 | | |
| |||
669 | 684 | | |
670 | 685 | | |
671 | 686 | | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
0 commit comments