Skip to content

Commit

Permalink
Fix Windows TemporaryDirectory issue (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
helena-intel authored Jun 6, 2024
1 parent dad18d1 commit 66191a3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions optimum/intel/openvino/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions optimum/intel/openvino/modeling_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions optimum/intel/openvino/modeling_base_seq2seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion optimum/intel/openvino/modeling_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 66191a3

Please sign in to comment.