From 70f78ab0cc35da5943ab83d7adc8e563133c7164 Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Wed, 5 Jun 2024 21:30:54 +0200 Subject: [PATCH] Fix Windows TemporaryDirectory issue --- optimum/intel/openvino/modeling.py | 3 +++ optimum/intel/openvino/modeling_base.py | 3 +++ optimum/intel/openvino/modeling_base_seq2seq.py | 4 ++++ optimum/intel/openvino/modeling_decoder.py | 4 +++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/optimum/intel/openvino/modeling.py b/optimum/intel/openvino/modeling.py index 1c907f213..6e7fb1e9b 100644 --- a/optimum/intel/openvino/modeling.py +++ b/optimum/intel/openvino/modeling.py @@ -446,6 +446,9 @@ def _from_transformers( save_dir = TemporaryDirectory() save_dir_path = Path(save_dir.name) + # This attribute is needed to keep one reference on the temporary directory, since garbage collecting + # would end-up removing the directory containing the underlying OpenVINO model + cls._model_save_dir_tempdirectory_instance = save_dir # If load_in_8bit and quantization_config not specified then ov_config is set to None and will be set by default in convert depending on the model size if load_in_8bit is None and not quantization_config: diff --git a/optimum/intel/openvino/modeling_base.py b/optimum/intel/openvino/modeling_base.py index 7937deea5..48bf400ac 100644 --- a/optimum/intel/openvino/modeling_base.py +++ b/optimum/intel/openvino/modeling_base.py @@ -366,6 +366,9 @@ def _from_transformers( save_dir = TemporaryDirectory() save_dir_path = Path(save_dir.name) + # This attribute is needed to keep one reference on the temporary directory, since garbage collecting + # would end-up removing the directory containing the underlying OpenVINO model + cls._model_save_dir_tempdirectory_instance = save_dir # If load_in_8bit and quantization_config not specified then ov_config is set to None and will be set by default in convert depending on the model size if load_in_8bit is None and not quantization_config: diff --git a/optimum/intel/openvino/modeling_base_seq2seq.py b/optimum/intel/openvino/modeling_base_seq2seq.py index fb53f9b2e..7a37020a3 100644 --- a/optimum/intel/openvino/modeling_base_seq2seq.py +++ b/optimum/intel/openvino/modeling_base_seq2seq.py @@ -281,6 +281,10 @@ def _from_transformers( save_dir = TemporaryDirectory() save_dir_path = Path(save_dir.name) + # This attribute is needed to keep one reference on the temporary directory, since garbage collecting + # would end-up removing the directory containing the underlying OpenVINO model + cls._model_save_dir_tempdirectory_instance = save_dir + if task is None: task = cls.export_feature if use_cache: diff --git a/optimum/intel/openvino/modeling_decoder.py b/optimum/intel/openvino/modeling_decoder.py index fe7cf14c1..8618198cb 100644 --- a/optimum/intel/openvino/modeling_decoder.py +++ b/optimum/intel/openvino/modeling_decoder.py @@ -116,7 +116,6 @@ def __init__( quantization_config=quantization_config, **kwargs, ) - self.is_dynamic = dynamic_shapes use_cache = kwargs.pop("use_cache", True) model_has_sinks = model_has_state(self.model) @@ -256,6 +255,9 @@ def _from_transformers( save_dir = TemporaryDirectory() save_dir_path = Path(save_dir.name) + # This attribute is needed to keep one reference on the temporary directory, since garbage collecting + # would end-up removing the directory containing the underlying OpenVINO model + cls._model_save_dir_tempdirectory_instance = save_dir if task is None: task = cls.export_feature