Skip to content

Commit

Permalink
Fix for Python 3.8
Browse files Browse the repository at this point in the history
Path.is_relative_to() was added in Python 3.9
  • Loading branch information
helena-intel committed Oct 25, 2023
1 parent 11d38f4 commit fe658be
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion optimum/intel/openvino/modeling_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion optimum/intel/openvino/modeling_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions optimum/intel/openvino/modeling_seq2seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit fe658be

Please sign in to comment.