Download validate_eval.py from tts-sft/round4-sft-eval: direct link, hf CLI and curl.
- Browser
- Download file 4.61 kB
-
https://huggingface.co/datasets/tts-sft/round4-sft-eval/resolve/main/validate_eval.py
- Command line
-
hf download hf://datasets/tts-sft/round4-sft-eval/validate_eval.py
-
curl -L -o validate_eval.py https://huggingface.co/datasets/tts-sft/round4-sft-eval/resolve/main/validate_eval.py
4.61 kB
| #!/usr/bin/env python3 | |
| """CPU validation of the eval cut: testset integrity, checker-aware grading | |
| path (stdin + SPJ + function_call), pass@k math, resume logic. Exit 0 = pass.""" | |
| import json, math, os, subprocess, sys, tempfile | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| PASS = FAIL = 0 | |
| def check(name, ok, detail=""): | |
| global PASS, FAIL | |
| ok = bool(ok); PASS += ok; FAIL += (not ok) | |
| print(f"{'PASS' if ok else 'FAIL'} {name}" + (f" [{detail}]" if detail and not ok else "")) | |
| rows = [json.loads(l) for l in open(os.path.join(HERE, "testset.jsonl"))] | |
| meta = json.load(open(os.path.join(HERE, "testset_meta.json"))) | |
| check("T1 657 problems", len(rows) == 657) | |
| from collections import Counter | |
| sets_ = Counter(r["set"] for r in rows) | |
| check("T2 set sizes", sets_ == Counter({"h_unsolved": 337, "dev": 200, "h_frontier": 120}), str(sets_)) | |
| n_ck = sum(1 for r in rows if r["test_cases"].get("checker")) | |
| check("T3 22 SPJ checkers inline", n_ck == 22, n_ck) | |
| check("T4 every row has question+suite", | |
| all(r["question"] and r["test_cases"].get("inputs") for r in rows)) | |
| check("T5 time_limit=10 everywhere", all(r["test_cases"]["time_limit"] == 10.0 for r in rows)) | |
| import hashlib | |
| check("T6 sha matches meta", hashlib.sha256(open(os.path.join(HERE, "testset.jsonl"), "rb").read()).hexdigest() == meta["sha256"]) | |
| # grading path: synthetic mini-testset through eval_grade.py | |
| with tempfile.TemporaryDirectory(dir="/var/tmp") as td: | |
| ts = os.path.join(td, "ts.jsonl") | |
| with open(ts, "w") as f: | |
| f.write(json.dumps({"id": "t1", "set": "dev", "subset": "x", "format": "stdin_stdout", | |
| "question": "q", "starter_code": "", "fn_name": "", | |
| "test_cases": {"inputs": ["1 2\n"], "outputs": ["3\n"], | |
| "time_limit": 10.0}}) + "\n") | |
| f.write(json.dumps({"id": "t2", "set": "dev", "subset": "x", "format": "stdin_stdout", | |
| "question": "q", "starter_code": "", "fn_name": "", | |
| "test_cases": {"inputs": ["3\n"], "outputs": ["1 2\n"], "time_limit": 10.0, | |
| "checker": "import sys\ni=open(sys.argv[1]).read().split()\ns=open(sys.argv[3]).read().split()\nprint(1 if len(s)==2 and sum(map(int,s))==int(i[0]) else 0)"}}) + "\n") | |
| f.write(json.dumps({"id": "t3", "set": "dev", "subset": "x", "format": "function_call", | |
| "question": "q", "starter_code": "def add(n, m):\n ", | |
| "fn_name": "add", | |
| "test_cases": {"inputs": ["n = 1\nm = 2"], "outputs": ["3"], "time_limit": 10.0}}) + "\n") | |
| sm = os.path.join(td, "s.jsonl") | |
| with open(sm, "w") as f: | |
| f.write(json.dumps({"id": "t1", "k": 0, "text": "```python\na,b=map(int,input().split());print(a+b)\n```"}) + "\n") | |
| f.write(json.dumps({"id": "t1", "k": 1, "text": "```python\nprint(0)\n```"}) + "\n") | |
| f.write(json.dumps({"id": "t2", "k": 0, "text": "```python\nn=int(input());print(2, n-2)\n```"}) + "\n") | |
| f.write(json.dumps({"id": "t3", "k": 0, "text": "```python\ndef add(n,m):\n return n+m\n```"}) + "\n") | |
| gr = os.path.join(td, "g.jsonl") | |
| r = subprocess.run([sys.executable, os.path.join(HERE, "eval_grade.py"), | |
| "--testset", ts, "--samples", sm, "--out", gr, "--workers", "4"], | |
| capture_output=True, text=True, timeout=300) | |
| g = {(x["id"], x["k"]): x["passed"] for x in map(json.loads, open(gr))} if os.path.exists(gr) else {} | |
| check("T7 stdin exact pass", g.get(("t1", 0)) is True, r.stderr[-200:]) | |
| check("T8 stdin wrong fails", g.get(("t1", 1)) is False) | |
| check("T9 SPJ alt answer passes via checker", g.get(("t2", 0)) is True, str(g)) | |
| check("T10 function_call passes", g.get(("t3", 0)) is True, str(g)) | |
| n0 = sum(1 for _ in open(gr)) | |
| r2 = subprocess.run([sys.executable, os.path.join(HERE, "eval_grade.py"), | |
| "--testset", ts, "--samples", sm, "--out", gr, "--workers", "4"], | |
| capture_output=True, text=True, timeout=120) | |
| check("T11 resume: no regrade", sum(1 for _ in open(gr)) == n0 and "0 to grade" in r2.stdout, r2.stdout[:120]) | |
| # pass@k estimator | |
| sys.path.insert(0, HERE) | |
| from eval_report import pass_at_k | |
| check("T12 pass@k math", abs(pass_at_k(16, 1, 1) - 1/16) < 1e-9 | |
| and pass_at_k(16, 0, 16) == 0.0 and pass_at_k(16, 1, 16) == 1.0 | |
| and abs(pass_at_k(4, 2, 2) - (1 - math.comb(2,2)/math.comb(4,2))) < 1e-9) | |
| print(f"\n{PASS} passed, {FAIL} failed") | |
| sys.exit(1 if FAIL else 0) | |