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

restore original model_index.json after save_pretrained call #961

Conversation

eaidova
Copy link
Collaborator

@eaidova eaidova commented Oct 23, 2024

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:

  • misalignment between optimum-cli result (cli tool preserves original model_index.json) and save_pretrained results
  • impossibility store original and ov pipeline in the same local directory or hub repository. if ov pipeline will be saved vi save_pretrained after original pipeline, you will not able to use original pipeline (model index json will contains wrong class names):
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

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.

@eaidova eaidova force-pushed the ea/restore_original_model_index_after_save_pretrained branch from b41d5d5 to bc88e42 Compare October 23, 2024 16:18
@IlyasMoutawwakil IlyasMoutawwakil merged commit a432102 into huggingface:main Oct 24, 2024
12 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants