huggingface / optimum-intel

🤗 Optimum Intel: Accelerate inference with Intel optimization tools
https://huggingface.co/docs/optimum/main/en/intel/index
Apache License 2.0
415 stars 112 forks source link

restore original model_index.json after save_pretrained call #961

Closed eaidova closed 1 month ago

eaidova commented 1 month ago

What does this PR do?

due to registration ov diffusion pipeline components in pipeline config, their classes appears in model_index.json after OVDiffusionPipeline.save_pretrained().

>>from optimum.intel.openvino import OVDiffusionPipeline

>>pipe = OVPipelineForText2Image.from_pretrained("hf-internal-testing/tiny-stable-diffusion-pipe-variants-right-format")
>>pipe.config
FrozenDict([('vae', ('optimum.intel.openvino.modeling_diffusion', 'OVModelVae')), ('text_encoder', ('optimum.intel.openvino.modeling_diffusion', 'OVModelTextEncoder')), ('tokenizer', ('transformers', 'CLIPTokenizer')), ('unet', ('optimum.intel.openvino.modeling_diffusion', 'OVModelUnet')), ('scheduler', ('diffusers', 'DDIMScheduler')), ('safety_checker', (None, None)), ('feature_extractor', ('transformers', 'CLIPFeatureExtractor')), ('image_encoder', (None, None)), ('requires_safety_checker', True), ('_name_or_path', '/tmp/tmpxgc_1oo1')]

That may bring some inconvinience:

from diffusers import DiffusionPipeline
from optimum.intel.openvino import OVDiffusionPipeline

save_dir = "common_repo"
model_id = "hf-internal-testing/tiny-stable-diffusion-pipe-variants-right-format"
pipe = DiffusionPipeline.from_pretrained(model_id)
pipe.save_pretrained(save_dir)

ov_pipe = OVDiffusionPipeline.from_pretrained(model_id)
ov_pipe.save_pretrained(save_dir)

# try to load original pipeline again
pipe_from_local_dir = DiffusionPipeline.from_pretrained(save_dir)

raises error:

diffusers/utils/import_utils.py", line 846, in __getattr__
    raise AttributeError(f"module {self.__name__} has no attribute {name}")
AttributeError: module diffusers has no attribute OVStableDiffusionPipeline
HuggingFaceDocBuilderDev commented 1 month ago

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.