Fix quantized Conv1d same padding with even kernels in XNNPACK#20734
Fix quantized Conv1d same padding with even kernels in XNNPACK#20734SakshamKapoor2911 wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20734
Note: Links to docs will display an error until the docs builds have been completed.
|
|
|
There was a problem hiding this comment.
Pull request overview
This PR fixes an XNNPACK delegation/runtime correctness issue for statically-quantized nn.Conv1d(padding="same") with even kernel sizes by folding the explicit temporal constant_pad_nd into asymmetric Conv2d padding during Conv1d→Conv2d lowering, and ensuring the serialized graph’s metadata matches the folded asymmetric padding.
Changes:
- Extend XNNPACK partitioning and Conv1d unsqueeze lowering to absorb temporal-only zero
constant_pad_ndinto the quantized Conv1d partition and fold it into asymmetricxnnpack_input_padding. - Teach Conv2d serialization to use folded asymmetric padding metadata when present, and add a late pass to repair Conv1d folded-pad tensor metadata after retracing passes.
- Add a regression test covering quantized Conv1d even-kernel
padding="same".
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| backends/xnnpack/test/ops/test_conv1d.py | Adds a regression test for quantized Conv1d even-kernel padding="same" and factors out calibration sample generation. |
| backends/xnnpack/partition/config/gemm_configs.py | Extends convolution activation-dependency discovery to include temporal-only zero constant_pad_nd for quantized Conv1d so it can be partitioned/delegated. |
| backends/xnnpack/operators/op_conv2d.py | Uses folded asymmetric xnnpack_input_padding metadata (top/right/bottom/left) when present instead of symmetric ATen padding args. |
| backends/xnnpack/_passes/conv1d_unsqueeze_pass.py | Folds eligible temporal-only constant_pad_nd into asymmetric input padding during Conv1d→Conv2d lowering and adds a pass to restore correct tensor metadata for folded-pad Conv1d. |
| backends/xnnpack/_passes/init.py | Registers the new folded-pad metadata repair pass in the default XNNPACK pass pipeline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
❌ 🤖 pytorchbot command failed: |
|
@pytorchbot label "release notes: xnnpack" |
Fixes #20558.
Related to #20553.
Summary
Quantized
nn.Conv1d(..., padding="same")with an even kernel exports as:XNNPACK's Conv1d lowering maps Conv1d through Conv2d by inserting an extra width dimension. For even-kernel same-padding, the explicit temporal pad has to be represented as asymmetric Conv2d input padding after that 1d-to-2d mapping. Otherwise the Conv1d case either remains partially undelegated or reaches XNNPACK with mismatched output metadata and fails/produces incorrect output.
This PR:
constant_pad_ndinto the quantized Conv1d partition,padding="same".Relationship to #20553
#20553 folds
constant_pad_ndinto convolution input padding for the Conv2d path. I tested its current head (a04093bba2766afe609ef325737effdd01c3c4ad) against the Conv1d repro from #20558. The odd-kernel case works, but the even-kernel Conv1d case still fails at runtime withxnn_status_invalid_parameter.This PR handles the Conv1d-specific path where the temporal dimension is later mapped to Conv2d height and where metadata must be corrected after XNNPACK passes retrace from symmetric ATen conv args.
I noticed #20558 is assigned to @JakeStevens; happy to adapt or defer if there is already an internal Conv1d fix in flight.
Test plan
Local note: this checkout does not expose
src/executorch/exir/_serialize/program.fbsas a package resource, soto_executorch()pytest runs used a temporarysitecustomize.pyshim that redirects missing FlatBuffer resource reads to reposchema/. The manual repro uses the same schema-resource workaround. CI/dev install should package these resources normally.Manual quantized Conv1d repro on patched main:
Additional manual quantized Conv1d same-padding matrix:
Commands run: