Skip to content

Commit 15207a8

Browse files
authored
fix: remove direct dependency on specific hf utils (MinishLab#244)
1 parent 562c14d commit 15207a8

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

model2vec/distill/distillation.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,10 @@
1313

1414
from model2vec.distill.inference import create_embeddings
1515
from model2vec.distill.tokenizer import replace_vocabulary
16-
from model2vec.distill.utils import Token, select_optimal_device
16+
from model2vec.distill.utils import select_optimal_device
1717
from model2vec.model import StaticModel
1818
from model2vec.quantization import DType, quantize_embeddings
1919

20-
try:
21-
# For huggingface_hub>=0.25.0
22-
from huggingface_hub.errors import RepositoryNotFoundError
23-
except ImportError:
24-
# For huggingface_hub<0.25.0
25-
from huggingface_hub.utils._errors import RepositoryNotFoundError
26-
27-
2820
logger = logging.getLogger(__name__)
2921

3022

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

144137
return StaticModel(

model2vec/hf_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ def load_pretrained(
158158
)
159159
)
160160
metadata = _get_metadata_from_readme(Path(readme_path))
161-
except huggingface_hub.utils.EntryNotFoundError:
162-
logger.info("No README found in the model folder. No model card loaded.")
161+
except Exception as e:
162+
# NOTE: we don't want to raise an error here, since the README is optional.
163+
logger.info(f"No README found in the model folder: {e} No model card loaded.")
163164
metadata = {}
164165

165166
config_path = Path(

0 commit comments

Comments
 (0)