Spaces:
Running
Running
File size: 2,677 Bytes
c846d02 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | """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)
@app.local_entrypoint()
def cli():
main()
|