Download code/v3/tdprm/scripts/probe_countdown.py from JoshuaW1997/tdprm-results: direct link, hf CLI and curl.
- Browser
- Download file 2.77 kB
-
https://huggingface.co/datasets/JoshuaW1997/tdprm-results/resolve/main/code/v3/tdprm/scripts/probe_countdown.py
- Command line
-
hf download hf://datasets/JoshuaW1997/tdprm-results/code/v3/tdprm/scripts/probe_countdown.py
-
curl -L -o probe_countdown.py https://huggingface.co/datasets/JoshuaW1997/tdprm-results/resolve/main/code/v3/tdprm/scripts/probe_countdown.py
2.77 kB
| """Base pass rates of candidate Countdown difficulty settings (picks the generator settings of the puzzle pair). | |
| python -m tdprm.scripts.probe_countdown --backbone qwen1.5b [--per-config 160] [--n 8] | |
| Writes $TDPRM_HOME/report/probe_countdown_<backbone>.json: pass@1 and the share of prompts solved 1-7 of 8 times for | |
| every (numbers, max number, max target) setting. | |
| """ | |
| import argparse | |
| import json | |
| import random | |
| from .. import paths | |
| from ..data.puzzles import countdown_puzzle, countdown_question | |
| from ..data.verify import verify | |
| from ..rl.launch import DOMAINS | |
| from ..sampling.base_rollouts import model_path | |
| from ..sampling.generate import generate, load_llm, render_prompt_ids | |
| CONFIGS = [(3, 10, 100), (3, 15, 150), (3, 20, 200), (3, 30, 1000), (4, 10, 100), (4, 15, 200), (4, 25, 500), | |
| (4, 50, 1000), (5, 10, 150), (5, 20, 500)] | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--backbone", default="qwen1.5b") | |
| ap.add_argument("--per-config", type=int, default=160) | |
| ap.add_argument("--n", type=int, default=8) | |
| args = ap.parse_args() | |
| rng = random.Random(7) | |
| records = [] | |
| for n, hi, top in CONFIGS: | |
| k = 0 | |
| while k < args.per_config: | |
| got = countdown_puzzle(n, hi, rng, max_target=top, min_target=2) | |
| if got is None: | |
| continue | |
| nums, target, expr = got | |
| records.append({"domain": "countdown", "data_source": "countdown", "question": countdown_question(nums, target), | |
| "answer": json.dumps({"answer": expr, "numbers": nums, "target": target}), | |
| "config": f"{n}x{hi}<={top}"}) | |
| k += 1 | |
| from transformers import AutoTokenizer | |
| path = model_path(args.backbone) | |
| tok = AutoTokenizer.from_pretrained(path) | |
| llm = load_llm(path, 2048, gpu_memory_utilization=0.85) | |
| outs = generate(llm, [render_prompt_ids(tok, r) for r in records], args.n, 1.0, 1.0, | |
| DOMAINS["countdown"]["max_response"], 0) | |
| stats = {} | |
| for r, samples in zip(records, outs): | |
| c = sum(verify("countdown", text, r["answer"])["score"] for _, text, _ in samples) | |
| s = stats.setdefault(r["config"], {"prompts": 0, "correct": 0, "kept": 0}) | |
| s["prompts"] += 1 | |
| s["correct"] += c | |
| s["kept"] += 1 <= c <= args.n - 1 | |
| for cfg, s in stats.items(): | |
| s["pass@1"] = round(s.pop("correct") / (s["prompts"] * args.n), 3) | |
| s["kept_share"] = round(s.pop("kept") / s["prompts"], 3) | |
| out = paths.HOME / "report" / f"probe_countdown_{args.backbone}.json" | |
| out.parent.mkdir(parents=True, exist_ok=True) | |
| out.write_text(json.dumps(stats, indent=1)) | |
| print(json.dumps(stats, indent=1)) | |
| if __name__ == "__main__": | |
| main() | |