File size: 3,091 Bytes
765160f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
"""Command line interface for one-model Helixbench runs."""
from __future__ import annotations

import argparse
import json
from pathlib import Path

from . import __version__
from .inputs import COHORT_SHA256, frozen_rows, prepare, sha256, validate_prepared
from .pipeline import METRICS, run
from .report import aggregate, calculate


def parser() -> argparse.ArgumentParser:
    command = argparse.ArgumentParser(prog="helixbench", description="Six fixed Helixbench metrics")
    command.add_argument("--version", action="version", version=__version__)
    sub = command.add_subparsers(dest="command", required=True)
    p = sub.add_parser("prepare", help="Validate the 1015 generated/GT media and freeze manifests")
    p.add_argument("--generated", type=Path, required=True)
    p.add_argument("--gt", type=Path, help="Optional if using packaged GT features")
    p.add_argument("--model-id", required=True)
    p.add_argument("--run-dir", type=Path, required=True)
    p = sub.add_parser("run", help="Run one or all six metric stages")
    p.add_argument("--run-dir", type=Path, required=True)
    p.add_argument("--metric", choices=("all", *METRICS), default="all")
    p.add_argument("--deps-root", type=Path, required=True)
    p.add_argument("--weights-root", type=Path, required=True)
    p.add_argument("--torch-home", type=Path, required=True)
    p.add_argument("--frame-workers", type=int, default=8)
    p = sub.add_parser("aggregate", help="Check coverage and emit exactly six scores")
    p.add_argument("--run-dir", type=Path, required=True)
    p = sub.add_parser("verify", help="Recalculate an existing six-score report")
    p.add_argument("--run-dir", type=Path, required=True)
    sub.add_parser("verify-package", help="Verify the frozen cohort and packaged engine hashes")
    return command


def main() -> None:
    args = parser().parse_args()
    if args.command == "prepare":
        print(json.dumps(prepare(args.generated, args.gt, args.run_dir, args.model_id), ensure_ascii=False))
    elif args.command == "run":
        run(args.run_dir, args.metric, args.deps_root, args.weights_root, args.torch_home, args.frame_workers)
    elif args.command == "aggregate":
        report = aggregate(args.run_dir)
        print(json.dumps({key: value["value"] for key, value in report["metrics"].items()}, ensure_ascii=False))
    elif args.command == "verify":
        expected = json.loads((args.run_dir / "REPORT.json").read_text())
        actual = calculate(args.run_dir)
        if expected != actual:
            raise ValueError("Stored report differs from recalculated six-metric result")
        complete = json.loads((args.run_dir / "COMPLETE.json").read_text())
        if complete["report_sha256"] != sha256(args.run_dir / "REPORT.json"):
            raise ValueError("REPORT.json SHA256 differs from COMPLETE.json")
        print("Helixbench report verified")
    elif args.command == "verify-package":
        from .provenance import verify_package
        print(json.dumps(verify_package(), ensure_ascii=False))


if __name__ == "__main__":
    main()