Spaces:
Paused
Paused
Download scripts/check_scorer_sync.py from KinetkAI/sdi-leaderboard: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/KinetkAI/sdi-leaderboard/resolve/main/scripts/check_scorer_sync.py
- Command line
-
hf download hf://spaces/KinetkAI/sdi-leaderboard/scripts/check_scorer_sync.py
-
curl -L -o check_scorer_sync.py https://huggingface.co/spaces/KinetkAI/sdi-leaderboard/resolve/main/scripts/check_scorer_sync.py
1.62 kB
| """Guard against drift between the two copies of the SDI scorer. | |
| The canonical scorer lives in the benchmark dataset repo as | |
| `kinetk_sdi/sdi.py`; this Space vendors a byte-identical copy as `sdi.py`. | |
| Run this before every push of either repo: | |
| python scripts/check_scorer_sync.py | |
| It compares against a sibling `../sdi-benchmark` checkout when present, | |
| otherwise against the published copy on the HF Hub. Exits non-zero on drift. | |
| """ | |
| from __future__ import annotations | |
| import hashlib | |
| import os | |
| import sys | |
| from pathlib import Path | |
| REPO_ROOT = Path(__file__).resolve().parent.parent | |
| LOCAL_COPY = REPO_ROOT / "sdi.py" | |
| SIBLING_COPY = REPO_ROOT.parent / "sdi-benchmark" / "kinetk_sdi" / "sdi.py" | |
| DATA_REPO = os.environ.get("DATA_REPO", "KinetkAI/KINETK-SDI-Benchmark") | |
| def _sha256(path: Path) -> str: | |
| return hashlib.sha256(path.read_bytes()).hexdigest() | |
| def main() -> int: | |
| if SIBLING_COPY.is_file(): | |
| canonical, origin = SIBLING_COPY, str(SIBLING_COPY) | |
| else: | |
| from huggingface_hub import hf_hub_download | |
| canonical = Path( | |
| hf_hub_download(DATA_REPO, "kinetk_sdi/sdi.py", repo_type="dataset") | |
| ) | |
| origin = f"{DATA_REPO} (Hub)" | |
| local, remote = _sha256(LOCAL_COPY), _sha256(canonical) | |
| if local == remote: | |
| print(f"OK: sdi.py matches canonical scorer from {origin} ({local[:12]})") | |
| return 0 | |
| print(f"DRIFT: sdi.py ({local[:12]}) != canonical {origin} ({remote[:12]})") | |
| print("Sync with: cp <sdi-benchmark>/kinetk_sdi/sdi.py sdi.py (or vice versa)") | |
| return 1 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |