-
Notifications
You must be signed in to change notification settings - Fork 848
Draft: Integration of QuantizeFusedConvBnBiasPass to NXP conversion pipeline
#17523
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
Draft
StrycekSimon
wants to merge
2
commits into
pytorch:main
Choose a base branch
from
nxp-upstream:convbn_no_bias_pass_nxp_pipeline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,9 @@ | |
| from typing import Any, Dict, List, Tuple, Type | ||
|
|
||
| import torch | ||
| from executorch.backends.transforms.quantize_fused_convbn_bias_pass import ( | ||
| QuantizeFusedConvBnBiasPass, | ||
| ) | ||
| from torch import fx | ||
| from torch._ops import OpOverload | ||
| from torch.export import ExportedProgram | ||
|
|
@@ -162,15 +165,15 @@ def find_sequential_partitions_aten( | |
|
|
||
|
|
||
| def calibrate_and_quantize( | ||
| model: ExportedProgram | fx.GraphModule, | ||
| model: ExportedProgram, | ||
| calibration_inputs: Iterable[tuple[torch.Tensor, ...]], | ||
| quantizer: Quantizer, | ||
| is_qat: bool = False, | ||
| ) -> fx.GraphModule: | ||
| """Quantize the provided model. | ||
|
|
||
| :param model: Aten model (or it's GraphModule representation) to quantize. | ||
| :param calibration_inputs: Either a tuple of calibration input tensors where each element corresponds to a model | ||
| :param model: Aten exported model to quantize. | ||
| :param calibration_inputs: Either a tuple of calibration input tensors where each element corresponds to a module | ||
| input. Or an iterator over such tuples. | ||
| :param quantizer: Quantizer to use. | ||
| :param is_qat: Whether quantization is done using Quantization Aware Training (QAT) or not. | ||
|
|
@@ -179,17 +182,21 @@ def calibrate_and_quantize( | |
| :return: Quantized GraphModule. | ||
| """ | ||
|
|
||
| if isinstance(model, ExportedProgram): | ||
| model = model.module() | ||
| module = model.module() | ||
|
|
||
| if is_qat: | ||
| m = prepare_qat_pt2e(model, quantizer) | ||
| m = move_exported_model_to_eval(m) | ||
| module = prepare_qat_pt2e(module, quantizer) | ||
| module = move_exported_model_to_eval(module) | ||
| else: | ||
| m = prepare_pt2e(model, quantizer) | ||
| module = prepare_pt2e(module, quantizer) | ||
|
|
||
| for data in calibration_inputs: | ||
| m(*data) | ||
| m = convert_pt2e(m) | ||
| module(*data) | ||
| module = convert_pt2e(module) | ||
|
|
||
| # Without this export, conv bias is not in the graph_signature. | ||
| model = torch.export.export(module, calibration_inputs[0], strict=True) | ||
| bias_quant_pass = QuantizeFusedConvBnBiasPass(model) | ||
| model = bias_quant_pass(model.graph_module) | ||
|
|
||
| return m | ||
| return model.graph_module | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the change to use graph_module desired outcome or currently just needed for the pass as is? |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,29 @@ | ||
| load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") | ||
| load("@fbcode_macros//build_defs:python_pytest.bzl", "python_pytest") | ||
| load(":targets.bzl", "define_common_targets") | ||
|
|
||
| oncall("executorch") | ||
|
|
||
| fbcode_target(_kind = define_common_targets,) | ||
|
|
||
| fbcode_target(_kind = python_pytest, | ||
| name = "test_quantize_fused_convbn_bias_pass", | ||
| srcs = [ | ||
| "test/test_quantize_fused_convbn_bias_pass.py", | ||
| ], | ||
| deps = [ | ||
| "//caffe2:torch", | ||
| ":quantize_fused_convbn_bias_pass", | ||
| "//executorch/backends/arm/quantizer:arm_quantizer", | ||
| "//executorch/backends/arm/test:arm_tester_lib", | ||
| "//executorch/backends/arm/test:arm_tester_serialize", | ||
| "//executorch/backends/arm/test:common", | ||
| "//executorch/backends/arm/tosa:tosa", | ||
| "//executorch/backends/nxp:quantizer", | ||
| "//executorch/backends/nxp:neutron_backend", | ||
| "//executorch/backends/xnnpack/test/tester:tester", | ||
| "//executorch/exir:lib", | ||
| "//executorch/kernels/quantized:custom_ops_generated_lib", | ||
| "fbsource//third-party/pypi/pytest:pytest", | ||
| ], | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So you want to try to drop needing this?