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

Allow loading local models in a subfolder (with config in root) #933

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

tomaarsen
Copy link
Member

@tomaarsen tomaarsen commented Oct 9, 2024

What does this PR do?

  • Allow loading local models in a subfolder, also when the configuration is in root

Note: This PR depends on huggingface/optimum#2044 to be merged & released, and would require increasing the optimum version in the dependencies. I'm not sure how the optimum vs optimum-... dependencies are handled, so I'm not sure if this is a viable PR.

You can consider this a sister-PR to huggingface/optimum#2044 - the changes were also inspired from it.

What didn't work before?

import tempfile
from pathlib import Path

from huggingface_hub import HfApi
from optimum.intel import OVModelForFeatureExtraction

model_id = "sentence-transformers-testing/stsb-bert-tiny-openvino"

# hub model
ov_model = OVModelForFeatureExtraction.from_pretrained(model_id, subfolder="openvino", file_name="openvino_model.xml")
print("Hub model:", ov_model)

# local model
api = HfApi()
with tempfile.TemporaryDirectory() as tmpdirname:
    local_dir = Path(tmpdirname) / "model"
    api.snapshot_download(repo_id=model_id, local_dir=local_dir)

    ov_model = OVModelForFeatureExtraction.from_pretrained(local_dir, subfolder="openvino", file_name="openvino_model.xml")
    print("Remote model:", ov_model)

The second model from this snippet would not be loaded, because the subfolder was not being inserted between the model path and the filename. huggingface/optimum#2044 fixes the same issue but for ONNX.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

cc @echarlaix

  • Tom Aarsen

Copy link
Collaborator

@echarlaix echarlaix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @tomaarsen

@echarlaix echarlaix merged commit 95a80f0 into huggingface:main Oct 10, 2024
15 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.

2 participants