Skip to content

Conversation

@StrycekSimon
Copy link
Collaborator

@StrycekSimon StrycekSimon commented Jan 15, 2026

Summary

Adds two passes for inserting/removing simulated BatchNorm fusion for QAT training, similarly to how _fuse_conv_bn_qat adds simulated Conv+BatchNorm fusion in prepare_qat_pt2e function from TorchAO.

Test plan

Added integration tests that covers newly added implementation,

cc @robert-kalmar

Copilot AI review requested due to automatic review settings January 15, 2026 15:12
@pytorch-bot
Copy link

pytorch-bot bot commented Jan 15, 2026

🔗 Helpful Links

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

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

❌ 11 New Failures, 1 Pending

As of commit d70a29e with merge base 7a9fb3f (image):

NEW FAILURES - The following jobs have failed:

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

@StrycekSimon StrycekSimon requested review from MartinPavella and removed request for Copilot and robert-kalmar January 15, 2026 15:12
@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 Jan 15, 2026
@StrycekSimon StrycekSimon added module: nxp Issues related to NXP Neutron NPU delegation and code under backends/nxp/ release notes: nxp Changes to the NXP Neutron backend delegate labels Jan 15, 2026
Copilot AI review requested due to automatic review settings January 29, 2026 12:40
@StrycekSimon StrycekSimon force-pushed the feature/EIEX-641-create-a-pass-to-fuse-linear-batchnorm-after-qat-quantization branch from 8d41a7a to b45a2ba Compare January 29, 2026 12:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds support for Linear + BatchNorm QAT (Quantization Aware Training) fusion in the NXP backend, following a similar approach to the existing Conv + BatchNorm fusion in TorchAO.

Changes:

  • Adds AddSimulatedLinearBatchNormFusionQATPass to insert simulated fusion during QAT training by normalizing linear weights and denormalizing outputs using BatchNorm statistics
  • Adds RemoveSimulatedLinearBatchNormFusionQATPass to remove the simulated fusion artifacts after QAT training is complete
  • Updates FuseBatchNormWithLinearPass to handle fake-quantized nodes during fusion
  • Updates LinearPattern quantizer to skip quantization between linear and batch norm nodes during QAT
  • Adds comprehensive integration tests covering the fusion workflow

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
backends/nxp/tests/models.py Adds LinearBNModule test model for testing Linear + BatchNorm patterns
backends/nxp/tests/ir/edge_passes/test_linear_bn_fusing.py Adds integration tests for simulated fusion, complete fusion pipeline, and graph equivalence
backends/nxp/aten_passes/add_simulated_linear_bn_fusion_qat_pass.py Implements pass to add simulated Linear + BatchNorm fusion for QAT by normalizing weights and denormalizing outputs
backends/nxp/aten_passes/remove_simulated_linear_bn_fusion_qat_pass.py Implements pass to remove simulated fusion artifacts after QAT training
backends/nxp/aten_passes/fuse_batch_norm_with_linear_pass.py Adds _unwrap_if_fq helper function to handle fake-quantized nodes during fusion
backends/nxp/quantizer/patterns.py Updates LinearPattern to skip output quantization when followed by BatchNorm during QAT

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@StrycekSimon StrycekSimon force-pushed the feature/EIEX-641-create-a-pass-to-fuse-linear-batchnorm-after-qat-quantization branch from b45a2ba to 764403b Compare January 29, 2026 16:35
Copilot AI review requested due to automatic review settings January 29, 2026 16:44
@StrycekSimon StrycekSimon force-pushed the feature/EIEX-641-create-a-pass-to-fuse-linear-batchnorm-after-qat-quantization branch from 764403b to 79557ff Compare January 29, 2026 16:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@StrycekSimon StrycekSimon force-pushed the feature/EIEX-641-create-a-pass-to-fuse-linear-batchnorm-after-qat-quantization branch from 79557ff to ad5acaf Compare January 29, 2026 19:44
Copilot AI review requested due to automatic review settings February 2, 2026 07:42
@StrycekSimon StrycekSimon force-pushed the feature/EIEX-641-create-a-pass-to-fuse-linear-batchnorm-after-qat-quantization branch from ad5acaf to ff54eb2 Compare February 2, 2026 07:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@StrycekSimon StrycekSimon force-pushed the feature/EIEX-641-create-a-pass-to-fuse-linear-batchnorm-after-qat-quantization branch from ff54eb2 to 2704388 Compare February 2, 2026 08:13
@robert-kalmar
Copy link
Collaborator

Only change I really would like to see is integration into the executorch_pipeline.py and to the aot_neutron_convert.py if it make sense (at this moment). Other my comments are nice to have.

@StrycekSimon
Copy link
Collaborator Author

Only change I really would like to see is integration into the executorch_pipeline.py and to the aot_neutron_convert.py if it make sense (at this moment). Other my comments are nice to have.

I will add it to the calibrate_and_quantize function just to include it in tests and cover that there are no conflicts (failing tests) with the rest of the implementation. Just note that the only model in aot_neutron_compile.py that uses QAT so far is CifarNet on which it is pretty pointless to explicitly use it as it does not contain the Linear+BN pattern.

Copilot AI review requested due to automatic review settings February 10, 2026 16:10
@StrycekSimon StrycekSimon force-pushed the feature/EIEX-641-create-a-pass-to-fuse-linear-batchnorm-after-qat-quantization branch from 2704388 to 51bd521 Compare February 10, 2026 16:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@StrycekSimon
Copy link
Collaborator Author

StrycekSimon commented Feb 11, 2026

After the recent push, one of PTQ test cases for mm op conversion fails. I will investigate.

Update: It's a mismatch by 1 in one of the output values, much like what can be seen in some other tests (eg. test_clone_converter.py) probably caused by float arithmetics. Increasing atol to 1 like in similar tests resolved this issue.

@StrycekSimon StrycekSimon force-pushed the feature/EIEX-641-create-a-pass-to-fuse-linear-batchnorm-after-qat-quantization branch from 51bd521 to fb048d2 Compare February 11, 2026 09:48
Copilot AI review requested due to automatic review settings February 11, 2026 10:05
@StrycekSimon StrycekSimon force-pushed the feature/EIEX-641-create-a-pass-to-fuse-linear-batchnorm-after-qat-quantization branch from fb048d2 to 0bcdcb9 Compare February 11, 2026 10:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@StrycekSimon StrycekSimon force-pushed the feature/EIEX-641-create-a-pass-to-fuse-linear-batchnorm-after-qat-quantization branch from 0bcdcb9 to d70a29e Compare February 11, 2026 13:29
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. module: nxp Issues related to NXP Neutron NPU delegation and code under backends/nxp/ release notes: nxp Changes to the NXP Neutron backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants