From b83947778e2c776f757a07d4719b7ce961d7ed55 Mon Sep 17 00:00:00 2001 From: Yuren Hao Date: Fri, 3 Jul 2026 05:56:50 -0500 Subject: =?UTF-8?q?Initial=20commit:=20ept=20=E2=80=94=20backprop-free=20e?= =?UTF-8?q?quilibrium=20transformer=20(EP)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Claude-Session: https://claude.ai/code/session_014FAPDWQ49M5Ye3NpTndTpn --- ep_run/knockout_s3200.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ep_run/knockout_s3200.py (limited to 'ep_run/knockout_s3200.py') diff --git a/ep_run/knockout_s3200.py b/ep_run/knockout_s3200.py new file mode 100644 index 0000000..1c05ca4 --- /dev/null +++ b/ep_run/knockout_s3200.py @@ -0,0 +1,27 @@ +import torch, pickle, math +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=3000 +torch.manual_seed(1234); idx,y=L.get_batch('val',B,T); idx=idx.to(dev) if hasattr(idx,'to') else idx +ck=torch.load('runs/redx_traj/s3200.pt',map_location=dev) +def relax_floor(alpha): + blk=EQBlock(512,16,256,256,s=1.0,c=1.0,attn_mode='thick'); blk.qknorm=True + with torch.no_grad(): + for p,w in zip(blk.allp,ck['allp']): p.copy_(w.to(dev)) + blk.WO.mul_(alpha) # scale attention OUTPUT contribution (alpha=0 -> no attention) + 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>1e3: return ('DIVERGED',t,r,0) + tail=ress[-800:] + return (ress[149] if len(ress)>149 else None, ress[-1], min(tail), max(tail)) +print("=== knockout: scale attention output (WO*alpha) on redx s3200, eval_relax 3000 steps ===") +print("alpha=1 is the cycling operator; if cycle dies (res->0, monotone) as alpha falls -> attention asymmetry drives it") +for a in [1.0, 0.7, 0.4, 0.2, 0.0]: + r150,rlast,tmin,tmax=relax_floor(a) + osc = (tmax-tmin) + print(f" alpha={a}: res(150)={r150:.3e} res(3000)={rlast:.3e} tail[min={tmin:.2e},max={tmax:.2e}] osc={osc:.2e} {'CYCLE' if osc>1e-3 and rlast>1e-3 else 'converged' if rlast<1e-3 else 'floored'}") +print("=== DONE ===") -- cgit v1.2.3