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

Add $ to the end of filename regex patterns #931

Merged
merged 1 commit into from
Oct 9, 2024
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
2 changes: 1 addition & 1 deletion optimum/intel/openvino/modeling_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def from_pretrained(

ov_files = _find_files_matching_pattern(
model_dir,
pattern=r"(.*)?openvino(.*)?\_model.xml",
pattern=r"(.*)?openvino(.*)?\_model.xml$",
subfolder=subfolder,
use_auth_token=token,
revision=revision,
Expand Down
2 changes: 1 addition & 1 deletion optimum/intel/openvino/modeling_open_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def from_pretrained(

ov_files = _find_files_matching_pattern(
model_dir,
pattern=r"(.*)?openvino(.*)?\_model\_(.*)?.xml",
pattern=r"(.*)?openvino(.*)?\_model\_(.*)?.xml$",
subfolder=subfolder,
use_auth_token=token,
revision=revision,
Expand Down
21 changes: 19 additions & 2 deletions tests/openvino/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def test_infer_export_when_loading(self):

def test_find_files_matching_pattern(self):
model_id = "echarlaix/tiny-random-PhiForCausalLM"
pattern = r"(.*)?openvino(.*)?\_model.xml"
pattern = r"(.*)?openvino(.*)?\_model.xml$"
# hub model
for revision in ("main", "ov", "itrex"):
ov_files = _find_files_matching_pattern(
Expand All @@ -360,7 +360,7 @@ def test_find_files_matching_pattern(self):

@parameterized.expand(("stable-diffusion", "stable-diffusion-openvino"))
def test_find_files_matching_pattern_sd(self, model_arch):
pattern = r"(.*)?openvino(.*)?\_model.xml"
pattern = r"(.*)?openvino(.*)?\_model.xml$"
model_id = MODEL_NAMES[model_arch]
# hub model
ov_files = _find_files_matching_pattern(model_id, pattern=pattern)
Expand All @@ -374,6 +374,23 @@ def test_find_files_matching_pattern_sd(self, model_arch):
ov_files = _find_files_matching_pattern(local_dir, pattern=pattern)
self.assertTrue(len(ov_files) > 0 if "openvino" in model_id else len(ov_files) == 0)

@parameterized.expand(("", "openvino"))
def test_find_files_matching_pattern_with_config_in_root(self, subfolder):
# Notably, the model has a config.json file in the root directory and not in the subfolder
model_id = "sentence-transformers-testing/stsb-bert-tiny-openvino"
pattern = r"(.*)?openvino(.*)?\_model.xml$"
# hub model
ov_files = _find_files_matching_pattern(model_id, pattern=pattern, subfolder=subfolder)
self.assertTrue(len(ov_files) == 1 if subfolder == "openvino" else len(ov_files) == 0)

# 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_files = _find_files_matching_pattern(local_dir, pattern=pattern, subfolder=subfolder)
self.assertTrue(len(ov_files) == 1 if subfolder == "openvino" else len(ov_files) == 0)


class PipelineTest(unittest.TestCase):
def test_load_model_from_hub(self):
Expand Down
Loading