File size: 2,787 Bytes
7e6579d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""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()