Skip to content

Fixes in Graph mode Quantizer - #144

Merged
aseemw merged 2 commits into
apple:mainfrom
aseemw:u/awadhwa/quantizer_fixes
Oct 19, 2026
Merged

aseemw merged 2 commits into
apple:mainfrom
aseemw:u/awadhwa/quantizer_fixes

Conversation

@aseemw

@aseemw aseemw commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes two cases where graph-mode quantization silently left conv/linear weights unquantized.

Issue 1: convs with padding="same" or padding="valid" were not quantized

Cause: torch.export exports a conv with string padding as a different aten overload, torch.ops.aten.conv2d.padding instead of torch.ops.aten.conv2d.default (likewise for conv1d/conv3d). The conv annotation patterns only contained aten.convNd.default, so they never matched these convs.

Fix: the conv patterns now also include the aten.convNd.padding overload.

Issue 2: conv/linear followed by an in-place activation (e.g. nn.ReLU(inplace=True)) was not quantized

Cause: match_pattern_with_subgraph_matcher keyed each match on the "mod" entry of the pattern's name node map, expected to point to the weighted op (the conv/linear). With In-place activation present, torch.export maps "mod" to the relu_ node instead of the conv. The match was then keyed on relu_, which received the input and weight specs it has no use for, and the conv got neither its input nor its weight quantizer.

Fix: the primary node of a match is now the op in the match that consumes the pattern's "weight", rather than the node named "mod".

…n place activation ops like relu_ being used with conv
@aseemw aseemw changed the title Fixes in Graph model Quantizer Fixes in Graph mode Quantizer Oct 17, 2026
@aseemw
aseemw marked this pull request as ready for review October 17, 2026 23:19
@aseemw aseemw assigned crowbat and NehalBhandari and unassigned crowbat Oct 17, 2026
@aseemw
aseemw force-pushed the u/awadhwa/quantizer_fixes branch from ebbbf30 to 6e23595 Compare October 18, 2026 02:36
@aseemw
aseemw force-pushed the u/awadhwa/quantizer_fixes branch from 6e23595 to 48ec9bb Compare October 18, 2026 03:14
@NehalBhandari

Copy link
Copy Markdown
Contributor

Thank you for the fixes. LGTM!

One thing to note is that we are not handling conv with padding in _conv_bn_utils which handles folding of conv bn weights. But torchao doesn't handle padding ops in fusion either so it should be okay to keep batch norm separate.

@aseemw
aseemw merged commit 0697202 into apple:main Oct 19, 2026
14 checks passed
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.

3 participants