Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reference to temporary directory #581

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions optimum/intel/openvino/modeling_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,18 @@ def __init__(
self._device = device.upper()
self.is_dynamic = dynamic_shapes
self.ov_config = ov_config if ov_config is not None else {}
self._model_save_dir = (
Path(model_save_dir.name) if isinstance(model_save_dir, TemporaryDirectory) else model_save_dir
)

# 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
self._model_save_dir_tempdirectory_instance = None
if isinstance(model_save_dir, TemporaryDirectory):
self._model_save_dir_tempdirectory_instance = model_save_dir
self._model_save_dir = Path(model_save_dir.name)
elif isinstance(model_save_dir, str):
self._model_save_dir = Path(model_save_dir)
else:
self._model_save_dir = model_save_dir

self.vae_decoder = OVModelVaeDecoder(vae_decoder, self)
self.unet = OVModelUnet(unet, self)
self.text_encoder = OVModelTextEncoder(text_encoder, self) if text_encoder is not None else None
Expand Down
Loading