Skip to content
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
21 changes: 19 additions & 2 deletions mteb/models/model_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from huggingface_hub.errors import (
EntryNotFoundError,
GatedRepoError,
HFValidationError,
NotASafetensorsRepoError,
RepositoryNotFoundError,
SafetensorsParsingError,
Expand Down Expand Up @@ -305,7 +306,7 @@ def _from_hub(
embedding_dim = None
max_tokens = None

if model_name and compute_metadata and repo_exists(model_name):
if model_name and compute_metadata and _repo_exists(model_name):
reference = "https://huggingface.co/" + model_name
card = ModelCard.load(model_name)
card_data: ModelCardData = card.data
Expand Down Expand Up @@ -414,7 +415,7 @@ def from_hub(
meta.framework.append("Sentence Transformers")
meta.modalities = ["text"]

if model and compute_metadata and repo_exists(model):
if model and compute_metadata and _repo_exists(model):
# have max_seq_length field
sbert_config = _get_json_from_hub(
model, "sentence_bert_config.json", "model", revision=revision
Expand Down Expand Up @@ -785,3 +786,19 @@ def _get_file_on_hub(
except (GatedRepoError, RepositoryNotFoundError, EntryNotFoundError) as e:
logger.warning(f"Can't get file {file_name} of {repo_id}: {e}")
return None


def _repo_exists(repo_id: str, repo_type: str | None = None) -> bool:
"""Checks if a repository exists on HuggingFace Hub.

Repo exists will raise HFValidationError for invalid local paths

Args:
repo_id: The repository ID.
repo_type: The type of repository (e.g., "model", "dataset", "space").
"""
try:
return repo_exists(repo_id=repo_id, repo_type=repo_type)
except HFValidationError as e:
logger.warning(f"Can't check existence of {repo_id}: {e}")
return False
6 changes: 6 additions & 0 deletions tests/test_models/test_model_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,9 @@ def test_model_to_python():
contacts=None,
)"""
)


def test_model_meta_local_path():
meta = ModelMeta.from_hub("/path/to/local/model")
assert meta.name == "/path/to/local/model"
assert meta.revision == "no_revision_available"