Commit 10d3009
Fix quantized Conv1d same padding with even kernels in XNNPACK (#20734)
Fixes #20558.
Related to #20553.
## Summary
Quantized `nn.Conv1d(..., padding="same")` with an even kernel exports
with
asymmetric padding (unequal left/right amounts), which cannot be folded
into
the convolution's symmetric padding field. The original pad-folding
approach
in this PR was replaced with the explicit-PAD approach from #20553:
- **InsertPadQDQPass** — inserts implicit quantize/dequantize pairs
after
constant_pad_nd nodes in quantized contexts so they serialize as
quantized
static pads. Refactored with additional guard checks (pad_value,
pad_amounts,
negative amounts) and correct idempotency.
- **ConvolutionConfig._get_act_deps** — pulls zero-valued
constant_pad_nd nodes
(and their QDQ chain if InsertPadQDQPass already ran) into the
convolution's
partition for both 1D and 2D convs. The merged method replaces separate
1D
and 2D implementations that existed on this branch.
- **Regression test** — quantized Conv1d even-kernel same-padding
covering both
symmetric and asymmetric pad cases, validated by numerical comparison.
- Removed unrelated __init__.py re-ordering and no-op
conv1d_unsqueeze_pass
changes.
With these changes, an even-kernel `padding="same"` conv1d graph:
```
dequant -> constant_pad_nd -> convolution
```
becomes (after XNNPACK preprocessing and partitioning):
```
[dequant -> pad -> q -> dq -> conv] (single XNNPACK delegate)
```
## Test plan
```
python -m pytest backends/xnnpack/test/ops/test_conv1d.py -q
# 7 passed (1 new regression test with 4 subTests)
python -m pytest backends/xnnpack/test/ops/test_conv2d.py -q
# 32 passed
python -m pytest backends/xnnpack/test/passes/test_insert_pad_qdq.py -q
# 3 passed
python -m pytest backends/xnnpack/test/ops/test_static_constant_pad.py -q
# 8 passed
lintrunner -a
# No lint issues
```
cc @GregoryComer @digantdesai @cbilgin @JakeStevens @freddan80 @per
@zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani
---------
Co-authored-by: Jacob Stevens <stevens.jacob1492@gmail.com>1 parent ab4271f commit 10d3009
3 files changed
Lines changed: 141 additions & 80 deletions
File tree
- backends/xnnpack
- _passes
- partition/config
- test/ops
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
10 | 16 | | |
11 | 17 | | |
12 | 18 | | |
13 | 19 | | |
14 | 20 | | |
15 | 21 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 33 | + | |
55 | 34 | | |
56 | | - | |
| 35 | + | |
| 36 | + | |
57 | 37 | | |
58 | | - | |
59 | | - | |
| 38 | + | |
| 39 | + | |
60 | 40 | | |
61 | 41 | | |
62 | 42 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
72 | 49 | | |
73 | 50 | | |
74 | 51 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
79 | 58 | | |
80 | 59 | | |
81 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
82 | 86 | | |
83 | 87 | | |
84 | | - | |
| 88 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | 400 | | |
408 | 401 | | |
409 | 402 | | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | 403 | | |
| 404 | + | |
420 | 405 | | |
421 | 406 | | |
422 | 407 | | |
423 | | - | |
| 408 | + | |
424 | 409 | | |
425 | 410 | | |
426 | | - | |
427 | 411 | | |
428 | | - | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
429 | 419 | | |
430 | | - | |
431 | | - | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
432 | 429 | | |
433 | 430 | | |
434 | 431 | | |
435 | 432 | | |
436 | 433 | | |
437 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
438 | 442 | | |
439 | 443 | | |
440 | 444 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
93 | 111 | | |
94 | 112 | | |
95 | 113 | | |
| |||
102 | 120 | | |
103 | 121 | | |
104 | 122 | | |
105 | | - | |
106 | | - | |
107 | | - | |
| 123 | + | |
108 | 124 | | |
109 | 125 | | |
110 | 126 | | |
| |||
160 | 176 | | |
161 | 177 | | |
162 | 178 | | |
| 179 | + | |
| 180 | + | |
| 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 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
163 | 216 | | |
164 | 217 | | |
165 | 218 | | |
| |||
0 commit comments