From bdc89b1571188c0da396caab92dc544666b1724d Mon Sep 17 00:00:00 2001 From: Liubov Talamanova Date: Mon, 21 Mar 2022 14:17:55 +0300 Subject: [PATCH] Moved quantization templates to openvino/tools/pot (#10814) --- tools/pot/docs/BestPractices.md | 6 +++--- .../algorithms/quantization/accuracy_aware/README.md | 2 +- .../pot/algorithms/quantization/default/README.md | 2 +- tools/pot/openvino/tools/pot/app/run.py | 2 +- .../openvino/tools/pot/configs/templates/__init__.py | 2 ++ .../accuracy_aware_quantization_template.json | 0 .../templates}/default_quantization_template.json | 0 tools/pot/setup.py | 10 +++------- 8 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 tools/pot/openvino/tools/pot/configs/templates/__init__.py rename tools/pot/{configs => openvino/tools/pot/configs/templates}/accuracy_aware_quantization_template.json (100%) rename tools/pot/{configs => openvino/tools/pot/configs/templates}/default_quantization_template.json (100%) diff --git a/tools/pot/docs/BestPractices.md b/tools/pot/docs/BestPractices.md index b0906f96372..5972b66e18e 100644 --- a/tools/pot/docs/BestPractices.md +++ b/tools/pot/docs/BestPractices.md @@ -18,7 +18,7 @@ Post-training quantization is a basic feature of the POT and it has lots of knob quantized model. However, as a starting point we suggest using the `DefaultQuantization` algorithm with default settings. In many cases it leads to satisfied accuracy and performance speedup. -A fragment of the configuration file (`config/default_quantization_template.json` in the POT directory) with default settings is shown below: +A fragment of the configuration file (`openvino/tools/pot/configs/templates/default_quantization_template.json` in the POT directory) with default settings is shown below: ``` "compression": { "target_device": "ANY", // Target device, the specificity of which will be taken into account during optimization. @@ -78,7 +78,7 @@ For example, the following `range_estimator` for activations can improve the acc } ``` -Find the possible options and their description in the `config/default_quantization_spec.json` file in the POT directory. +Find the possible options and their description in the `configs/default_quantization_spec.json` file in the POT directory. 4. The next option is `stat_subset_size`. It controls the size of the calibration dataset used by POT to collect statistics for quantization parameters initialization. It is assumed that this dataset should contain a sufficient number of representative samples. Thus, varying this parameter may affect accuracy (higher is better). @@ -92,7 +92,7 @@ In case when the steps above do not lead to the accurate quantized model you may The whole idea behind that is to revert quantized layers back to floating-point precision based on their contribution to the accuracy drop until the desired accuracy degradation with respect to the full-precision model is satisfied. -A fragment of the configuration file with default settings is shown below (`configs/accuracy_aware_quantization_template.json`): +A fragment of the configuration file with default settings is shown below (`openvino/tools/pot/configs/templates/accuracy_aware_quantization_template.json`): ``` "compression": { "target_device": "ANY", // Target device, the specificity of which will be taken into account during optimization. diff --git a/tools/pot/openvino/tools/pot/algorithms/quantization/accuracy_aware/README.md b/tools/pot/openvino/tools/pot/algorithms/quantization/accuracy_aware/README.md index fcda4140e71..2ab67df921d 100644 --- a/tools/pot/openvino/tools/pot/algorithms/quantization/accuracy_aware/README.md +++ b/tools/pot/openvino/tools/pot/algorithms/quantization/accuracy_aware/README.md @@ -58,7 +58,7 @@ quantization time. Default value is `False`. ## Examples A template and full specification for AccuracyAwareQuantization algorithm: - * [Template](https://github.com/openvinotoolkit/openvino/blob/master/tools/pot/configs/accuracy_aware_quantization_template.json) + * [Template](https://github.com/openvinotoolkit/openvino/blob/master/tools/pot/openvino/tools/pot/configs/templates/accuracy_aware_quantization_template.json) * [Full specification](https://github.com/openvinotoolkit/openvino/blob/master/tools/pot/configs/accuracy_aware_quantization_spec.json) Example of using POT API with Accuracy-aware algorithm: diff --git a/tools/pot/openvino/tools/pot/algorithms/quantization/default/README.md b/tools/pot/openvino/tools/pot/algorithms/quantization/default/README.md index bb9ea902dea..3a8849f38d0 100644 --- a/tools/pot/openvino/tools/pot/algorithms/quantization/default/README.md +++ b/tools/pot/openvino/tools/pot/algorithms/quantization/default/README.md @@ -116,7 +116,7 @@ Enabling this option may increase compressed model accuracy, but will result in ## Examples A template and full specification for DefaultQuantization algorithm: - * [Template](https://github.com/openvinotoolkit/openvino/blob/master/tools/pot/configs/default_quantization_template.json) + * [Template](https://github.com/openvinotoolkit/openvino/blob/master/tools/pot/openvino/tools/pot/configs/templates/default_quantization_template.json) * [Full specification](https://github.com/openvinotoolkit/openvino/blob/master/tools/pot/configs/default_quantization_spec.json) Command-line example: diff --git a/tools/pot/openvino/tools/pot/app/run.py b/tools/pot/openvino/tools/pot/app/run.py index 3c3f2694c22..01d06c3777c 100644 --- a/tools/pot/openvino/tools/pot/app/run.py +++ b/tools/pot/openvino/tools/pot/app/run.py @@ -76,7 +76,7 @@ def _create_log_path(config): def _update_config_path(args): - config_template_folder = os.path.join(Path(__file__).parents[4], 'configs') + config_template_folder = os.path.join(Path(__file__).parents[1], 'configs', 'templates') if args.quantize is not None: if args.quantize == 'default': diff --git a/tools/pot/openvino/tools/pot/configs/templates/__init__.py b/tools/pot/openvino/tools/pot/configs/templates/__init__.py new file mode 100644 index 00000000000..6b0e0edda5b --- /dev/null +++ b/tools/pot/openvino/tools/pot/configs/templates/__init__.py @@ -0,0 +1,2 @@ +# Copyright (C) 2022 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 diff --git a/tools/pot/configs/accuracy_aware_quantization_template.json b/tools/pot/openvino/tools/pot/configs/templates/accuracy_aware_quantization_template.json similarity index 100% rename from tools/pot/configs/accuracy_aware_quantization_template.json rename to tools/pot/openvino/tools/pot/configs/templates/accuracy_aware_quantization_template.json diff --git a/tools/pot/configs/default_quantization_template.json b/tools/pot/openvino/tools/pot/configs/templates/default_quantization_template.json similarity index 100% rename from tools/pot/configs/default_quantization_template.json rename to tools/pot/openvino/tools/pot/configs/templates/default_quantization_template.json diff --git a/tools/pot/setup.py b/tools/pot/setup.py index bcc6c6bdd2b..07d41a9a7b5 100644 --- a/tools/pot/setup.py +++ b/tools/pot/setup.py @@ -25,11 +25,6 @@ class InstallCmd(install): # install requires self.do_egg_install() - def_quant_path = os.path.join("configs", "default_quantization_template.json") - aa_quant_path = os.path.join("configs", "accuracy_aware_quantization_template.json") - copyfile(def_quant_path, os.path.join(self.install_purelib, prefix, "pot", def_quant_path)) - copyfile(aa_quant_path, os.path.join(self.install_purelib, prefix, "pot", aa_quant_path)) - version_txt = os.path.join(prefix, "pot", "version.txt") if os.path.exists(version_txt): copyfile(os.path.join(version_txt), @@ -143,8 +138,9 @@ setup( url='https://software.intel.com/openvino-toolkit', packages=find_packages(exclude=["tests", "tests.*", "tools", "tools.*"]), - package_data={"openvino.tools.pot.configs.hardware": ['*.json'], - "openvino.tools.pot.api.samples": ['*.md', '*/*.md']}, + package_data={'openvino.tools.pot.configs.hardware': ['*.json'], + 'openvino.tools.pot.api.samples': ['*.md', '*/*.md'], + 'openvino.tools.pot.configs.templates': ['*.json']}, include_package_data=True, cmdclass={ 'install': InstallCmd,