Download scripts/run_checks.py from EngineeringWithJay/pi-office-math-bootstrap: direct link, hf CLI and curl.
- Browser
- Download file 5.03 kB
-
https://huggingface.co/EngineeringWithJay/pi-office-math-bootstrap/resolve/main/scripts/run_checks.py
- Command line
-
hf download hf://EngineeringWithJay/pi-office-math-bootstrap/scripts/run_checks.py
-
curl -L -o run_checks.py https://huggingface.co/EngineeringWithJay/pi-office-math-bootstrap/resolve/main/scripts/run_checks.py
5.03 kB
| """ | |
| run_checks.py — the integration test suite for the Pi Office Math bootstrap. | |
| Runs inside the Docker container (check or run image). Verifies every | |
| integration point between the sandbox, verifier, worker logic, and dataset | |
| utilities — everything EXCEPT vLLM generation itself (which requires a GPU). | |
| Exit 0 = all pass. Exit 1 = at least one failure. | |
| """ | |
| import json | |
| import sys | |
| import traceback | |
| import day1_bootstrap as d | |
| failures = [] | |
| total = 0 | |
| def check(label, condition, detail=""): | |
| global total | |
| total += 1 | |
| status = "PASS" if condition else "FAIL" | |
| print(f"{status} | {label}") | |
| if not condition: | |
| failures.append(f"{label}: {detail}") | |
| return condition | |
| # --- postprocess_code (5 checks) --- | |
| check("postprocess: fence strip", | |
| d.postprocess_code("```python\nresult = 5\n```") == "result = 5") | |
| check("postprocess: think tag strip", | |
| d.postprocess_code("<think>let me solve</think>\nresult = 5") == "result = 5") | |
| check("postprocess: intent-JSON degeneracy guard", | |
| d.postprocess_code('{"solver_id": "x"}') is None) | |
| check("postprocess: empty -> None", | |
| d.postprocess_code("") is None) | |
| check("postprocess: plain code passthrough", | |
| d.postprocess_code("result = 5") == "result = 5") | |
| check("postprocess: prose rejected (7B failure mode)", | |
| d.postprocess_code("To find the answer, we first compute x, then y.") is None) | |
| check("postprocess: indented code kept", | |
| d.postprocess_code("if x == 1:\n result = 2") == "if x == 1:\n result = 2") | |
| # --- extract_gsm8k_answer (2 checks) --- | |
| check("gsm8k: trailing number", | |
| d.extract_gsm8k_answer("Natalia sold 48/2 = <<48/2=24>> clips. She sold 72.") == "72") | |
| check("gsm8k: thousand comma stripped", | |
| d.extract_gsm8k_answer("answer: 1,250") == "1250") | |
| # --- verify_candidate (6 checks: real sandbox + strong_compare) --- | |
| # Load a known-verified pair from the MATH-500 bootstrap for the True case. | |
| # In the container we don't have results/ — craft synthetic cases instead. | |
| cases = [ | |
| ("verified (real compute)", | |
| {"code": "import sympy as sp\nx = sp.symbols('x')\nresult = sp.solve(x**2 - 5*x + 6, x)", "expected": "[2, 3]"}, | |
| True, "verified"), | |
| ("crash (division by zero)", | |
| {"code": "result = 1/0", "expected": "5"}, | |
| False, "crash"), | |
| ("gate refusal (__import__)", | |
| {"code": "result = __import__('os').system('ls')", "expected": "5"}, | |
| False, "gate"), | |
| ("no result (None class)", | |
| {"code": "x = 5", "expected": "5"}, | |
| None, "no_result"), | |
| ("wrong-caught (numeric mismatch)", | |
| {"code": "result = 30", "expected": "145"}, | |
| False, "wrong_caught"), | |
| ("word-vs-number mismatch", | |
| {"code": "result = 5", "expected": "\\text{Evelyn}"}, | |
| False, "wrong_caught"), | |
| ] | |
| for label, task, want_v, want_r in cases: | |
| try: | |
| got = d.verify_candidate(task) | |
| ok_v = got["verdict"] is want_v | |
| ok_r = got["reason"].startswith(want_r) | |
| check(f"verify_candidate: {label}", | |
| ok_v and ok_r, | |
| f"want verdict={want_v} reason={want_r}, got verdict={got['verdict']} reason={got['reason']}") | |
| except Exception as exc: | |
| check(f"verify_candidate: {label}", False, | |
| f"EXCEPTION {type(exc).__name__}: {exc}") | |
| # --- CODEGEN_SYSTEM is the proven prompt (byte-identical) --- | |
| try: | |
| import benchmark_mode3_lean as b | |
| check("CODEGEN_SYSTEM byte-identical to proven prompt", | |
| d.CODEGEN_SYSTEM == b.CODEGEN_SYSTEM, | |
| "prompt text drifted from benchmark_mode3_lean") | |
| except Exception as exc: | |
| check("CODEGEN_SYSTEM import", False, str(exc)) | |
| # --- strong_compare direct spot-checks (the authority) --- | |
| from mode3_verify import strong_compare | |
| check("strong_compare: degree normalization", | |
| strong_compare("145^\\circ", "145") is True) | |
| check("strong_compare: mixed number", | |
| strong_compare("3\\frac{1}{2}", "7/2") is True) | |
| check("strong_compare: imaginary unit", | |
| strong_compare("6 - 5i", "6 - 5*I") is True) | |
| check("strong_compare: leading zeros (AIME)", | |
| strong_compare("025", "25") is True) | |
| # --- dataset loading (regression: pod failure on 2026-08-04 -- hendrycks | |
| # needs trust_remote_code; lighteval/MATH is 401-gated) --- | |
| try: | |
| loaded = d.load_datasets() | |
| check("datasets: GSM8K + MATH train load", | |
| len(loaded) > 100 and | |
| all(p["id"] and p["problem"] and p["answer"] for p in loaded[:50]), | |
| f"got {len(loaded)} problems; sample answers: " | |
| f"{[p['answer'][:12] for p in loaded[:3]]}") | |
| except Exception as exc: | |
| check("datasets: GSM8K + MATH train load", False, | |
| f"EXCEPTION {type(exc).__name__}: {str(exc)[:200]}") | |
| # --- summary --- | |
| print(f"\n{'=' * 50}") | |
| if failures: | |
| print(f"RESULT: {len(failures)} FAILURES out of {total} checks") | |
| for f in failures: | |
| print(f" FAIL: {f}") | |
| sys.exit(1) | |
| else: | |
| print(f"RESULT: ALL {total} CHECKS PASS — integration verified") | |
| print("(vLLM generation itself requires a GPU and is tested via --dry-run 20)") | |
| sys.exit(0) | |