Skip to content

[Torch] Preserve PT2E quantization as LinalgExt ops - #24918

Merged
ziereis merged 1 commit into
mainfrom
users/ziereis/qdq-torch-conversion
Oct 7, 2026
Merged

ziereis merged 1 commit into
mainfrom
users/ziereis/qdq-torch-conversion

Conversation

@ziereis

@ziereis ziereis commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Converts the typed PT2E quantized_decomposed per-tensor and per-channel quantize/dequantize ops to iree_linalg_ext.quantize_affine / dequantize_affine during Torch input conversion, before Torch-to-Linalg expands them into scalar arithmetic.

Ops LinalgExt cannot express (fp8 storage, non-constant bounds or axis, an axis outside the input rank, unknown dtypes) stay on the existing Torch-to-Linalg path. Well-formedness of the Torch ops is left to their verifiers.

Per-tensor scales are applied in f32 for both directions, matching Inductor, which computes in f32 and rounds once to the result dtype.

Part of #24862.

🤖 Generated with Claude Code

@ziereis
ziereis added this pull request to stack #24903 September 11, 2026 06:50
@ziereis ziereis changed the title users/ziereis/qdq torch conversion [Torch] Preserve PT2E quantization as LinalgExt ops Sep 11, 2026
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch from 6b7fe06 to f5477f8 Compare September 11, 2026 07:24
@ziereis
ziereis force-pushed the users/ziereis/qdq-torch-conversion branch from 009c66d to 38febbf Compare September 11, 2026 07:24
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch from f5477f8 to 2bcf3a1 Compare September 11, 2026 07:27
@ziereis
ziereis force-pushed the users/ziereis/qdq-torch-conversion branch from 38febbf to 6ca5cd6 Compare September 11, 2026 07:27
@Manewing
Manewing force-pushed the users/ziereis/qdq-reshape-propagation branch from 2bcf3a1 to 719cc19 Compare September 15, 2026 08:38
@Manewing
Manewing force-pushed the users/ziereis/qdq-torch-conversion branch from 6ca5cd6 to 4fd9b48 Compare September 15, 2026 08:38
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch from 719cc19 to 8c34330 Compare September 29, 2026 09:40
@ziereis
ziereis force-pushed the users/ziereis/qdq-torch-conversion branch from 4fd9b48 to 594d13e Compare September 29, 2026 10:10
@ziereis
ziereis removed this pull request from stack #24903 September 29, 2026 10:11
@ziereis
ziereis changed the base branch from users/ziereis/qdq-reshape-propagation to main September 29, 2026 10:11
roberto-laudani added a commit to roberto-laudani/iree-test-suites that referenced this pull request Oct 1, 2026
Adds end-to-end CPU quality regressions for MobileNetV2: the
float32 model, and an int8 variant quantized with PT2E and the ExecuTorch
XNNPACKQuantizer (int8 weights symmetric per channel, int8 activations
asymmetric per tensor). IREE compiles the committed
MLIR, fetches the externalized parameters and references from the Hugging Face
Hub (pinned by revision), and compares the output logits against PyTorch.

The PT2E test depends on iree-org/iree#24908 (torch-mlir update with typed
quantized_decomposed ops) and iree-org/iree#24918 (PT2E quantization as
LinalgExt ops).

Signed-off-by: Roberto Laudani <[email protected]>
roberto-laudani added a commit to roberto-laudani/iree-test-suites that referenced this pull request Oct 1, 2026
Adds end-to-end CPU quality regressions for MobileNetV2: the
float32 model, and an int8 variant quantized with PT2E and the ExecuTorch
XNNPACKQuantizer (int8 weights symmetric per channel, int8 activations
asymmetric per tensor). IREE compiles the committed
MLIR, fetches the externalized parameters and references from the Hugging Face
Hub (pinned by revision), and compares the output logits against PyTorch.

The PT2E test depends on iree-org/iree#24908 (torch-mlir update with typed
quantized_decomposed ops) and iree-org/iree#24918 (PT2E quantization as
LinalgExt ops).

Signed-off-by: Roberto Laudani <[email protected]>
@ziereis
ziereis force-pushed the users/ziereis/qdq-torch-conversion branch from bd712df to 13f30e3 Compare October 6, 2026 07:38
@ziereis
ziereis marked this pull request as ready for review October 6, 2026 08:15
@ziereis

ziereis commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@roberto-laudani Thanks for the review. I did quite a bunch of refactoring afterwards but i hope most of your comments stay addressed. Would be appreciated if you could take another look :)

@roberto-laudani

Copy link
Copy Markdown
Contributor

Hi @ziereis, thanks for the changes. I added two more comments. Other than that the PR looks good to me.

@ziereis
ziereis force-pushed the users/ziereis/qdq-torch-conversion branch from 13f30e3 to 1723899 Compare October 6, 2026 11:09
Convert the typed PT2E quantize_per_tensor, dequantize_per_tensor,
quantize_per_channel, and dequantize_per_channel ops to
iree_linalg_ext.quantize_affine and dequantize_affine before
Torch-to-Linalg expands them, so later QDQ optimizations keep the
scale, zero point, granularity, and range.

Ops LinalgExt cannot express, such as fp8 storage, non-constant bounds
or axis, an axis outside the input rank, and unknown dtypes, remain for
the Torch-to-Linalg lowering. Well-formedness of the Torch ops is left
to their verifiers.

Per-tensor scales are applied in f32 for both directions, matching
Inductor, which computes in f32 and rounds once to the result dtype.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Thomas Ziereis <[email protected]>
@ziereis
ziereis force-pushed the users/ziereis/qdq-torch-conversion branch from 1723899 to 0898322 Compare October 6, 2026 11:22
@roberto-laudani
roberto-laudani self-requested a review October 6, 2026 15:07
@ziereis
ziereis merged commit 4fc29b6 into main Oct 7, 2026
54 of 60 checks passed
@ziereis
ziereis deleted the users/ziereis/qdq-torch-conversion branch October 7, 2026 07:30
roberto-laudani added a commit that referenced this pull request Oct 15, 2026
Extends `ConvertTorchQuantizationToLinalgExt` (#24918) to
`quantized_decomposed.quantize_per_token` and `dequantize_per_token`.

Depends on #25008 and #25046.

Part of #24862.

Signed-off-by: Roberto Laudani <[email protected]>
@devtbi devtbi mentioned this pull request Oct 19, 2026
7 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants