Commit 750bdb5
[LINALG] Fix: Incorrect linalg lowering for aten.convolution_transpose with negative effective padding (#4369)
### **The Bug**
The `torch-to-linalg` lowering for `aten.convolution` (with
`transposed=true`) incorrectly handles cases where the effective padding
is negative. The logic for this is contained in
`createTransposedInputPadding`.
The original implementation had two critical flaws:
**Incorrect Math**: The logic block for negative padding (if
(anyDimensionPaddingIsNegative)) attempted to "pre-crop" the input
tensor before un-striding. The math used to calculate these slice
offsets and sizes was incorrect, resulting in `tensor.extract_slice`
operations with out-of-bounds offsets and negative sizes, causing the
compiler to fail.
**Failed "Mixed-Mode**" **Logic**: The code was built on an
"all-or-nothing" assumption. It failed to handle "mixed-mode" padding,
where one spatial dimension required padding (positive offset) while
another required cropping (negative offset). It would enter the negative
padding path and apply cropping logic to all dimensions, leading to
out-of-bounds errors when it tried to crop a dimension that should have
been padded.
### **The Fix**
This patch refactors the logic into two clean, robust paths:
**All-Padding Path (else block):**
Trigger: All spatial dimensions have an effective padding offset >= 0.
Action: Retains the original, efficient "fast path." It uses a single
`tensor.insert_slice` to perform both un-striding (with strides) and
padding (with offsets) in one operation.
**Safe Path (if (anyDimensionPaddingIsNegative) block):**
Trigger: At least one spatial dimension has a negative effective padding
offset.
Action: This path is now a unified, robust 3-step process that correctly
handles both all-crop and mixed-mode scenarios:
Create "Super-Tensor": It computes a maxSizes tensor, which is the
"union" of the padded and un-strided sizes (i.e., max(innerSize,
outerSize) for each dimension).
Pad & Un-stride: It performs a single `tensor.insert_slice` of the
original input into this maxSizes tensor. This one operation correctly
applies all positive padding (via insertSliceOffsets) and un-striding
(via strideIndexValues).
Crop: It performs a final `tensor.extract_slice` to crop the maxSizes
tensor down to the final outerSizes. This correctly applies all negative
padding (via extractSliceOffsets).
This new logic resolves all known failure cases and is validated by the
new TransposedConv{1,2,3}dNegativePadding test cases, which specifically
target this functionality.
---------
Co-authored-by: Hariprasad Ravishankar <[email protected]>
Co-authored-by: Hariprasad Ravishankar <[email protected]>1 parent 8d563af commit 750bdb5
File tree
4 files changed
+225
-36
lines changed- lib/Conversion/TorchToLinalg
- projects/pt1
- e2e_testing
- python/torch_mlir_e2e_test/test_suite
- test/Conversion/TorchToLinalg
4 files changed
+225
-36
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1538 | 1538 | | |
1539 | 1539 | | |
1540 | 1540 | | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
1541 | 1560 | | |
1542 | 1561 | | |
1543 | 1562 | | |
| |||
1551 | 1570 | | |
1552 | 1571 | | |
1553 | 1572 | | |
1554 | | - | |
1555 | | - | |
1556 | | - | |
1557 | | - | |
1558 | | - | |
1559 | | - | |
1560 | | - | |
1561 | | - | |
| 1573 | + | |
1562 | 1574 | | |
1563 | 1575 | | |
1564 | 1576 | | |
1565 | 1577 | | |
1566 | 1578 | | |
1567 | 1579 | | |
| 1580 | + | |
1568 | 1581 | | |
1569 | 1582 | | |
1570 | 1583 | | |
1571 | 1584 | | |
| 1585 | + | |
1572 | 1586 | | |
1573 | 1587 | | |
1574 | 1588 | | |
1575 | 1589 | | |
1576 | 1590 | | |
1577 | 1591 | | |
1578 | 1592 | | |
| 1593 | + | |
| 1594 | + | |
1579 | 1595 | | |
| 1596 | + | |
| 1597 | + | |
1580 | 1598 | | |
| 1599 | + | |
| 1600 | + | |
1581 | 1601 | | |
1582 | 1602 | | |
1583 | 1603 | | |
| |||
1587 | 1607 | | |
1588 | 1608 | | |
1589 | 1609 | | |
1590 | | - | |
1591 | | - | |
| 1610 | + | |
| 1611 | + | |
1592 | 1612 | | |
1593 | 1613 | | |
1594 | 1614 | | |
1595 | | - | |
1596 | | - | |
1597 | | - | |
1598 | | - | |
1599 | | - | |
1600 | | - | |
1601 | 1615 | | |
1602 | 1616 | | |
1603 | 1617 | | |
1604 | | - | |
1605 | 1618 | | |
1606 | 1619 | | |
1607 | 1620 | | |
1608 | 1621 | | |
1609 | | - | |
1610 | 1622 | | |
1611 | 1623 | | |
1612 | 1624 | | |
1613 | 1625 | | |
1614 | 1626 | | |
1615 | 1627 | | |
1616 | | - | |
1617 | 1628 | | |
1618 | | - | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
1619 | 1654 | | |
1620 | 1655 | | |
1621 | | - | |
1622 | | - | |
| 1656 | + | |
1623 | 1657 | | |
1624 | | - | |
1625 | | - | |
1626 | | - | |
1627 | | - | |
1628 | | - | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
1629 | 1680 | | |
1630 | 1681 | | |
1631 | 1682 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3267 | 3267 | | |
3268 | 3268 | | |
3269 | 3269 | | |
| 3270 | + | |
3270 | 3271 | | |
3271 | 3272 | | |
3272 | 3273 | | |
| |||
3961 | 3962 | | |
3962 | 3963 | | |
3963 | 3964 | | |
| 3965 | + | |
| 3966 | + | |
3964 | 3967 | | |
| 3968 | + | |
3965 | 3969 | | |
3966 | 3970 | | |
3967 | 3971 | | |
| |||
5039 | 5043 | | |
5040 | 5044 | | |
5041 | 5045 | | |
| 5046 | + | |
| 5047 | + | |
5042 | 5048 | | |
| 5049 | + | |
5043 | 5050 | | |
5044 | 5051 | | |
5045 | 5052 | | |
| |||
Lines changed: 101 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1988 | 1988 | | |
1989 | 1989 | | |
1990 | 1990 | | |
1991 | | - | |
| 1991 | + | |
1992 | 1992 | | |
1993 | 1993 | | |
1994 | 1994 | | |
| |||
2002 | 2002 | | |
2003 | 2003 | | |
2004 | 2004 | | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
2005 | 2071 | | |
2006 | 2072 | | |
2007 | 2073 | | |
| |||
2034 | 2100 | | |
2035 | 2101 | | |
2036 | 2102 | | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
2037 | 2135 | | |
2038 | 2136 | | |
2039 | 2137 | | |
| |||
2052 | 2150 | | |
2053 | 2151 | | |
2054 | 2152 | | |
2055 | | - | |
| 2153 | + | |
2056 | 2154 | | |
2057 | | - | |
| 2155 | + | |
2058 | 2156 | | |
2059 | 2157 | | |
2060 | 2158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
161 | 166 | | |
162 | 167 | | |
163 | 168 | | |
| |||
174 | 179 | | |
175 | 180 | | |
176 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
0 commit comments