Download verify_export.py from zzhaobz/cembra: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/zzhaobz/cembra/resolve/main/verify_export.py
- Command line
-
hf download hf://zzhaobz/cembra/verify_export.py
-
curl -L -o verify_export.py https://huggingface.co/zzhaobz/cembra/resolve/main/verify_export.py
1.68 kB
| """Verify uploaded fold weights against one stored OOF prediction per fold.""" | |
| from __future__ import annotations | |
| import csv | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| from inference import PseudoSnpSVD64 | |
| ROOT = Path(__file__).resolve().parent | |
| OOF = ROOT / "results" / "pseudosnp" / "oof_predictions_pip_ge_0.30.tsv" | |
| def main() -> None: | |
| model = PseudoSnpSVD64(ROOT) | |
| examples: dict[int, dict[str, str]] = {} | |
| with OOF.open("r", encoding="utf-8", newline="") as handle: | |
| for row in csv.DictReader(handle, delimiter="\t"): | |
| fold = int(row["outer_fold"]) | |
| examples.setdefault(fold, row) | |
| if len(examples) == 5: | |
| break | |
| if set(examples) != set(range(5)): | |
| raise RuntimeError("stored OOF evidence does not cover all five folds") | |
| checks = [] | |
| for fold in range(5): | |
| row = examples[fold] | |
| observed = float( | |
| model.score_pair_by_fold(row["sequence_ref"], row["sequence_alt"])[fold] | |
| ) | |
| expected = float(row["transfer_fixed_raw_score"]) | |
| close = bool(np.isclose(observed, expected, rtol=0.0, atol=5e-6)) | |
| checks.append( | |
| { | |
| "fold": fold, | |
| "example_id": row["example_id"], | |
| "expected": expected, | |
| "observed": observed, | |
| "absolute_error": abs(observed - expected), | |
| "passed": close, | |
| } | |
| ) | |
| if not all(item["passed"] for item in checks): | |
| raise AssertionError(json.dumps(checks, indent=2)) | |
| print(json.dumps({"status": "PASS", "checks": checks}, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |