Download code/v1/tdprm/queue/plan.py from JoshuaW1997/tdprm-results: direct link, hf CLI and curl.
- Browser
- Download file 7.41 kB
-
https://huggingface.co/datasets/JoshuaW1997/tdprm-results/resolve/main/code/v1/tdprm/queue/plan.py
- Command line
-
hf download hf://datasets/JoshuaW1997/tdprm-results/code/v1/tdprm/queue/plan.py
-
curl -L -o plan.py https://huggingface.co/datasets/JoshuaW1997/tdprm-results/resolve/main/code/v1/tdprm/queue/plan.py
7.41 kB
| """Generate the experiment plan (job scripts + plan.json) for the single 8xA100 node. | |
| python -m tdprm.queue.plan [--rounds 200] [--extra-seeds 0] [--llama-arms all] | |
| python -m tdprm.queue.gpuq simulate --plan $TDPRM_HOME/queue/plan.json | |
| nohup python -m tdprm.queue.gpuq run --plan $TDPRM_HOME/queue/plan.json > $TDPRM_HOME/queue/queue.log 2>&1 & | |
| Priority (lower first): data/sampling/state fitting -> OpenJev construction (critical path of the six | |
| 1.b arms) -> Qwen-math (first comparison) -> Qwen-HotpotQA -> Llama-math -> Llama-HotpotQA. Each training | |
| job also runs its in-loop evaluations and final test (tdprm.rl.train); only the base model is evaluated | |
| by a separate job. | |
| """ | |
| import argparse | |
| import json | |
| import stat | |
| from collections import defaultdict | |
| from .. import paths | |
| from ..rl.launch import ARMS, PREAMBLE, eval_script, experiment, gpus_for, local_model, train_script | |
| CELLS = [("qwen1.5b", "math"), ("qwen1.5b", "proverqa"), ("llama3b", "math"), ("llama3b", "proverqa")] | |
| ARM_ORDER = ["grpo", "s_hc", "s_gae", "s_gaed", "prm800k", "qwenprm", "versaprm", "j_hc", "j_gae", "j_gaed"] | |
| # Estimated wall-clock hours for 200 rounds (64 prompts x 8 rollouts) on one Qwen-1.5B GPU / two Llama-3B GPUs. | |
| BASE_HOURS = {("qwen1.5b", "math"): 6.0, ("qwen1.5b", "proverqa"): 6.0, | |
| ("llama3b", "math"): 7.8, ("llama3b", "proverqa"): 7.8} | |
| TEST_HOURS = {"qwen1.5b": 0.3, "llama3b": 0.4} # in-run final test on the colocated vLLM engine | |
| ARM_FACTOR = {"grpo": 1.0, "s_hc": 1.08, "s_gae": 1.08, "s_gaed": 1.08, "prm800k": 1.25, "qwenprm": 1.25, | |
| "versaprm": 1.3, "j_hc": 1.25, "j_gae": 1.25, "j_gaed": 1.25} | |
| def write_script(name, body): | |
| path = paths.QUEUE / "scripts" / f"{name}.sh" | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| tmp = path.with_suffix(".tmp") | |
| tmp.write_text(body) | |
| tmp.chmod(tmp.stat().st_mode | stat.S_IXUSR) | |
| tmp.replace(path) # a running job's bash keeps reading its old (unlinked) script | |
| return str(path) | |
| def py_job(module_args): | |
| return PREAMBLE.format(repo=paths.REPO, home=paths.HOME) + f"python -m {module_args}\n" | |
| SMOKE_ARMS = ["grpo", "s_gae", "j_gae", "prm800k", "versaprm"] | |
| def build(args): | |
| jobs = [] | |
| smoke = args.smoke | |
| cells = [("qwen1.5b", "math")] if smoke else CELLS | |
| backbones = sorted({b for b, _ in cells}, key=lambda b: ("qwen" not in b, b)) | |
| domains = [d for d in ("math", "proverqa") if any(c[1] == d for c in cells)] | |
| tiny = {"sample": " --max-prompts 256", "fit": " --max-rollouts 1000", | |
| "build": " --rounds 2 --proposals 1 --round-size 200 --per-backbone 300", | |
| "label": " --n-ref 40", "calib": " --n-ref 40 --n-warm 200"} if smoke else defaultdict(str) | |
| def add(jid, body, gpus, priority, deps=(), est=1.0, **extra): | |
| jobs.append({"id": jid, "script": write_script(jid, body), "gpus": gpus, "priority": priority, | |
| "deps": list(deps), "est_hours": round(est, 2), **extra}) | |
| add("prep_data", py_job("tdprm.data.prepare"), 0, 0, est=0.3) | |
| add("download_models", PREAMBLE.format(repo=paths.REPO, home=paths.HOME) + | |
| "bash $TDPRM_REPO/tdprm/scripts/download_models.sh\n", 0, 0, est=0.6) | |
| prep = ["prep_data", "download_models"] | |
| for ci, (b, d) in enumerate(cells): | |
| add(f"sample_{b}_{d}", py_job(f"tdprm.sampling.base_rollouts --backbone {b} --domain {d}" + tiny["sample"]), | |
| 1, 1 + ci * 0.1, prep, est={"qwen1.5b": 0.35, "llama3b": 0.6}[b]) | |
| add(f"fit_spectral_{b}_{d}", py_job(f"tdprm.states.fit spectral --backbone {b} --domain {d}" + tiny["fit"]), | |
| 1, 2 + ci * 0.1, [f"sample_{b}_{d}"], est={"qwen1.5b": 0.3, "llama3b": 0.45}[b]) | |
| for b in backbones: | |
| add(f"eval_base_{b}", eval_script(local_model(paths.BACKBONES[b]), f"{b}-base/step_0"), 1, 6, prep, | |
| est={"qwen1.5b": 0.25, "llama3b": 0.4}[b]) | |
| jev_group = [] | |
| for di, d in enumerate(domains): | |
| # OpenJev-27B (bf16 fits one A100-80GB): build + balance the domain's state set from both backbones' steps; | |
| # then label a few thousand steps per cell as the reference for JevK5 (online labeler) calibration, | |
| # after which JevK5 labels the warm-start rollouts. | |
| jid = f"openjev_states_{d}" | |
| add(jid, py_job(f"tdprm.states.openjev build --domain {d}" + tiny["build"]), 1, 3 + di, | |
| [f"sample_{b}_{d}" for b in backbones], est=1.5) | |
| jev_group.append(jid) | |
| for b in backbones: | |
| lid, cid = f"openjev_label_{b}_{d}", f"jevk5_calib_{b}_{d}" | |
| add(lid, py_job(f"tdprm.states.openjev label --backbone {b} --domain {d}" + tiny["label"]), | |
| 1, 3.1 + di, [jid], est=0.4) | |
| add(cid, py_job(f"tdprm.states.openjev calibrate --backbone {b} --domain {d}" + tiny["calib"]), | |
| 1, 3.2 + di, [lid], est=0.35) | |
| jev_group += [lid, cid] | |
| llama_arms = ARM_ORDER if args.llama_arms == "all" else args.llama_arms.split(",") | |
| seeds = [0] if smoke else [1] + list(range(2, 2 + args.extra_seeds)) # smoke runs never collide with real ones | |
| for ci, (b, d) in enumerate(cells): | |
| arms = SMOKE_ARMS if smoke else (ARM_ORDER if b == "qwen1.5b" else llama_arms) | |
| for seed in seeds: | |
| if seed > 1 and (b, d) != ("qwen1.5b", "math"): | |
| continue | |
| for ai, arm in enumerate(arms): | |
| exp = experiment(b, d, arm, seed) | |
| deps = [f"sample_{b}_{d}"] | |
| if ARMS[arm].get("extractor") == "spectral": | |
| deps.append(f"fit_spectral_{b}_{d}") | |
| if ARMS[arm].get("extractor") == "jev": | |
| deps.append(f"jevk5_calib_{b}_{d}") | |
| est = BASE_HOURS[(b, d)] * ARM_FACTOR[arm] * args.rounds / 200 + TEST_HOURS[b] | |
| prio = 10 + 10 * ci + ai * 0.1 + (50 if seed > 1 else 0) | |
| tid = f"train_{exp}" | |
| add(tid, train_script(b, d, arm, seed, args.rounds), gpus_for(b, arm), prio, deps, est, | |
| first_look_frac=(100 / args.rounds if ci == 0 and seed == 1 and not smoke else None)) | |
| out = paths.QUEUE / ("plan_smoke.json" if smoke else "plan.json") | |
| reservations = [{"gpus": args.jev_gpus, "jobs": jev_group}] if args.jev_gpus else [] | |
| out.write_text(json.dumps({"jobs": jobs, "reservations": reservations}, indent=1)) | |
| print(f"wrote {out}: {len(jobs)} jobs " | |
| f"({sum(j['id'].startswith('train_') for j in jobs)} training runs, " | |
| f"{sum(j['id'].startswith('eval_') for j in jobs)} evaluations)") | |
| return out | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--rounds", type=int, default=200, help="GRPO rounds (64 prompts x 8 rollouts each)") | |
| parser.add_argument("--extra-seeds", type=int, default=0, help="extra seeds for the Qwen-math cell") | |
| parser.add_argument("--llama-arms", default="all") | |
| parser.add_argument("--smoke", action="store_true", | |
| help="tiny end-to-end check (Qwen-math, 10 rounds, small samples); use a separate TDPRM_HOME") | |
| parser.add_argument("--jev-gpus", type=lambda s: [int(x) for x in s.split(",")] if s else [], default="7", | |
| help="GPUs held for the OpenJev/JevK5 state pipeline until it finishes") | |
| args = parser.parse_args() | |
| if args.smoke: | |
| args.rounds = min(args.rounds, 10) | |
| build(args) | |
| if __name__ == "__main__": | |
| main() | |