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

fix misplaced configs saving #1159

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions optimum/intel/openvino/modeling_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,12 @@ def _save_pretrained(self, save_directory: Union[str, Path]):
dst_path = save_path / OV_XML_FILE_NAME
dst_path.parent.mkdir(parents=True, exist_ok=True)
openvino.save_model(model.model, dst_path, compress_to_fp16=False)
model_dir = model.config.get("_name_or_path", None) or model.model_save_dir
config_path = Path(model_dir) / CONFIG_NAME
model_dir = (
self.model_save_dir
if not isinstance(self.model_save_dir, TemporaryDirectory)
else self.model_save_dir.name
)
config_path = Path(model_dir) / save_path.name / CONFIG_NAME
if config_path.is_file():
config_save_path = save_path / CONFIG_NAME
shutil.copyfile(config_path, config_save_path)
Expand Down
7 changes: 7 additions & 0 deletions tests/openvino/test_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ def test_load_and_save_pipeline_with_safety_checker(self):
self.assertTrue(model_lib in ["diffusers", "transformers"])
self.assertFalse(model_class.startswith("OV"))
loaded_pipeline = self.OVMODEL_CLASS.from_pretrained(tmpdirname)
for component in ["text_encoder", "unet", "vae_encoder", "vae_decoder"]:
config = getattr(getattr(ov_pipeline, component), "config", None)
if config is not None:
loaded_config = getattr(getattr(loaded_pipeline, component), "config")
self.assertDictEqual(
config, loaded_config, f"Expected config:\n{config}\nLoaded config:|n{loaded_config}"
)
self.assertTrue(loaded_pipeline.safety_checker is not None)
self.assertIsInstance(loaded_pipeline.safety_checker, StableDiffusionSafetyChecker)
del loaded_pipeline
Expand Down
Loading