Skip to content

Conversation

@StrycekSimon
Copy link
Collaborator

@StrycekSimon StrycekSimon commented Nov 10, 2025

Summary

Adds quantization aware training support for NeutronQuantizer.

Test plan

New test cases covering QAT mode were added + dedicated test for training a simple NN in QAT mode.

cc @robert-kalmar @JakeStevens @digantdesai

@pytorch-bot
Copy link

pytorch-bot bot commented Nov 10, 2025

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 5c2ff05 with merge base 32916d3 (image):

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

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 Nov 10, 2025
@StrycekSimon
Copy link
Collaborator Author

@pytorchbot label "release notes: nxp"

@pytorch-bot pytorch-bot bot added the release notes: nxp Changes to the NXP Neutron backend delegate label Nov 10, 2025
@StrycekSimon
Copy link
Collaborator Author

@pytorchbot label "module: nxp"

@pytorch-bot pytorch-bot bot added the module: nxp Issues related to NXP Neutron NPU delegation and code under backends/nxp/ label Nov 10, 2025
@StrycekSimon StrycekSimon force-pushed the feature/nxg10272/EIEX-592-enable-qat-using-neutronquantizer branch 2 times, most recently from f174949 to 35fce40 Compare November 11, 2025 14:45
@StrycekSimon StrycekSimon force-pushed the feature/nxg10272/EIEX-592-enable-qat-using-neutronquantizer branch from 28ad64a to 26ceba4 Compare November 18, 2025 13:25
@StrycekSimon StrycekSimon marked this pull request as ready for review November 18, 2025 13:31
@mergennachin mergennachin requested a review from Copilot November 18, 2025 15:31
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 PR adds Quantization Aware Training (QAT) support to the NeutronQuantizer backend. The implementation uses fake quantization with moving average observers for QAT mode while maintaining backward compatibility with existing Post-Training Quantization (PTQ) mode.

  • Introduces is_qat parameter throughout the quantization pipeline to control QAT vs PTQ behavior
  • Updates all quantization patterns to support QAT with appropriate fake quantization and observers
  • Adds comprehensive test coverage for both QAT and PTQ modes across all test files

Reviewed Changes

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

Show a summary per file
File Description
backends/nxp/quantizer/neutron_quantizer.py Refactors quantization specs into functions that return QAT or PTQ-specific specs based on is_qat parameter
backends/nxp/quantizer/patterns.py Updates QuantizationPattern base class and all pattern classes to accept is_qat parameter and use appropriate observers/fake quantizers
backends/nxp/quantizer/utils.py Adds QAT support to post_training_quantize function with prepare_qat_pt2e and move_exported_model_to_eval
backends/nxp/tests/use_qat.py Adds pytest fixture to parametrize tests with QAT and PTQ modes
backends/nxp/tests/executorch_pipeline.py Threads use_qat parameter through pipeline functions
backends/nxp/tests/models.py Adds MLP model for QAT training test
backends/nxp/tests/test_quantizer.py Adds QAT-specific tests including training test and graph comparison test
All other test files Updates tests to parametrize with use_qat fixture for comprehensive coverage
Comments suppressed due to low confidence (4)

backends/nxp/quantizer/patterns.py:1

  • [nitpick] The order of initialization should be consistent with parent class expectations. Consider moving super().__init__(is_qat=is_qat) to be the first statement in __init__, following Python best practices for constructor ordering.
# Copyright (c) Meta Platforms, Inc. and affiliates.

backends/nxp/quantizer/utils.py:1

  • The function name post_training_quantize is misleading when is_qat=True, as QAT (Quantization Aware Training) is not post-training quantization. Consider renaming to quantize_model or prepare_and_convert_model to reflect that it handles both PTQ and QAT modes.
# Copyright (c) Meta Platforms, Inc. and affiliates.

backends/nxp/quantizer/patterns.py:210

class AddmmPattern(QuantizationPattern):

backends/nxp/quantizer/patterns.py:841

class ActivationsConcatClusterPattern(QuantizationPattern):

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

@StrycekSimon
Copy link
Collaborator Author

Looking back at my implementation changes, I should've renamed the post_training_quantize function since it now partially supports QAT mode. Will fix it together with the Copilot suggestions.

@StrycekSimon StrycekSimon force-pushed the feature/nxg10272/EIEX-592-enable-qat-using-neutronquantizer branch from 26ceba4 to 8e58be6 Compare November 19, 2025 11:03
Copilot AI review requested due to automatic review settings November 24, 2025 09:33
@StrycekSimon StrycekSimon force-pushed the feature/nxg10272/EIEX-592-enable-qat-using-neutronquantizer branch from 8e58be6 to 0912c53 Compare November 24, 2025 09:33
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 34 out of 34 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

backends/nxp/quantizer/patterns.py:845

class ActivationsConcatClusterPattern(QuantizationPattern):

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

@StrycekSimon StrycekSimon force-pushed the feature/nxg10272/EIEX-592-enable-qat-using-neutronquantizer branch from 0912c53 to 4e30d39 Compare November 24, 2025 14:11
Copy link
Collaborator

@jirioc jirioc left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Copilot AI review requested due to automatic review settings December 2, 2025 13:54
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@StrycekSimon StrycekSimon force-pushed the feature/nxg10272/EIEX-592-enable-qat-using-neutronquantizer branch from 7744543 to 5c2ff05 Compare December 10, 2025 15:42
@roman-janik-nxp
Copy link
Collaborator

@StrycekSimon @robert-kalmar This PR means a great change in backend workflow and as such should be described in backend docs. There is still opened a PR for docs changes that precede QAT feature. Please merge that other PR and update docs in this or a new PR.
Otherwise nice implementation. 👍

@robert-kalmar robert-kalmar merged commit b6935ad into pytorch:main Dec 11, 2025
139 of 140 checks passed
@robert-kalmar robert-kalmar deleted the feature/nxg10272/EIEX-592-enable-qat-using-neutronquantizer branch December 11, 2025 10:22
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.

4 participants