"""Launch the Challenge-5 architecture x seed training matrix as HF Jobs (uv, t4-small). Each job runs job_train.py: trains on the unified dataset windows_5s, sweeps the wake threshold on unified validation, exports static ONNX (threshold in metadata), measures ORT latency, writes challenge-format predictions, and publishes a gated model repo Tonic/challenge5-acoustic--s + appends to the Tonic/challenge5-acoustic-results leaderboard. Usage: .venv/Scripts/python.exe launch_matrix.py [--flavor t4-small] [--seeds 42,7] """ import argparse, json, os, sys, time from pathlib import Path from huggingface_hub import HfApi ROOT = Path(__file__).parent TOKEN = os.environ.get("HF_TOKEN") or Path.home().joinpath(".huggingface", "token").read_text().strip() ARCHES = ["mobilenet_v3_small", "shufflenet_v2_x0_5", "squeezenet1_1", "efficientnet_lite0", "ghostnet_050", "cnn6_custom"] def main(): ap = argparse.ArgumentParser() ap.add_argument("--flavor", default="t4-small") ap.add_argument("--seeds", default="42,7") ap.add_argument("--epochs", type=int, default=10) ap.add_argument("--batch", type=int, default=64) ap.add_argument("--arch", default=None, help="limit to one arch") ap.add_argument("--seed", type=int, default=None, help="limit to one seed") ap.add_argument("--timeout", type=int, default=6 * 3600) ap.add_argument("--dry", action="store_true") args = ap.parse_args() seeds = [int(s) for s in args.seeds.split(",")] archs = [args.arch] if args.arch else ARCHES if args.seed is not None: seeds = [args.seed] script = (ROOT / "job_train.py").read_text(encoding="utf-8") api = HfApi(token=TOKEN) jobs = [] for arch in archs: for seed in seeds: name = f"c5-{arch}-s{seed}" sargs = ["--arch", arch, "--seed", str(seed), "--epochs", str(args.epochs), "--batch", str(args.batch)] if args.dry: print("DRY:", name, sargs) continue info = api.run_uv_job( script=script, script_args=sargs, python="3.12", flavor=args.flavor, timeout=args.timeout, env={"HF_TOKEN": TOKEN}, name=name, labels={"project": "challenge5-acoustic", "arch": arch, "seed": str(seed)}, ) url = f"https://huggingface.co/jobs/{info.namespace}/{info.id}" print(f"launched {name}: id={info.id} {url}", flush=True) jobs.append({"name": name, "arch": arch, "seed": seed, "id": info.id, "namespace": info.namespace, "url": url}) time.sleep(2) out = ROOT / "build" / "matrix_jobs.json" out.parent.mkdir(parents=True, exist_ok=True) prev = json.loads(out.read_text()) if out.exists() else [] out.write_text(json.dumps(prev + jobs, indent=2)) print(f"\n{len(jobs)} jobs launched; manifest: {out}") if __name__ == "__main__": main()