Download training_code/scripts/60_verify_hf.py from TrendeX90/expected-greenness: direct link, hf CLI and curl.
- Browser
- Download file 2.79 kB
-
https://huggingface.co/TrendeX90/expected-greenness/resolve/main/training_code/scripts/60_verify_hf.py
- Command line
-
hf download hf://TrendeX90/expected-greenness/training_code/scripts/60_verify_hf.py
-
curl -L -o 60_verify_hf.py https://huggingface.co/TrendeX90/expected-greenness/resolve/main/training_code/scripts/60_verify_hf.py
2.79 kB
| """Verify what is on Hugging Face from a clean machine (no access to the Vast box). | |
| uv run --with xgboost --with pandas --with pyarrow --with huggingface_hub python scripts/60_verify_hf.py | |
| 1. Downloads TrendeX90/expected-greenness at tag v1, runs the golden test with its own predict.py. | |
| 2. Reads naryn-cube: manifest, cells.parquet, one year of monthly data, products summary. | |
| """ | |
| from __future__ import annotations | |
| import importlib.util | |
| import json | |
| import sys | |
| import tempfile | |
| from pathlib import Path | |
| import numpy as np | |
| import pandas as pd | |
| from huggingface_hub import HfApi, hf_hub_download, snapshot_download | |
| MODEL, CUBE = "TrendeX90/expected-greenness", "TrendeX90/naryn-cube" | |
| def main() -> None: | |
| api = HfApi() | |
| tags = [t.name for t in api.list_repo_refs(MODEL).tags] | |
| print("model tags:", tags) | |
| with tempfile.TemporaryDirectory() as tmp: | |
| root = Path(snapshot_download(MODEL, revision="v1", local_dir=Path(tmp) / "model")) | |
| print("model files:", sorted(p.name for p in root.iterdir() if not p.name.startswith("."))) | |
| spec = importlib.util.spec_from_file_location("predict", root / "predict.py") | |
| mod = importlib.util.module_from_spec(spec) | |
| sys.modules["predict"] = mod | |
| spec.loader.exec_module(mod) | |
| m = mod.load(root) | |
| got = m.predict(pd.read_parquet(root / "golden" / "inputs.parquet")) | |
| want = pd.read_parquet(root / "golden" / "expected.parquet") | |
| diff = float(np.max(np.abs(got.values - want.values))) | |
| print(f"golden test on this machine: max diff {diff:.2e} -> {'PASS' if diff < 1e-6 else 'FAIL'}") | |
| metrics = json.loads((root / "metrics.json").read_text()) | |
| print("gate:", metrics["gate"]) | |
| files = api.list_repo_files(CUBE, repo_type="dataset") | |
| print(f"cube files: {len(files)} | monthly years: {sum(f.startswith('monthly/') for f in files)} | " | |
| f"products: {sorted(f for f in files if f.startswith('products/'))}") | |
| man = json.loads(Path(hf_hub_download(CUBE, "manifest.json", repo_type="dataset")).read_text()) | |
| print("manifest: synthetic =", man["synthetic"], "| partial =", man["partial"], "| sources =", man["sources_used"]) | |
| cells = pd.read_parquet(hf_hub_download(CUBE, "cells.parquet", repo_type="dataset")) | |
| print("cells:", len(cells), "| in oblast:", int(cells["in_oblast"].sum())) | |
| y = pd.read_parquet(hf_hub_download(CUBE, "monthly/year=2024/part.parquet", repo_type="dataset")) | |
| print("monthly 2024 rows:", len(y), "| columns:", list(y.columns)) | |
| summ = json.loads(Path(hf_hub_download(CUBE, "products/products_summary.json", repo_type="dataset")).read_text()) | |
| print("residual trend shares:", summ["residual_trend_cell_class_shares"]) | |
| print("VERIFY_DONE") | |
| if __name__ == "__main__": | |
| main() | |