Skip to content

Commit 95a80f0

Browse files
authored
Allow loading model models in a subfolder (with config in root) (#933)
1 parent cb5208c commit 95a80f0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

optimum/intel/openvino/modeling_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def _cached_file(
512512
# locates a file in a local folder and repo, downloads and cache it if necessary.
513513
model_path = Path(model_path)
514514
if model_path.is_dir():
515-
model_cache_path = model_path / file_name
515+
model_cache_path = model_path / subfolder / file_name
516516
else:
517517
file_name = Path(file_name)
518518
if file_name.suffix != ".onnx":

tests/openvino/test_modeling.py

+14
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,20 @@ def test_load_model_from_hub_private_with_token(self):
324324
self.assertIsInstance(model.config, PretrainedConfig)
325325
self.assertTrue(model.stateful)
326326

327+
@parameterized.expand(("", "openvino"))
328+
def test_loading_with_config_in_root(self, subfolder):
329+
# config.json file in the root directory and not in the subfolder
330+
model_id = "sentence-transformers-testing/stsb-bert-tiny-openvino"
331+
export = subfolder == ""
332+
# hub model
333+
OVModelForFeatureExtraction.from_pretrained(model_id, subfolder=subfolder, export=export)
334+
# local model
335+
api = HfApi()
336+
with tempfile.TemporaryDirectory() as tmpdirname:
337+
local_dir = Path(tmpdirname) / "model"
338+
api.snapshot_download(repo_id=model_id, local_dir=local_dir)
339+
OVModelForFeatureExtraction.from_pretrained(local_dir, subfolder=subfolder, export=export)
340+
327341
def test_infer_export_when_loading(self):
328342
model_id = MODEL_NAMES["phi"]
329343
model = AutoModelForCausalLM.from_pretrained(model_id)

0 commit comments

Comments
 (0)