XNNPACK: Fix cat qparams for quantized ViT token paths#20280
Conversation
Bug: Cat annotation always used the first input as the shared qparam source. In DeiT Tiny, the first input to token concatenation is the class-token path: cls_token -> expand -> cat The patch-token path is a later cat input: conv -> flatten -> transpose -> cat The conv output has annotated activation qparams, and flatten/transpose are qparam-preserving view/layout ops. They should carry the same qparams with SharedQuantizationSpec. Anchoring cat qparams on the class-token path can leave the patch-token static transpose with different input/output qparams. XNNPACK rejects this during runtime initialization because static transpose only reorders bytes. Fix: Choose the first cat input that traces through qparam-preserving ops to annotated output qparams, falling back to the first input otherwise. Also propagate shared qparams through reshape and transpose so static transpose nodes keep identical input and output qparams. Add a quantized XNNPACK regression covering conv, flatten, transpose, cat, and add. Change-Id: I86fafd584c1cb561bd2d4444ea70c1a1b0650066 Signed-off-by: Måns Nilsson <mans.nilsson@arm.com>
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20280
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 New FailuresAs of commit 194bb19 with merge base e88fd04 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a quantization annotation bug in the XNNPACK backend where cat shared quantization parameters were always anchored on the first input, which can be incorrect for quantized ViT token concatenation patterns (e.g., DeiT Tiny). It adjusts the cat qparam source selection to prefer an input that traces through qparam-preserving ops to an already-annotated activation producer, and extends qparam propagation through additional view/layout ops to keep static transpose nodes’ input/output qparams identical.
Changes:
- Update
catquantization annotation to select a better shared-qparam “source” input (prefer inputs tracing to annotated activation qparams). - Treat
aten.transpose.intandaten.reshape.defaultas qparam-preserving ops for annotation propagation. - Add a quantized XNNPACK regression test covering
conv -> flatten -> transpose -> cat -> addconsistent with ViT token paths.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| backends/xnnpack/quantizer/xnnpack_quantizer_utils.py | Improves cat qparam-source selection and extends qparam propagation through transpose/reshape. |
| backends/xnnpack/test/ops/test_cat.py | Adds a quantized regression test reproducing the ViT-style token concat path and validating successful lowering/execution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Bug: Cat annotation always used the first input as the shared qparam source. In DeiT Tiny, the first input to token concatenation is the class-token path:
cls_token -> expand -> cat
The patch-token path is a later cat input:
conv -> flatten -> transpose -> cat
The conv output has annotated activation qparams, and flatten/transpose are qparam-preserving view/layout ops. They should carry the same qparams with SharedQuantizationSpec. Anchoring cat qparams on the class-token path can leave the patch-token static transpose with different input/output qparams. XNNPACK rejects this during runtime initialization because static transpose only reorders bytes.
Fix: Choose the first cat input that traces through qparam-preserving ops to annotated output qparams, falling back to the first input otherwise. Also propagate shared qparams through reshape and transpose so static transpose nodes keep identical input and output qparams.
Add a quantized XNNPACK regression covering conv, flatten, transpose, cat, and add.
cc @GregoryComer @digantdesai @cbilgin @freddan80 @per @zingo @oscarandersson8218 @Sebastian-Larsson @robell @rascani