Skip to content

[LinalgExt] Canonicalize zero zero-points in affine QDQ ops - #24905

Merged
Manewing merged 1 commit into
mainfrom
users/ziereis/qdq-drop-zero-zp
Sep 23, 2026
Merged

Manewing merged 1 commit into
mainfrom
users/ziereis/qdq-drop-zero-zp

Conversation

@ziereis

@ziereis ziereis commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Canonicalizes iree_linalg_ext.quantize_affine and iree_linalg_ext.dequantize_affine by removing a zero-point operand when its constant value is zero in every element. The operations then expose symmetric quantization directly, allowing decomposition to omit zero-point arithmetic and the integer-contraction rewrite to skip the corresponding correction terms.

Handles scalar constants, tensor splats, dense tensors, and resource-backed tensor constants. Removing the operand also removes its indexing map and zp_unsigned attribute while preserving the remaining operation attributes. Tests cover these constant representations, nonzero values that must remain, and preservation of the operation's other parameters.

Builds on #24902 in the affine QDQ stack. Part of #24862.

@ziereis
ziereis added this pull request to stack #24903 September 10, 2026 07:06
@ziereis ziereis changed the title [LinalgExt] Drop a provably zero zero_point from the quantization ops [LinalgExt] Canonicalize zero zero-points in affine QDQ ops Sep 10, 2026
@ziereis
ziereis force-pushed the users/ziereis/qdq-drop-zero-zp branch 2 times, most recently from 7e83cea to f6ef8a2 Compare September 10, 2026 07:26
@ziereis
ziereis force-pushed the users/ziereis/qdq-drop-zero-zp branch from f6ef8a2 to abdb4d4 Compare September 11, 2026 06:37
@Manewing
Manewing force-pushed the users/ziereis/qdq-drop-zero-zp branch from abdb4d4 to 9290c37 Compare September 15, 2026 08:38
@Manewing
Manewing marked this pull request as ready for review September 22, 2026 11:21
Base automatically changed from users/ziereis/qdq-integer-contractions to main September 22, 2026 13:43
A dequantize whose zero point is zero is symmetric, and every consumer
benefits from seeing it that way: the QDQ to integer rewrite skips a
whole correction term, and the decomposition skips a subtraction.

Quantizers spell a symmetric zero point as a splat, as an explicit
tensor of zeros, or, once the model is frozen, as a resource blob whose
bytes live outside the attribute. isKnownZero answers a splat from its
one stored element and everything else from raw bytes: for an integer
tensor, all bytes zero is equivalent to all elements zero whatever the
width and packing, so no element is materialized as an APInt and the
resource case needs no per width decoding. Padding bytes can only make
the answer a conservative false.

The element type is not rechecked. The only caller passes a zero_point
the op verifier has already established to be an integer.

zero_point is the only optional operand, so the ops carry no operand
segment attribute and the drop is an in place mutation: clear the
operand, drop its indexing map, remove zp_unsigned. Everything else the
op carries is preserved by construction rather than by an attribute
copy that would have to be revisited whenever an attribute is added.

Signed-off-by: Thomas Ziereis <[email protected]>
Signed-off-by: default <[email protected]>
@Manewing
Manewing force-pushed the users/ziereis/qdq-drop-zero-zp branch from 9290c37 to 926c874 Compare September 22, 2026 13:43
@Manewing
Manewing merged commit 3f1d7ae into main Sep 23, 2026
60 checks passed
@Manewing
Manewing deleted the users/ziereis/qdq-drop-zero-zp branch September 23, 2026 07:15
@devtbi devtbi mentioned this pull request Oct 19, 2026
7 of 8 tasks
roberto-laudani added a commit that referenced this pull request Oct 23, 2026
PT2E accepts float zero points, and exports store those of symmetric
weights as float zeros. The conversion passed them to
`iree_linalg_ext.quantize_affine` / `dequantize_affine`, which require
integer zero points, so the converted IR failed verification:

```
'iree_linalg_ext.dequantize_affine' op expected zero_point to have a signless integer element type, got 'f32'
```

- All-zero float zero points are now dropped like a `None` zero point.
- The check reuses `isKnownZero` from #24905, moved from
`LinalgExtOps.cpp` to the LinalgExt utils and extended to float splats.
- The per-channel, per-channel-group and per-token readers now read
their zero points through one helper.

Part of #24862.

Signed-off-by: Roberto Laudani <[email protected]>
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