Skip to content

Commit

Permalink
Improve huggingface loading
Browse files Browse the repository at this point in the history
- Allow just `repo_id`
  • Loading branch information
HCookie committed Dec 9, 2024
1 parent b7b1440 commit 1eebd23
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/anemoi/inference/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import datetime
import logging
from collections import defaultdict
from pathlib import Path
from functools import cached_property

from anemoi.utils.checkpoints import load_metadata
Expand All @@ -24,11 +25,19 @@
def _download_huggingfacehub(huggingface_config):
"""Download model from huggingface"""
try:
from huggingface_hub import hf_hub_download
from huggingface_hub import hf_hub_download, snapshot_download
except ImportError as e:
raise ImportError("Could not import `huggingface_hub`, please run `pip install huggingface_hub`.") from e

config_path = hf_hub_download(**huggingface_config)
if 'filename' in huggingface_config:
config_path = hf_hub_download(**huggingface_config)
else:
repo_path = Path(snapshot_download(**huggingface_config))
ckpt_files = list(repo_path.glob('*.ckpt'))
if len(ckpt_files) == 1:
return str(ckpt_files[0])
else:
ValueError(f"Multiple ckpt files found in repo, {ckpt_files}.\nCannot pick one to load, please specify `filename`.")
return config_path


Expand Down

0 comments on commit 1eebd23

Please sign in to comment.