diff --git a/optimum/intel/openvino/modeling_base.py b/optimum/intel/openvino/modeling_base.py index cb103bb35a..eb1ed88467 100644 --- a/optimum/intel/openvino/modeling_base.py +++ b/optimum/intel/openvino/modeling_base.py @@ -339,7 +339,7 @@ def compile(self): if self.request is None: logger.info(f"Compiling the model to {self._device} ...") ov_config = {**self.ov_config} - if "CACHE_DIR" not in self.ov_config.keys() and not self.model_save_dir.is_relative_to(gettempdir()): + if "CACHE_DIR" not in self.ov_config.keys() and not str(self.model_save_dir).startswith(gettempdir()): # Set default CACHE_DIR only if it is not set, and if the model is not in a temporary directory cache_dir = Path(self.model_save_dir).joinpath("model_cache") ov_config["CACHE_DIR"] = str(cache_dir) diff --git a/optimum/intel/openvino/modeling_diffusion.py b/optimum/intel/openvino/modeling_diffusion.py index c88b61e58a..2707260606 100644 --- a/optimum/intel/openvino/modeling_diffusion.py +++ b/optimum/intel/openvino/modeling_diffusion.py @@ -539,7 +539,7 @@ def __init__( self._model_dir = Path(model_dir or parent_model._model_save_dir) config_path = self._model_dir / model_name / self.CONFIG_NAME self.config = self.parent_model._dict_from_json_file(config_path) if config_path.is_file() else {} - if "CACHE_DIR" not in self.ov_config.keys() and not self._model_dir.is_relative_to(gettempdir()): + if "CACHE_DIR" not in self.ov_config.keys() and not str(self._model_dir).startswith(gettempdir()): self.ov_config["CACHE_DIR"] = os.path.join(self._model_dir, self._model_name, "model_cache") def _compile(self): diff --git a/optimum/intel/openvino/modeling_seq2seq.py b/optimum/intel/openvino/modeling_seq2seq.py index f2e2a989b7..c800312e82 100644 --- a/optimum/intel/openvino/modeling_seq2seq.py +++ b/optimum/intel/openvino/modeling_seq2seq.py @@ -205,7 +205,7 @@ def __init__( encoder_cache_dir = Path(self.model_save_dir).joinpath("encoder_cache") ov_encoder_config = self.ov_config - if "CACHE_DIR" not in ov_encoder_config.keys() and not self.model_save_dir.is_relative_to(gettempdir()): + if "CACHE_DIR" not in ov_encoder_config.keys() and not str(self.model_save_dir).startswith(gettempdir()): ov_encoder_config["CACHE_DIR"] = str(encoder_cache_dir) self.encoder = OVEncoder( @@ -215,7 +215,7 @@ def __init__( decoder_cache_dir = Path(self.model_save_dir).joinpath("decoder_cache") ov_decoder_config = self.ov_config - if "CACHE_DIR" not in ov_decoder_config.keys() and not self.model_save_dir.is_relative_to(gettempdir()): + if "CACHE_DIR" not in ov_decoder_config.keys() and not str(self.model_save_dir).startswith(gettempdir()): ov_decoder_config["CACHE_DIR"] = str(decoder_cache_dir) self.decoder = OVDecoder(self.decoder_model, self._device, ov_decoder_config) @@ -224,7 +224,7 @@ def __init__( decoder_past_cache_dir = Path(self.model_save_dir).joinpath("decoder_past_cache") ov_decoder_past_config = self.ov_config - if "CACHE_DIR" not in ov_decoder_past_config.keys() and not self.model_save_dir.is_relative_to( + if "CACHE_DIR" not in ov_decoder_past_config.keys() and not str(self.model_save_dir).startswith( gettempdir() ): ov_decoder_past_config["CACHE_DIR"] = str(decoder_past_cache_dir)