diff options
| author | Yuren Hao <yurenh2@illinois.edu> | 2026-07-03 05:56:50 -0500 |
|---|---|---|
| committer | Yuren Hao <yurenh2@illinois.edu> | 2026-07-03 05:56:50 -0500 |
| commit | b83947778e2c776f757a07d4719b7ce961d7ed55 (patch) | |
| tree | b9cc01d7adda691d9156d9d04f4fb2f644674e96 /ep_run/spec_bifurcation.py | |
Initial commit: ept — backprop-free equilibrium transformer (EP)
Code (ep_run/), organized docs (docs/{method,campaign,hardware,outreach,paper}),
analysis scripts (scripts/), ONBOARDING.md entry point. Large data/checkpoints
git-ignored (share separately).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014FAPDWQ49M5Ye3NpTndTpn
Diffstat (limited to 'ep_run/spec_bifurcation.py')
| -rw-r--r-- | ep_run/spec_bifurcation.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/ep_run/spec_bifurcation.py b/ep_run/spec_bifurcation.py new file mode 100644 index 0000000..aca7629 --- /dev/null +++ b/ep_run/spec_bifurcation.py @@ -0,0 +1,38 @@ +import torch, glob, re, math, pickle +from pathlib import Path +import lt_ep_train as L +from lt_ep_train import EQBlock +L.DD = Path('data/tinystories_bpe') +L.vocab = pickle.load(open(L.DD/'meta.pkl','rb'))['vocab_size'] +dev='cuda'; eps=0.1; B=8; T=256; N=800 +torch.manual_seed(1234) # FIXED batch across all ckpts +idx, y = L.get_batch('val', B, T) +idx = idx.to(dev) if hasattr(idx,'to') else idx +def measure(ckpt): + blk = EQBlock(512,16,256,256, s=1.0, c=1.0, attn_mode='thick'); blk.qknorm=True + ck = torch.load(ckpt, map_location=dev) + with torch.no_grad(): + for p,w in zip(blk.allp, ck['allp']): p.copy_(w.to(dev)) + xin = blk.embed(idx).detach(); z = xin.clone(); ress=[] + for t in range(N): + z2 = z + eps*blk.force(z, xin).detach() + r = (z2-z).norm().item()/(z.norm().item()+1e-9); ress.append(r); z=z2 + if (not math.isfinite(r)) or r>1e2: break + win=[ress[i] for i in range(len(ress)) if 1e-6<ress[i]<1e-1] or ress[-200:] + rats=[win[i+1]/win[i] for i in range(len(win)-1) if win[i]>0] + rho = math.exp(sum(math.log(x) for x in rats)/len(rats)) if rats else float('nan') + return rho, ress[-1], len(ress) +valmap={} +for l in open('runs/ep_redx.log'): + if l.startswith('step'): + m=re.search(r'step\s+(\d+)/.*val CE ([\d.]+)', l) + if m: valmap[int(m.group(1))]=m.group(2) +print("=== BIFURCATION PROBE — free-phase contraction ratio rho (fixed batch, 800 relax steps) ===") +print("rho<1 contractive | rho->1 marginal | rho>=1 divergent ; final_res = floor reached") +r,fr,n = measure('runs/bptt_final.pt'); print(f"REF BPTT(val~1.83): rho={r:.4f} final_res={fr:.2e} steps={n}") +print("redx approach to blowup:") +for ck in sorted(glob.glob('runs/redx_traj/s*.pt'), key=lambda p:int(re.search(r's(\d+)',p).group(1))): + step=int(re.search(r's(\d+)',ck).group(1)) + try: r,fr,n = measure(ck); print(f" step {step:5d} (val {valmap.get(step,'?')}): rho={r:.4f} final_res={fr:.2e} steps={n}") + except Exception as e: print(f" step {step:5d}: ERR {repr(e)[:80]}") +print("=== DONE ===") |
