-
Notifications
You must be signed in to change notification settings - Fork 291
[TorchAO] [OVQuantizer] Update Torch AO Dependency and Refactor Executorch Tests #3842
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: develop
Are you sure you want to change the base?
Changes from 51 commits
9dd119c
b62071b
0467fda
4090ae9
716d1be
a3664bc
602f773
096347b
9be7502
414b74b
e55c599
2f54bd5
4c4cd31
77090db
2fdca07
11cc209
cd320cc
248f87e
778ef3b
9d1dc3c
b55de80
558ab32
e1a6b31
25e088a
e6b67eb
4e5edc8
dac8ac1
7ee370b
daa7db8
5fc5401
5690a77
4774caa
a9696d0
e19c369
11854c5
781679c
66c6a95
663d787
4ea7ca4
82d2675
964435c
7ced6db
4fbe6ed
7ab039c
1e7e2a1
59d0623
db81c40
dcab6dd
0b1dbd6
987da71
9fce258
9b556dc
fc76f1f
2e825b0
fdc99eb
e8ad45a
fa98dd1
23a2b7e
f64a0f4
b6275b7
a193bca
9e671a5
f41a16a
ef50f87
711fd78
d84f54f
a119db0
d388f8f
e138d70
2e22915
5964281
dc1db31
c03cab4
8f64c90
25900e3
dde7249
0f67e43
91b8f58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ openvino==2025.4.1 | |
| # Pytorch | ||
| torch==2.9.0 | ||
| torchvision==0.24.0 | ||
| torchao==0.14.0 | ||
|
Collaborator
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. Aamir, as we discussed it with Alexander Suslov, the main idea was to get rid of torch.ao and do not use any external dependencies (like torchao) |
||
|
|
||
| # ONNX | ||
| onnx==1.17.0; python_version < '3.13' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| tensorboard==2.13.0 | ||
| torch==2.9.0 | ||
| torchao==0.14.0 | ||
|
Collaborator
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. Why torch example require torchao?
Collaborator
Author
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. It was importing torchao in https://github.com/openvinotoolkit/nncf/actions/runs/21142246987/job/60798968378 Perhaps I can make it lazy import inside the convert_to_torch_fakequantizer function |
||
| numpy>=1.23.5,<2 | ||
| openvino==2025.4.1 | ||
| optimum-intel==1.27.0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| tensorboard==2.13.0 | ||
| torch==2.9.0 | ||
| torchao==0.14.0 | ||
| numpy>=1.23.5,<2 | ||
| openvino==2025.4.1 | ||
| optimum-intel==1.27.0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ datasets==4.4.1 | |
| openvino==2025.4.1 | ||
| optimum==2.1.0 | ||
| torch==2.9.0 | ||
| torchao==0.14.0 | ||
| torchvision==0.24.0 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ fastcore==1.11.5 | |
| openvino==2025.4.1 | ||
| torch==2.9.0 | ||
| torchvision==0.24.0 | ||
| torchao==0.14.0 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,18 +8,17 @@ | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from copy import deepcopy | ||
| from typing import Optional | ||
|
|
||
| import torch | ||
| import torch.fx | ||
| from torch.ao.quantization.pt2e.port_metadata_pass import PortNodeMetaForQDQ | ||
| from torch.ao.quantization.pt2e.utils import _disallow_eval_train | ||
| from torch.ao.quantization.pt2e.utils import _fuse_conv_bn_ | ||
| from torch.ao.quantization.quantizer import Quantizer | ||
| from torch.fx import GraphModule | ||
| from torch.fx.passes.infra.pass_manager import PassManager | ||
| from torchao.quantization.pt2e.quantizer import PortNodeMetaForQDQ | ||
| from torchao.quantization.pt2e.quantizer.quantizer import Quantizer | ||
| from torchao.quantization.pt2e.utils import _disallow_eval_train | ||
| from torchao.quantization.pt2e.utils import _fuse_conv_bn_ | ||
|
|
||
| import nncf | ||
| from nncf import AdvancedCompressionParameters | ||
|
|
@@ -32,7 +31,6 @@ | |
| from nncf.experimental.quantization.algorithms.weight_compression.algorithm import WeightsCompression | ||
| from nncf.experimental.torch.fx.constant_folding import constant_fold | ||
| from nncf.experimental.torch.fx.quantization.quantizer.openvino_adapter import OpenVINOQuantizerAdapter | ||
| from nncf.experimental.torch.fx.quantization.quantizer.openvino_quantizer import OpenVINOQuantizer | ||
| from nncf.experimental.torch.fx.quantization.quantizer.torch_ao_adapter import TorchAOQuantizerAdapter | ||
| from nncf.experimental.torch.fx.transformations import QUANTIZE_NODE_TARGETS | ||
| from nncf.experimental.torch.fx.transformations import DuplicateDQPassNoAnnotations | ||
|
|
@@ -42,6 +40,19 @@ | |
| from nncf.quantization.range_estimator import RangeEstimatorParameters | ||
|
|
||
|
|
||
| def _is_openvino_quantizer_instance(obj) -> bool: | ||
|
||
| """ | ||
| Safely check if an object is instance of OpenVINOQuantizer. | ||
| This is to avoid a circular import | ||
| """ | ||
| try: | ||
| from executorch.backends.openvino.quantizer.quantizer import OpenVINOQuantizer | ||
|
|
||
| return isinstance(obj, OpenVINOQuantizer) | ||
| except ImportError: | ||
| return False | ||
|
|
||
|
|
||
| @api(canonical_alias="nncf.experimental.torch.fx.quantize_pt2e") | ||
| def quantize_pt2e( | ||
| model: torch.fx.GraphModule, | ||
|
|
@@ -60,7 +71,7 @@ def quantize_pt2e( | |
| ) -> torch.fx.GraphModule: | ||
| """ | ||
| Applies post-training quantization to the torch.fx.GraphModule provided model | ||
| using provided torch.ao quantizer. | ||
| using provided torchao quantizer. | ||
|
|
||
| :param model: A torch.fx.GraphModule instance to be quantized. | ||
| :param quantizer: Torch ao quantizer to annotate nodes in the graph with quantization setups | ||
|
|
@@ -103,7 +114,7 @@ def quantize_pt2e( | |
| model = deepcopy(model) | ||
|
|
||
| _fuse_conv_bn_(model) | ||
| if isinstance(quantizer, OpenVINOQuantizer) or hasattr(quantizer, "get_nncf_quantization_setup"): | ||
| if _is_openvino_quantizer_instance(quantizer) or hasattr(quantizer, "get_nncf_quantization_setup"): | ||
| quantizer = OpenVINOQuantizerAdapter(quantizer) | ||
| else: | ||
| quantizer = TorchAOQuantizerAdapter(quantizer) | ||
|
|
@@ -178,7 +189,7 @@ def compress_pt2e( | |
| advanced_parameters: Optional[AdvancedCompressionParameters] = None, | ||
| ) -> torch.fx.GraphModule: | ||
| """ | ||
| Applies Weight Compression to the torch.fx.GraphModule model using provided torch.ao quantizer. | ||
| Applies Weight Compression to the torch.fx.GraphModule model using provided torchao quantizer. | ||
|
|
||
| :param model: A torch.fx.GraphModule instance to be quantized. | ||
| :param quantizer: Torch ao quantizer to annotate nodes in the graph with quantization setups | ||
|
|
@@ -196,7 +207,7 @@ def compress_pt2e( | |
| preserve the accuracy of the model, the more sensitive layers receive a higher precision. | ||
| :param advanced_parameters: Advanced parameters for algorithms in the compression pipeline. | ||
| """ | ||
| if isinstance(quantizer, OpenVINOQuantizer) or hasattr(quantizer, "get_nncf_weight_compression_parameters"): | ||
| if _is_openvino_quantizer_instance(quantizer) or hasattr(quantizer, "get_nncf_weight_compression_parameters"): | ||
| quantizer = OpenVINOQuantizerAdapter(quantizer) | ||
| compression_format = nncf.CompressionFormat.DQ | ||
| else: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.