-
Notifications
You must be signed in to change notification settings - Fork 834
NXP backend: Linear + BatchNorm QAT fusing #16623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
NXP backend: Linear + BatchNorm QAT fusing #16623
Conversation
🔗 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 PendingAs of commit d70a29e with merge base 7a9fb3f ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
backends/nxp/aten_passes/add_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
backends/nxp/aten_passes/add_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
backends/nxp/aten_passes/add_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
backends/nxp/aten_passes/add_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
backends/nxp/aten_passes/add_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
...nxp/aten_passes/simulated_linear_bn_fusion_passes/add_simulated_linear_bn_fusion_qat_pass.py
Show resolved
Hide resolved
backends/nxp/aten_passes/add_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
8d41a7a to
b45a2ba
Compare
There was a problem hiding this 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
AddSimulatedLinearBatchNormFusionQATPassto insert simulated fusion during QAT training by normalizing linear weights and denormalizing outputs using BatchNorm statistics - Adds
RemoveSimulatedLinearBatchNormFusionQATPassto remove the simulated fusion artifacts after QAT training is complete - Updates
FuseBatchNormWithLinearPassto handle fake-quantized nodes during fusion - Updates
LinearPatternquantizer 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.
...nxp/aten_passes/simulated_linear_bn_fusion_passes/add_simulated_linear_bn_fusion_qat_pass.py
Show resolved
Hide resolved
backends/nxp/aten_passes/add_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
backends/nxp/aten_passes/add_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
backends/nxp/aten_passes/remove_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
...nxp/aten_passes/simulated_linear_bn_fusion_passes/add_simulated_linear_bn_fusion_qat_pass.py
Show resolved
Hide resolved
backends/nxp/aten_passes/remove_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
b45a2ba to
764403b
Compare
764403b to
79557ff
Compare
There was a problem hiding this 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.
backends/nxp/aten_passes/add_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
backends/nxp/aten_passes/add_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
backends/nxp/aten_passes/remove_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
backends/nxp/aten_passes/add_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
79557ff to
ad5acaf
Compare
ad5acaf to
ff54eb2
Compare
There was a problem hiding this 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.
backends/nxp/aten_passes/add_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
ff54eb2 to
2704388
Compare
backends/nxp/aten_passes/remove_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
.../aten_passes/simulated_linear_bn_fusion_passes/remove_simulated_linear_bn_fusion_qat_pass.py
Show resolved
Hide resolved
|
Only change I really would like to see is integration into the |
I will add it to the |
2704388 to
51bd521
Compare
There was a problem hiding this 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.
.../aten_passes/simulated_linear_bn_fusion_passes/remove_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
.../aten_passes/simulated_linear_bn_fusion_passes/remove_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
|
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. |
51bd521 to
fb048d2
Compare
fb048d2 to
0bcdcb9
Compare
There was a problem hiding this 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.
...nxp/aten_passes/simulated_linear_bn_fusion_passes/add_simulated_linear_bn_fusion_qat_pass.py
Outdated
Show resolved
Hide resolved
0bcdcb9 to
d70a29e
Compare
Summary
Adds two passes for inserting/removing simulated BatchNorm fusion for QAT training, similarly to how
_fuse_conv_bn_qatadds simulated Conv+BatchNorm fusion inprepare_qat_pt2efunction from TorchAO.Test plan
Added integration tests that covers newly added implementation,
cc @robert-kalmar