Skip to content

Commit

Permalink
Extend NNCF logging by the device information where quantization was …
Browse files Browse the repository at this point in the history
…done (#2931)

### Changes

Extend NNCF logging by the device information where quantization was
done

### Related tickets

Ref: 150780
  • Loading branch information
andrey-churkin authored Sep 5, 2024
1 parent ca41c70 commit d7bb1ca
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/openvino/tools/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand Down

0 comments on commit d7bb1ca

Please sign in to comment.