From 43ddf460c1fa00222d0565f4c88fa10f561fb249 Mon Sep 17 00:00:00 2001 From: Helena Date: Tue, 30 Jan 2024 17:10:51 +0100 Subject: [PATCH 1/3] Show device name in _print_compiled_model_properties Enable CACHE_DIR also for devices like "GPU:0" --- optimum/intel/openvino/modeling_base.py | 2 +- optimum/intel/openvino/modeling_diffusion.py | 2 +- optimum/intel/openvino/modeling_seq2seq.py | 4 ++-- optimum/intel/openvino/utils.py | 8 +++++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/optimum/intel/openvino/modeling_base.py b/optimum/intel/openvino/modeling_base.py index 97ad432fa6..38527dae7a 100644 --- a/optimum/intel/openvino/modeling_base.py +++ b/optimum/intel/openvino/modeling_base.py @@ -349,7 +349,7 @@ def compile(self): if ( "CACHE_DIR" not in self.ov_config.keys() and not str(self.model_save_dir).startswith(gettempdir()) - and self._device.lower() == "gpu" + and self._device.lower().split(":")[0] == "gpu" ): # Set default CACHE_DIR only if it is not set, if the model is not in a temporary directory, and device is GPU cache_dir = Path(self.model_save_dir).joinpath("model_cache") diff --git a/optimum/intel/openvino/modeling_diffusion.py b/optimum/intel/openvino/modeling_diffusion.py index 41f06936f8..277aa14518 100644 --- a/optimum/intel/openvino/modeling_diffusion.py +++ b/optimum/intel/openvino/modeling_diffusion.py @@ -547,7 +547,7 @@ def _compile(self): if ( "CACHE_DIR" not in self.ov_config.keys() and not str(self._model_dir).startswith(gettempdir()) - and self.device.lower() == "gpu" + and self.device.lower().split(":")[0] == "gpu" ): self.ov_config["CACHE_DIR"] = os.path.join(self._model_dir, self._model_name, "model_cache") diff --git a/optimum/intel/openvino/modeling_seq2seq.py b/optimum/intel/openvino/modeling_seq2seq.py index 7e9f582799..34735507bb 100644 --- a/optimum/intel/openvino/modeling_seq2seq.py +++ b/optimum/intel/openvino/modeling_seq2seq.py @@ -456,7 +456,7 @@ def _compile(self): if ( "CACHE_DIR" not in ov_config.keys() and not str(self.parent_model.model_save_dir).startswith(gettempdir()) - and self._device.lower() == "gpu" + and self._device.lower().split(":")[0] == "gpu" ): cache_dir = Path(self.parent_model.model_save_dir).joinpath("model_cache") ov_config["CACHE_DIR"] = str(cache_dir) @@ -568,7 +568,7 @@ def _compile(self): if ( "CACHE_DIR" not in ov_config.keys() and not str(self.parent_model.model_save_dir).startswith(gettempdir()) - and self._device.lower() == "gpu" + and self._device.lower().startswith("gpu") ): cache_dir = Path(self.parent_model.model_save_dir).joinpath("model_cache") ov_config["CACHE_DIR"] = str(cache_dir) diff --git a/optimum/intel/openvino/utils.py b/optimum/intel/openvino/utils.py index 46442d4d22..d7a4e5e4e1 100644 --- a/optimum/intel/openvino/utils.py +++ b/optimum/intel/openvino/utils.py @@ -20,7 +20,7 @@ import numpy as np from huggingface_hub import model_info -from openvino.runtime import Type, properties +from openvino.runtime import Core, Type, properties from transformers.onnx.utils import ParameterFormat, compute_serialized_parameters_size @@ -145,3 +145,9 @@ def _print_compiled_model_properties(compiled_model): logger.info(f" {k}: {value}") except Exception: logger.error(f"[error] Get property of '{k}' failed") + try: + logger.info("EXECUTION_DEVICES:") + for device in compiled_model.get_property("EXECUTION_DEVICES"): + logger.info(f" {device}: {Core().get_property(device, 'FULL_DEVICE_NAME')}") + except Exception: + logger.error("[error] Get FULL_DEVICE_NAME failed") From 52445f42954969f01c1f0f5217365abc9a3e49c9 Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Tue, 12 Mar 2024 14:34:13 +0100 Subject: [PATCH 2/3] Update optimum/intel/openvino/modeling_seq2seq.py Co-authored-by: Ella Charlaix <80481427+echarlaix@users.noreply.github.com> --- optimum/intel/openvino/modeling_seq2seq.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimum/intel/openvino/modeling_seq2seq.py b/optimum/intel/openvino/modeling_seq2seq.py index 34735507bb..08eacf355e 100644 --- a/optimum/intel/openvino/modeling_seq2seq.py +++ b/optimum/intel/openvino/modeling_seq2seq.py @@ -456,7 +456,7 @@ def _compile(self): if ( "CACHE_DIR" not in ov_config.keys() and not str(self.parent_model.model_save_dir).startswith(gettempdir()) - and self._device.lower().split(":")[0] == "gpu" + and "gpu" in self._device.lower() ): cache_dir = Path(self.parent_model.model_save_dir).joinpath("model_cache") ov_config["CACHE_DIR"] = str(cache_dir) From 8927cd87e4c6c0727ab5c5286d8ed835c2afe9e4 Mon Sep 17 00:00:00 2001 From: Helena Date: Tue, 12 Mar 2024 15:25:47 +0100 Subject: [PATCH 3/3] Change check for gpu device --- optimum/intel/openvino/modeling_base.py | 2 +- optimum/intel/openvino/modeling_seq2seq.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/optimum/intel/openvino/modeling_base.py b/optimum/intel/openvino/modeling_base.py index 38527dae7a..e0ed193f6d 100644 --- a/optimum/intel/openvino/modeling_base.py +++ b/optimum/intel/openvino/modeling_base.py @@ -349,7 +349,7 @@ def compile(self): if ( "CACHE_DIR" not in self.ov_config.keys() and not str(self.model_save_dir).startswith(gettempdir()) - and self._device.lower().split(":")[0] == "gpu" + and "gpu" in self._device.lower() ): # Set default CACHE_DIR only if it is not set, if the model is not in a temporary directory, and device is GPU cache_dir = Path(self.model_save_dir).joinpath("model_cache") diff --git a/optimum/intel/openvino/modeling_seq2seq.py b/optimum/intel/openvino/modeling_seq2seq.py index 08eacf355e..2bf4c56555 100644 --- a/optimum/intel/openvino/modeling_seq2seq.py +++ b/optimum/intel/openvino/modeling_seq2seq.py @@ -568,7 +568,7 @@ def _compile(self): if ( "CACHE_DIR" not in ov_config.keys() and not str(self.parent_model.model_save_dir).startswith(gettempdir()) - and self._device.lower().startswith("gpu") + and "gpu" in self._device.lower() ): cache_dir = Path(self.parent_model.model_save_dir).joinpath("model_cache") ov_config["CACHE_DIR"] = str(cache_dir)