Skip to content

Comments

Add quantize fused convbn bias pass#17348

Open
JakeStevens wants to merge 1 commit intopytorch:mainfrom
JakeStevens:export-D92733079
Open

Add quantize fused convbn bias pass#17348
JakeStevens wants to merge 1 commit intopytorch:mainfrom
JakeStevens:export-D92733079

Conversation

@JakeStevens
Copy link
Contributor

@JakeStevens JakeStevens commented Feb 10, 2026

Summary:
When performing QAT with a model that has a conv layer with no bias followed by batch norm, the fusion process creates a bias. This is done after observers are attached so the resulting bias is kept as float.

This diff adds a pass which grabs the proper qparams and applies them to the non-quantized bias.

Differential Revision: D92733079

cc @robert-kalmar @digantdesai

@pytorch-bot
Copy link

pytorch-bot bot commented Feb 10, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/17348

Note: Links to docs will display an error until the docs builds have been completed.

❌ 8 New Failures

As of commit 6b825e9 with merge base 6c1dc31 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 10, 2026
@meta-codesync
Copy link
Contributor

meta-codesync bot commented Feb 10, 2026

@JakeStevens has exported this pull request. If you are a Meta employee, you can view the originating Diff in D92733079.

@github-actions
Copy link

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@JakeStevens JakeStevens added the module: nxp Issues related to NXP Neutron NPU delegation and code under backends/nxp/ label Feb 10, 2026
JakeStevens added a commit to JakeStevens/executorch that referenced this pull request Feb 10, 2026
Summary:

When performing QAT with a model that has a conv layer with no bias followed by batch norm, the fusion process creates a bias. This is done *after* observers are attached so the resulting bias is kept as float.

This diff adds a pass which grabs the proper qparams and applies them to the non-quantized bias.

Differential Revision: D92733079
Summary:

When performing QAT with a model that has a conv layer with no bias followed by batch norm, the fusion process creates a bias. This is done *after* observers are attached so the resulting bias is kept as float.

This diff adds a pass which grabs the proper qparams and applies them to the non-quantized bias.

Differential Revision: D92733079
@robert-kalmar
Copy link
Collaborator

CC @StrycekSimon @roman-janik-nxp

Copy link
Collaborator

@StrycekSimon StrycekSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried running it with our conversion pipeline but not successfully. Seems like the bias is being added as another input of the model. Can you take a look at it? Or is there some postprocessing step needed I am missing?

return node.target in (
exir_ops.edge.aten.convolution.default,
torch.ops.aten.convolution.default,
torch.ops.aten.conv2d.default,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add also transposed convs here? Or is there a reason for omitting them?

)

pass_instance = QuantizeFusedConvBnBiasPass(exported_program)
result = pass_instance.call(exported_program.graph_module)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some postprocessing needed after this line of code? I tried plugging it into our pipeline right after the calibrate_and_quantize call (same as here) and it fails on: "TypeError: missing a required argument: 'b__scale_0'" when trying to call export(result.graph_module, ...) which we do here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put up a draft pr to show how you tried plugging it in? Then I can literate on that and make sure it works appropriately

JakeStevens added a commit to JakeStevens/executorch that referenced this pull request Feb 20, 2026
Summary:

When performing QAT with a conv layer (bias=False) followed by batch norm, the fusion process introduces a bias after observers are attached, so the bias remains unquantized. These passes find such biases, compute the correct scale from the input and weight dequantize nodes, and insert proper quantize/dequantize nodes for the bias. 
                                                                                                                                                                
                                                                                                                                                                        
Two pass variants are provided:                                                                                                                                       
  - QuantizeFusedConvBnBiasPass (ExportPass) — operates on edge dialect graphs after to_edge()
  - QuantizeFusedConvBnBiasAtenPass (PassBase) — operates on aten dialect graphs, supporting both plain GraphModules (get_attr nodes) and ExportedPrograms (placeholder nodes)

Differential Revision: D92733079
@JakeStevens
Copy link
Contributor Author

@StrycekSimon the NXP changes and test are now here:

#17599

This diff is now "standalone" pass and the integration with your backend in the above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported module: nxp Issues related to NXP Neutron NPU delegation and code under backends/nxp/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants