Skip to content

[Torch] Preserve PT2E per-channel-group quantization as LinalgExt ops - #25008

Merged
roberto-laudani merged 2 commits into
mainfrom
users/roberto-laudani/qdq-per-channel-group
Oct 14, 2026
Merged

roberto-laudani merged 2 commits into
mainfrom
users/roberto-laudani/qdq-per-channel-group

Conversation

@roberto-laudani

@roberto-laudani roberto-laudani commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Extends ConvertTorchQuantizationToLinalgExt to the PT2E quantized_decomposed per-channel-group quantize/dequantize ops. All granularities, including per-tensor and per-channel, derive their layout from a torchao-style block size and share one operand check. Bool zero points are treated as unsigned.

Part of #24862.

@roberto-laudani roberto-laudani self-assigned this Oct 7, 2026
@roberto-laudani
roberto-laudani force-pushed the users/roberto-laudani/qdq-per-channel-group branch from e15b536 to 52fcff2 Compare October 7, 2026 13:12
@roberto-laudani
roberto-laudani marked this pull request as draft October 7, 2026 13:20
@roberto-laudani
roberto-laudani force-pushed the users/roberto-laudani/qdq-per-channel-group branch 3 times, most recently from f4d9db0 to 322517e Compare October 12, 2026 07:29
@roberto-laudani roberto-laudani changed the title [Torch] Convert PT2E per-channel-group quantization to LinalgExt [Torch] Preserve PT2E per-channel-group quantization as LinalgExt ops Oct 12, 2026
@roberto-laudani
roberto-laudani marked this pull request as ready for review October 12, 2026 07:33

@ziereis ziereis 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.

Generally the approach looks fine to me. I'm generally not very happy with the axis/group_size split, thats also why we need so many special case if blocks. Depending on if the the per_token lowering adds another set of those we should maybe think of refactoring this a bit. However i would not do this right now.

I think some of the tests could be a bit more verbose and i have some smaller comments about duplicate verification/ verification in the wrong place. If these are addressed its good2go from my side.

@ziereis

ziereis commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

i just took a quick look at the PR for the per_tensor ops. I think better if we add something like:

https://github.com/pytorch/ao/blob/9d0c4946b11af5e484f3ac36d61ec970c40c68cf/torchao/quantization/quant_primitives.py#L414

to the PT2EQuantization struct and get rid of the "axis" and "groupSize" parameter and instead derive this from the named pt2e ops. This could then also be used by the per_token ops and ofc also the torchao-native ops as soon as they are ready.

@roberto-laudani
roberto-laudani force-pushed the users/roberto-laudani/qdq-per-channel-group branch 4 times, most recently from 512a5f1 to d22e898 Compare October 14, 2026 07:21
Convert quantized_decomposed.quantize_per_channel_group and
dequantize_per_channel_group to iree_linalg_ext.quantize_affine and
dequantize_affine, so later QDQ optimizations see the groups instead of
the floordiv-indexed arithmetic of Torch-to-Linalg.

LinalgExt parameter maps must be projected permutations, so the ops work
on the input with its last dimension split into groups, and the result
is collapsed back.

Ops that LinalgExt cannot express stay on the Torch-to-Linalg path, such
as groups that do not divide a static last dimension, bounds outside the
storage type, and quantize with scales narrower than 32 bits or than the
input. These checks only apply to the grouped ops, so per-tensor and
per-channel conversion is unchanged.

Dequantization matches the PT2E reference, except where the reference
overflows when subtracting the zero point in the storage type. The
reference quantizes by adding the zero point before rounding, so ties
with odd zero points differ, as they already do in Torch-to-Linalg.

Signed-off-by: Roberto Laudani <[email protected]>
@roberto-laudani
roberto-laudani force-pushed the users/roberto-laudani/qdq-per-channel-group branch 2 times, most recently from f09b638 to 7079f29 Compare October 14, 2026 14:14
@roberto-laudani
roberto-laudani force-pushed the users/roberto-laudani/qdq-per-channel-group branch from 7079f29 to 9ce7cea Compare October 14, 2026 14:50
@roberto-laudani

Copy link
Copy Markdown
Contributor Author

@ziereis thanks for the review. I addressed your comments. Could you have another look, please?

@roberto-laudani
roberto-laudani merged commit 8fe6062 into main Oct 14, 2026
60 checks passed
@roberto-laudani
roberto-laudani deleted the users/roberto-laudani/qdq-per-channel-group branch October 14, 2026 20:47
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