diff --git a/tests/openvino/tools/calibrate.py b/tests/openvino/tools/calibrate.py index a044bf8f269..c0542180223 100644 --- a/tests/openvino/tools/calibrate.py +++ b/tests/openvino/tools/calibrate.py @@ -14,6 +14,8 @@ import json import multiprocessing import os +import platform +import subprocess from argparse import ArgumentParser from collections import OrderedDict from collections import defaultdict @@ -26,6 +28,7 @@ import numpy as np import openvino.runtime as ov +import pkg_resources from config import Config from openvino.runtime import Dimension from openvino.runtime import PartialShape @@ -41,6 +44,7 @@ import nncf from nncf.common.deprecation import warning_deprecated +from nncf.common.logging import nncf_logger from nncf.common.logging.logger import set_log_file from nncf.common.quantization.structs import QuantizationPreset from nncf.common.quantization.structs import QuantizationScheme @@ -1076,6 +1080,67 @@ def update_nncf_algorithms_config(nncf_algorithms_config: Dict[str, Dict[str, An print(f"Updated subset_size value for {nncf_method} method to {new_subset_size} ") +class EnvInfo: + + @staticmethod + def print_info() -> None: + """ + Prints NNCF version, python version and CPU model name. + """ + python_version = EnvInfo._get_python_version() + nncf_version = EnvInfo._get_nncf_version() + cpu_model = EnvInfo._get_cpu_model() + + nncf_logger.info(f"Python version: {python_version}") + nncf_logger.info(f"NNCF version: {nncf_version}") + nncf_logger.info(f"CPU model: {cpu_model}") + + @staticmethod + def _get_nncf_version() -> str: + try: + version = pkg_resources.get_distribution("nncf").version + except pkg_resources.DistributionNotFound: + version = "Unknown" + return version + + @staticmethod + def _get_python_version() -> str: + return platform.python_version() + + @staticmethod + def _get_cpu_model() -> str: + """ + Returns CPU device name. + """ + + def _get_cpu_model_name_linux_os() -> str: + try: + output = subprocess.check_output("lscpu", shell=True) + for line in output.decode().splitlines(): + if "Model name:" in line: + return line.split(":")[1].strip() + return "Unknown" + except Exception: + return "Unknown" + + def _get_cpu_model_name_windows() -> str: + try: + output = subprocess.check_output("wmic cpu get name", shell=True) + return output.decode().splitlines()[1].strip() + except Exception: + return "Unknown" + + os_name = platform.system() + + cpu_model = "Unknown" + if os_name == "Linux": + cpu_model = _get_cpu_model_name_linux_os() + elif os_name == "Windows": + cpu_model = _get_cpu_model_name_windows() + + return cpu_model + + def main(): args = parse_args() if args.impl is not None: @@ -1095,6 +1160,8 @@ def main(): output_dir = os.path.join(args.output_dir, "optimized") os.makedirs(output_dir, exist_ok=True) + EnvInfo.print_info() + algo_name_to_method_map = { "quantize": quantize_model, "quantize_with_accuracy_control": quantize_model_with_accuracy_control,