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
11 changes: 11 additions & 0 deletions hub/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"model_type": "nesso1",
"architectures": ["Nesso1"],
"library_name": "nesso",
"default_revision": "v1.0.0",
"files": {
"hparams": "hparams.json",
"weights": "model.safetensors",
"ccd": "ccd.pkl"
}
}
20 changes: 20 additions & 0 deletions nesso/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
FALLBACK_REVISION = "main"
MODEL_WEIGHTS_NAME = "model.safetensors"
MODEL_HPARAMS_NAME = "hparams.json"
# Root query file used by the Hub for download counting (GET/HEAD on this path).
# See https://huggingface.co/docs/hub/models-download-stats
MODEL_CONFIG_NAME = "config.json"


def get_default_model_revision() -> str:
Expand Down Expand Up @@ -109,6 +112,23 @@ def ensure_cache(
if checkpoint is not None:
model_dir = checkpoint
else:
# Fetch the Hub query file so this load is counted in download stats.
# Always from ``main`` so version tags need not re-copy this file.
try:
from huggingface_hub.errors import EntryNotFoundError

hf_hub_download(
repo_id=HF_REPO_ID,
filename=MODEL_CONFIG_NAME,
revision="main",
cache_dir=hf_cache_dir,
)
except EntryNotFoundError as exc:
warnings.warn(
f"Could not download Hub query file {MODEL_CONFIG_NAME!r} "
f"(download stats will not increment): {exc}",
stacklevel=2,
)
weights = Path(
hf_hub_download(
repo_id=HF_REPO_ID,
Expand Down
13 changes: 13 additions & 0 deletions nesso/model/models/nesso1.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,19 @@ def from_pretrained(
except PackageNotFoundError:
hub_revision = "main"

# Root ``config.json`` is the Hub download-stats query file; fetch it
# from ``main`` so Hub loads are counted (hparams/weights alone are not).
try:
from huggingface_hub.errors import EntryNotFoundError

hf_hub_download(
repo_id=str(pretrained_model_name_or_path),
filename="config.json",
revision="main",
cache_dir=cache_dir,
)
except EntryNotFoundError:
pass
hparams_path = Path(
hf_hub_download(
repo_id=str(pretrained_model_name_or_path),
Expand Down
Loading