summaryrefslogtreecommitdiff
path: root/ep_run/casc_eq_train.py
diff options
context:
space:
mode:
Diffstat (limited to 'ep_run/casc_eq_train.py')
-rw-r--r--ep_run/casc_eq_train.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/ep_run/casc_eq_train.py b/ep_run/casc_eq_train.py
index 6a6865d..e29048c 100644
--- a/ep_run/casc_eq_train.py
+++ b/ep_run/casc_eq_train.py
@@ -22,7 +22,7 @@ ap.add_argument('--wandb_run', default='')
ap.add_argument('--kmax', type=int, default=8) # adaptive fb rounds cap
ap.add_argument('--noguard', action='store_true') # diagnosis: skip only non-finite grads
ap.add_argument('--untie', action='store_true') # separate readout matrix (untied from tok)
-ap.add_argument('--opt', choices=['adamw', 'muon', 'sgdm', 'lion', 'olion', 'adafactor', 'signline', 'conslion', 'ditherlion'], default='adamw')
+ap.add_argument('--opt', choices=['adamw', 'muon', 'sgdm', 'lion', 'olion', 'adafactor', 'signline', 'conslion', 'ditherlion', 'cautlion'], default='adamw')
ap.add_argument('--muon_lr', type=float, default=0.02)
ap.add_argument('--tok_init', type=float, default=0.0) # >0: init tok/pos with this std (GPT-standard 0.02)
ap.add_argument('--compile', action='store_true') # torch.compile each block (free speed where supported)
@@ -61,6 +61,7 @@ ap.add_argument('--gen_new', type=int, default=120)
ap.add_argument('--probe_dgspec', type=int, default=0) # >0: M1 spectroscopy, value = n batches; exits before training
ap.add_argument('--probe_gains', default='1,2,4,8,16,32,64,128,256')
ap.add_argument('--probe_f64', action='store_true') # fp64 states+model in the probe: the fp-floor decisive arm # >1: per-STEP log-uniform dgain_top in
+ap.add_argument('--dump_grad', type=int, default=0) # >0: record per-step grad estimates + beta sign
ap.add_argument('--dump_mom', type=int, default=0) # >0: record 3 Muon momentum matrices every step
# for N steps -> runs/momdump_{tag}.pt, then exit
# (EqOLion tracking-falsification input)
@@ -344,7 +345,7 @@ if args.bf16:
if args.untie:
with torch.no_grad(): W_out.data = W_out.data.to(torch.bfloat16)
print('[bf16] model cast to bfloat16 (E-accum + sigma stay fp32)', flush=True)
-if args.opt in ('sgdm', 'lion', 'olion', 'adafactor', 'signline', 'conslion', 'ditherlion'):
+if args.opt in ('sgdm', 'lion', 'olion', 'adafactor', 'signline', 'conslion', 'ditherlion', 'cautlion'):
from muon import build_alt
opt, sched = build_alt(args.opt, blocks, all_params, args.lr, args.warmup,
total_steps=(args.steps if args.cosine else 0), lr_min_ratio=args.lr_min_ratio,
@@ -1050,6 +1051,20 @@ for step in range(start_step, args.steps + 1):
with torch.no_grad():
WSNAP['p'] = [p.detach().clone() for p in all_params]
WSNAP['o'] = _clone_state(opt.state_dict())
+ if args.dump_grad > 0 and args.opt == 'muon':
+ # per-step gradient ESTIMATES + the bsign coin, for the odd/even (curvature-channel)
+ # decomposition test: E[s*ghat] = beta*c. Captured BEFORE opt.step consumes grads.
+ om_ = opt.optimizers[0]
+ _m2 = om_.param_groups[0]['params']
+ _s2 = [_m2[1], _m2[len(_m2) // 2], _m2[-1]]
+ if 'GDUMP' not in globals():
+ GDUMP = {'shapes': [tuple(p.shape) for p in _s2], 'sign': [], 'traj': []}
+ GDUMP['sign'].append(1.0 if beta_t > 0 else -1.0)
+ GDUMP['traj'].append([p.grad.detach().float().cpu().clone() for p in _s2])
+ if step >= args.dump_grad:
+ torch.save(GDUMP, f'runs/graddump_{args.tag}.pt')
+ print(f'[graddump] DONE {len(GDUMP["traj"])} steps -> runs/graddump_{args.tag}.pt', flush=True)
+ import sys; sys.exit(0)
opt.step(); sched.step(); opt.zero_grad(set_to_none=True)
if args.dump_mom > 0 and args.opt == 'muon':
# per-step momentum trajectory for the EqOLion tracking falsification: three