Skip to content

[GlobalOptimization] Propagate affine QDQ through tensor operations - #24906

Merged
ziereis merged 4 commits into
mainfrom
users/ziereis/qdq-reshape-propagation
Oct 12, 2026
Merged

ziereis merged 4 commits into
mainfrom
users/ziereis/qdq-reshape-propagation

Conversation

@ziereis

@ziereis ziereis commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

The integer contraction rewrite from #24902 needs dequantize_affine to be the direct producer of a contraction operand. This PR adds PropagateAffineQuantization, which moves the tensor ops in between onto the quantized side, where they also operate on narrower data. It runs right before each integer QDQ rewrite.

It perform the following transformations:

quantize(collapse_shape(x))   ->  collapse_shape(quantize(x))
expand_shape(dequantize(q))   ->  dequantize(expand_shape(q))
pad(dequantize(q), 0.0)       ->  dequantize(pad(q, zp))
transpose(dequantize(q))      ->  dequantize(q) with its output map permuted

Part of #24862

Assisted By: Claude Code

@ziereis
ziereis added this pull request to stack #24903 September 10, 2026 08:19
@ziereis ziereis changed the title [GlobalOptimization] Propagate QDQ through layout operations [GlobalOptimization] Propagate affine QDQ toward contractions Sep 10, 2026
@ziereis
ziereis force-pushed the users/ziereis/qdq-drop-zero-zp branch from f6ef8a2 to abdb4d4 Compare September 11, 2026 06:37
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch from c8b49c2 to 6b7fe06 Compare September 11, 2026 06:37
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch 2 times, most recently from f5477f8 to 2bcf3a1 Compare September 11, 2026 07:27
@Manewing
Manewing force-pushed the users/ziereis/qdq-drop-zero-zp branch from abdb4d4 to 9290c37 Compare September 15, 2026 08:38
@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-drop-zero-zp branch from 9290c37 to 926c874 Compare September 22, 2026 13:43
Base automatically changed from users/ziereis/qdq-drop-zero-zp to main September 23, 2026 07:15
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch from 719cc19 to 8c34330 Compare September 29, 2026 09:40
@ziereis
ziereis removed this pull request from stack #24903 September 29, 2026 10:11
@ziereis ziereis changed the title [GlobalOptimization] Propagate affine QDQ toward contractions [GlobalOptimization] Propagate affine QDQ through tensor operations Sep 29, 2026
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch from 2992dd3 to c9a05a3 Compare September 30, 2026 12:21
@ziereis
ziereis changed the base branch from main to users/ziereis/qdq-transpose-pattern-refactor September 30, 2026 12:23
@ziereis
ziereis force-pushed the users/ziereis/qdq-transpose-pattern-refactor branch from b858147 to 528f5c6 Compare September 30, 2026 13:58
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch from c9a05a3 to 41c764e Compare September 30, 2026 13:58
@ziereis
ziereis force-pushed the users/ziereis/qdq-transpose-pattern-refactor branch from 528f5c6 to d98e118 Compare September 30, 2026 15:16
@ziereis ziereis closed this Sep 30, 2026
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch from 41c764e to d98e118 Compare September 30, 2026 15:16
@ziereis ziereis reopened this Sep 30, 2026
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch from d98e118 to 26f9b99 Compare September 30, 2026 15:25
@ziereis
ziereis force-pushed the users/ziereis/qdq-transpose-pattern-refactor branch from 5f74093 to 8e2cdbf Compare September 30, 2026 15:25
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch from 26f9b99 to f516972 Compare September 30, 2026 15:31
@ziereis
ziereis force-pushed the users/ziereis/qdq-transpose-pattern-refactor branch from 8e2cdbf to 6854dae Compare September 30, 2026 15:32
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch 2 times, most recently from 7fe8848 to 8b0febd Compare September 30, 2026 15:53
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch 3 times, most recently from 2cead15 to 70fc572 Compare September 30, 2026 16:22
@ziereis
ziereis marked this pull request as ready for review September 30, 2026 16:28
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch from 70fc572 to 7882973 Compare September 30, 2026 16:29
devtbi pushed a commit that referenced this pull request Oct 1, 2026
…24978)

I ran into multiple scenarios in the past (and now again for #24906)
where i had to reimplement some form of transpose propagation. To
improve this, this PR refactors the transpose propagation pass into
reusable patterns.

This PR should not cause any functional changes and should be a pure
refactor.

Assisted by: Claude

Signed-off-by: Thomas Ziereis <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Base automatically changed from users/ziereis/qdq-transpose-pattern-refactor to main October 1, 2026 08:51
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch from 7882973 to 894488e Compare October 6, 2026 08:33

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

Few things otherwise looks good to me :)

@ziereis

ziereis commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@Manewing Thanks for the review, comments should be addressed.

I made one more change to the PR beyond this, which is allowing pads to propagate even if the dequantize op is not single use.

I have some experimental evidence that this would block some integer rewrites in real models and generally looks profitable to do from the data i have now. However this might need some better heuristic in the future.

ziereis and others added 4 commits October 12, 2026 07:58
Move affine quantization through supported reshapes and padding, fuse
consuming transposes into dequantize, and run propagation before integer
QDQ rewriting so contractions consume dequantize results directly.

Add a pattern that fuses a transpose into its single-use dequantize by
permuting the dequantize's output map, the same map update the generic
producer fusion applies. The integer contraction rewrite already reads
through permuted dequantize maps, so no transpose is materialized on
either side. The QDQ propagation pass uses it together with generic
transpose specialization, restricted to transposes of dequantized
values. The general transpose propagation pass also runs it while
bubbling.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Thomas Ziereis <[email protected]>
- Keep the static result type of the original pad when moving it onto
  the quantized side instead of inferring it from the source.
- Replace operands by position when cloning an op with dropped unit
  dims: the same value can appear as several operands that need
  different replacements.
- Name the actual reason a per-channel zero point cannot pad the
  quantized side: tensor.pad tiling only supports a padding value
  defined outside the pad.
- Say collapse_shape or expand_shape instead of reshape where a
  specific op is meant, and drop a redundant CHECK-NOT.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Thomas Ziereis <[email protected]>
BubblePadThroughDequantize required the dequantize to have the pad as
its only user. A dequantized activation that feeds both a padded
convolution and another consumer, such as a residual add or concat,
kept its pad on the real-valued side, so the convolution never saw a
dequantize producer and stayed in floating point.

Moving the pad does not need exclusive ownership: the padded positions
get their own dequantize of the padded quantized value, while the other
users keep reading the original dequantize. Drop the restriction.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Thomas Ziereis <[email protected]>
The IREE dialects moved to strict properties in #24983, so the parser
no longer accepts the inherent attributes of quantize_affine and
dequantize_affine in an attribute dictionary. Rewrite the test inputs
and CHECK patterns to the <...> property syntax.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Thomas Ziereis <[email protected]>
@ziereis
ziereis force-pushed the users/ziereis/qdq-reshape-propagation branch from 7478472 to b975dde Compare October 12, 2026 08:42
@ziereis
ziereis enabled auto-merge (squash) October 12, 2026 09:43
@ziereis
ziereis merged commit 388e65c into main Oct 12, 2026
85 of 89 checks passed
@ziereis
ziereis deleted the users/ziereis/qdq-reshape-propagation branch October 12, 2026 09:54
@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