Skip to content

Commit

Permalink
print properties of compile model
Browse files Browse the repository at this point in the history
  • Loading branch information
wgzintel committed Dec 11, 2023
1 parent f32d501 commit 457e563
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion optimum/intel/openvino/modeling_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from ...exporters.openvino import export, main_export
from ..utils.import_utils import is_nncf_available, is_transformers_version
from .utils import ONNX_WEIGHTS_NAME, OV_XML_FILE_NAME
from .utils import ONNX_WEIGHTS_NAME, OV_XML_FILE_NAME, print_compile_model_properties


if is_transformers_version("<", "4.25.0"):
Expand Down Expand Up @@ -346,6 +346,11 @@ def compile(self):
ov_config["CACHE_DIR"] = str(cache_dir)
logger.info(f"Setting OpenVINO CACHE_DIR to {str(cache_dir)}")
self.request = core.compile_model(self.model, self._device, ov_config)
# OPENVINO_LOG_LEVEL can be found in https://docs.openvino.ai/2023.2/openvino_docs_OV_UG_supported_plugins_AUTO_debugging.html
if 'OPENVINO_LOG_LEVEL' in os.environ and int(os.environ['OPENVINO_LOG_LEVEL']) > 2:
logger.info(f'{self._device} SUPPORTED_PROPERTIES:')
print_compile_model_properties(self.request)


def _reshape(
self,
Expand Down
21 changes: 21 additions & 0 deletions optimum/intel/openvino/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
import json
import os
from glob import glob
import logging

import numpy as np
from huggingface_hub import model_info
from openvino.runtime import Type
from transformers.onnx.utils import ParameterFormat, compute_serialized_parameters_size


logger = logging.getLogger(__name__)

OV_XML_FILE_NAME = "openvino_model.xml"
OV_ENCODER_NAME = "openvino_encoder_model.xml"
OV_DECODER_NAME = "openvino_decoder_model.xml"
Expand Down Expand Up @@ -123,3 +126,21 @@ def _is_timm_ov_dir(model_dir):
if hf_hub_id and model_info(hf_hub_id).library_name == "timm":
return True
return False


def param_to_string(parameters) -> str:
"""Convert a list / tuple of parameters returned from IE to a string."""
if isinstance(parameters, (list, tuple)):
return ', '.join([str(x) for x in parameters])
else:
return str(parameters)


def print_compile_model_properties(compile_model):
for property_key in compile_model.get_property('SUPPORTED_PROPERTIES'):
if property_key not in ('SUPPORTED_METRICS', 'SUPPORTED_CONFIG_KEYS', 'SUPPORTED_PROPERTIES'):
try:
property_val = compile_model.get_property(property_key)
except TypeError:
property_val = 'UNSUPPORTED TYPE'
logger.info(f'\t{property_key}: {param_to_string(property_val)}')

0 comments on commit 457e563

Please sign in to comment.