Spaces:
Running
Running
Download run_grid.py from UncleanCode/denseam-hp-transfer: direct link, hf CLI and curl.
- Browser
- Download file 2.68 kB
-
https://huggingface.co/spaces/UncleanCode/denseam-hp-transfer/resolve/main/run_grid.py
- Command line
-
hf download hf://spaces/UncleanCode/denseam-hp-transfer/run_grid.py
-
curl -L -o run_grid.py https://huggingface.co/spaces/UncleanCode/denseam-hp-transfer/resolve/main/run_grid.py
2.68 kB
| """Run the Figure 4 grid on Modal, collect results, and write a JSONL log.""" | |
| import argparse | |
| import json | |
| import os | |
| import time | |
| import denseam_repro as d | |
| app = d.app | |
| LR_SGD = [1e-4, 1e-3, 3e-3, 1e-2, 3e-2, 1e-1, 3e-1, 1.0, 3.0, 10.0, 30.0] | |
| LR_ADAM = [1e-4, 3e-4, 1e-3, 3e-3, 1e-2, 3e-2, 1e-1, 3e-1, 1.0, 3.0, 10.0] | |
| def build_configs(scales, acts, opt_seeds, seeds): | |
| cfgs = [] | |
| for j in scales: | |
| for act in acts: | |
| for opt in opt_seeds: | |
| for seed in seeds: | |
| for lr in (LR_SGD if opt == "sgd" else LR_ADAM): | |
| cfgs.append(dict(j=j, act=act, opt=opt, eta0=lr, seed=seed, noise=0.1)) | |
| return cfgs | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--scales", default=os.environ.get("GRID_SCALES", "1,2,3,4,5,6")) | |
| ap.add_argument("--acts", default=os.environ.get("GRID_ACTS", "relu")) | |
| ap.add_argument("--opts", default=os.environ.get("GRID_OPTS", "sgd,adam")) | |
| ap.add_argument("--seeds", default=os.environ.get("GRID_SEEDS", "0,1,2")) | |
| ap.add_argument("--softmax-seeds", default=os.environ.get("GRID_SOFTMAX_SEEDS", "0")) | |
| ap.add_argument("--out", default=os.environ.get("GRID_OUT", "results/grid.jsonl")) | |
| ap.add_argument("--limit", type=int, default=int(os.environ.get("GRID_LIMIT", "0"))) | |
| a, _unknown = ap.parse_known_args() | |
| scales = [int(v) for v in a.scales.split(",")] | |
| acts = a.acts.split(",") | |
| opts = a.opts.split(",") | |
| seeds = [int(v) for v in a.seeds.split(",")] | |
| cfgs = [] | |
| for act in acts: | |
| if act == "softmax": | |
| cfgs += build_configs(scales, [act], opts, [int(v) for v in a.softmax_seeds.split(",")]) | |
| else: | |
| cfgs += build_configs(scales, [act], opts, seeds) | |
| if a.limit: | |
| cfgs = cfgs[:a.limit] | |
| print(f"{len(cfgs)} runs", flush=True) | |
| os.makedirs(os.path.dirname(a.out), exist_ok=True) | |
| t0 = time.time() | |
| rows = [] | |
| for i, r in enumerate(d.remote_run.map(cfgs, order_outputs=True)): | |
| rows.append(r) | |
| print(f"[{i+1}/{len(cfgs)}] j={r['j']} {r['act']} {r['opt']} eta0={r['eta0']:<8g} " | |
| f"seed={r['seed']} train={r['final_train_mse']:.4g} " | |
| f"eval={r['final_eval_mse']:.4g} div={r['diverged']} {r['wall_s']}s", flush=True) | |
| if (i + 1) % 20 == 0: | |
| with open(a.out, "w") as fh: | |
| for row in rows: | |
| fh.write(json.dumps(row) + "\n") | |
| with open(a.out, "w") as fh: | |
| for row in rows: | |
| fh.write(json.dumps(row) + "\n") | |
| print(f"done {len(rows)} runs in {time.time()-t0:.0f}s -> {a.out}", flush=True) | |
| def cli(): | |
| main() | |