Skip to content

fix: remove direct dependency on specific hf utils #244

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

Merged
merged 1 commit into from
May 21, 2025
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
15 changes: 4 additions & 11 deletions model2vec/distill/distillation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@

from model2vec.distill.inference import create_embeddings
from model2vec.distill.tokenizer import replace_vocabulary
from model2vec.distill.utils import Token, select_optimal_device
from model2vec.distill.utils import select_optimal_device
from model2vec.model import StaticModel
from model2vec.quantization import DType, quantize_embeddings

try:
# For huggingface_hub>=0.25.0
from huggingface_hub.errors import RepositoryNotFoundError
except ImportError:
# For huggingface_hub<0.25.0
from huggingface_hub.utils._errors import RepositoryNotFoundError


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -137,8 +129,9 @@ def distill_from_model(
try:
info = model_info(model_name)
language = info.cardData.get("language", None)
except RepositoryNotFoundError:
logger.info("No model info found for the model. Setting language to None.")
except Exception as e:
# NOTE: bare except because there's many reasons this can fail.
logger.warning(f"Couldn't get the model info from the Hugging Face Hub: {e}. Setting language to None.")
language = None

return StaticModel(
Expand Down
5 changes: 3 additions & 2 deletions model2vec/hf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ def load_pretrained(
)
)
metadata = _get_metadata_from_readme(Path(readme_path))
except huggingface_hub.utils.EntryNotFoundError:
logger.info("No README found in the model folder. No model card loaded.")
except Exception as e:
# NOTE: we don't want to raise an error here, since the README is optional.
logger.info(f"No README found in the model folder: {e} No model card loaded.")
metadata = {}

config_path = Path(
Expand Down