Skip to content

XNNPACK: Fix cat qparams for quantized ViT token paths#20280

Open
mansnils wants to merge 1 commit into
pytorch:mainfrom
mansnils:xnnpack
Open

XNNPACK: Fix cat qparams for quantized ViT token paths#20280
mansnils wants to merge 1 commit into
pytorch:mainfrom
mansnils:xnnpack

Conversation

@mansnils

@mansnils mansnils commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

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

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>
@mansnils mansnils requested a review from GregoryComer June 15, 2026 12:43
@mansnils mansnils added the module: xnnpack Issues related to xnnpack delegation and the code under backends/xnnpack/ label Jun 15, 2026
@mansnils mansnils requested a review from digantdesai as a code owner June 15, 2026 12:43
Copilot AI review requested due to automatic review settings June 15, 2026 12:43
@mansnils mansnils added partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm ciflow/trunk labels Jun 15, 2026
@pytorch-bot

pytorch-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

🔗 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 Failures

As of commit 194bb19 with merge base e88fd04 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 15, 2026
@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 cat quantization annotation to select a better shared-qparam “source” input (prefer inputs tracing to annotated activation qparams).
  • Treat aten.transpose.int and aten.reshape.default as qparam-preserving ops for annotation propagation.
  • Add a quantized XNNPACK regression test covering conv -> flatten -> transpose -> cat -> add consistent 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: xnnpack Issues related to xnnpack delegation and the code under backends/xnnpack/ partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants