"""Score sampled completions through the env, with the judge in stub or beam mode. python scripts/smoke_run.py --samples samples.jsonl --judge stub --out judge_log.jsonl HF_TOKEN=... python scripts/smoke_run.py --samples samples.jsonl --judge beam \ --out judge_log.jsonl --live `--judge beam` refuses to run without --live. """ from __future__ import annotations import argparse import json import sys from pathlib import Path from foresightbench_env import EnvConfig, ForesightEnv from foresightbench_env.judge import BudgetExhausted ROOT = Path(__file__).resolve().parents[1] def main() -> None: ap = argparse.ArgumentParser() ap.add_argument("--samples", type=Path, required=True) ap.add_argument("--judge", choices=["stub", "beam"], default="stub") ap.add_argument("--split", default="train") ap.add_argument("--out", type=Path, default=Path("judge_log.jsonl")) ap.add_argument("--cache-dir", type=Path, default=ROOT / ".cache") ap.add_argument("--budget-usd", type=float, default=20.0) ap.add_argument("--batch", type=int, default=16) ap.add_argument("--live", action="store_true") a = ap.parse_args() if a.judge == "beam" and not a.live: sys.exit("refusing: --judge beam spends Beam budget; pass --live to run it") samples = [json.loads(l) for l in a.samples.open(encoding="utf-8") if l.strip()] env = ForesightEnv(EnvConfig(split=a.split, judge_mode=a.judge, cache_dir=a.cache_dir, budget_usd=a.budget_usd, judge_log=a.out)) rewards = [] try: for i in range(0, len(samples), a.batch): chunk = samples[i:i + a.batch] rewards += env.score_batch([s["sample_id"] for s in chunk], [s["completion"] for s in chunk]) print(f"{min(i + a.batch, len(samples))}/{len(samples)} scored", file=sys.stderr) except BudgetExhausted as e: print(f"stopped: {e}", file=sys.stderr) n = len(rewards) print(json.dumps({"n_scored": n, "mean_reward": sum(rewards) / n if n else None, "judge_log": str(a.out)})) if __name__ == "__main__": main()