okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-142b-serve into f-1426e1085c1d

main
4.2 KiB82 linesraw
1"""WSL-only evaluation using EvalPlus 0.3.1's official checking functions."""
2import argparse
3import hashlib
4import json
5from pathlib import Path
6import sys
7import time
8
9from evalplus.data import get_human_eval_plus, get_human_eval_plus_hash
10from evalplus.eval import PASS, untrusted_check
11from evalplus.evaluate import get_groundtruth
12
13
14def main():
15    ap = argparse.ArgumentParser()
16    ap.add_argument("--out", required=True, type=Path)
17    ap.add_argument("--sanity", action="store_true")
18    ap.add_argument("--limit-seconds", type=float, default=720)
19    a = ap.parse_args()
20    a.out.mkdir(parents=True, exist_ok=True)
21    all_problems = get_human_eval_plus()
22    ids = sorted(all_problems, key=lambda x: int(x.split("/")[-1]))[:40]
23    problems = {k: all_problems[k] for k in ids}
24    digest = get_human_eval_plus_hash()
25    if not a.sanity:
26        saved_dataset = json.loads((a.out / "humaneval-subset.json").read_text(encoding="utf-8"))
27        if saved_dataset["dataset_hash"] != digest or saved_dataset["ids"] != ids:
28            raise RuntimeError("Evaluation dataset differs from the saved generation dataset")
29    if a.sanity:
30        (a.out / "humaneval-subset.json").write_text(json.dumps({"dataset_hash": digest,
31            "ids": ids, "problems": problems}, ensure_ascii=False), encoding="utf-8")
32    oracle = get_groundtruth(problems, digest + "-numeric-first40-strata0141", [])
33    p = problems[ids[0]]
34    o = oracle[ids[0]]
35
36    def check(code, problem, ref, part):
37        status, details = untrusted_check("humaneval", code, problem[part + "_input"],
38            problem["entry_point"], ref[part], problem["atol"], ref[part + "_time"], fast_check=True)
39        return {"status": status, "tested_inputs": len(details), "passed_inputs": sum(map(bool, details))}
40
41    if a.sanity:
42        correct = check(p["prompt"] + p["canonical_solution"], p, o, "base")
43        wrong = check(p["prompt"] + f"\n    return None\n", p, o, "base")
44        ready = correct["status"] == PASS and wrong["status"] != PASS
45        (a.out / "eval-ready.json").write_text(json.dumps({"ready": ready, "version": "0.3.1",
46            "dataset_hash": digest, "canonical": correct, "intentional_wrong": wrong}), encoding="utf-8")
47        print(json.dumps({"evaluator_ready": ready, "subset": len(ids)}), flush=True)
48        return 0 if ready else 1
49    deadline = time.monotonic() + a.limit_seconds
50    def save_results(path, rows):
51        temporary = path.with_suffix(".json.tmp")
52        temporary.write_text(json.dumps(rows, indent=2), encoding="utf-8")
53        temporary.replace(path)
54
55    for file in sorted((a.out / "code").glob("*-samples.jsonl")):
56        samples = {s["task_id"]: s for s in (json.loads(line) for line in file.read_text(encoding="utf-8").splitlines() if line.strip())}
57        hashes = {tid: hashlib.sha256(s["solution"].encode("utf-8")).hexdigest() for tid, s in samples.items()}
58        result_path = a.out / "code" / (file.stem + "-eval.json")
59        old = json.loads(result_path.read_text(encoding="utf-8")) if result_path.exists() else []
60        checked = {r["task_id"]: r for r in old if r.get("solution_sha256") == hashes.get(r["task_id"])
61            and r.get("dataset_hash") == digest and r.get("evalplus_version") == "0.3.1"}
62        for tid, sample in samples.items():
63            if tid in checked:
64                continue
65            if time.monotonic() >= deadline:
66                break
67            base = check(sample["solution"], problems[tid], oracle[tid], "base")
68            plus = check(sample["solution"], problems[tid], oracle[tid], "plus")
69            checked[tid] = {"task_id": tid, "base": base, "plus": plus,
70                "solution_sha256": hashes[tid], "dataset_hash": digest, "evalplus_version": "0.3.1",
71                "base_and_plus_pass": base["status"] == plus["status"] == PASS}
72            save_results(result_path, list(checked.values()))
73        results = list(checked.values())
74        save_results(result_path, results)
75        print(json.dumps({"file": file.name, "evaluated": len(results),
76            "base_pass": sum(r["base"]["status"] == PASS for r in results),
77            "plus_pass": sum(r["base_and_plus_pass"] for r in results)}), flush=True)
78    return 0
79
80
81if __name__ == "__main__":
82    sys.exit(main())