diff options
Diffstat (limited to 'ep_run/knockout_s3200.py')
| -rw-r--r-- | ep_run/knockout_s3200.py | 27 |
1 files changed, 27 insertions, 0 deletions
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 ===") |
