PerDepthAdapter (Bae-style per-iteration merges) + convergence-halting probe (free ACT); pre-registration item 13

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Nils
2026-07-15 01:07:01 +02:00
co-authored by Claude Fable 5
parent f254b20b62
commit d00f120f27
4 changed files with 88 additions and 13 deletions
+24 -4
View File
@@ -28,8 +28,9 @@ OUT = Path(os.environ.get("LOOP_OUT",
@torch.no_grad()
def pass1_at_k(looper, adapter, tok, items, k, batch=8, max_new=220,
feedforward=False, pause=0):
feedforward=False, pause=0, halt=False):
codes = []
k_convs = []
for i in range(0, len(items), batch):
torch.cuda.empty_cache()
chunk = items[i : i + batch]
@@ -42,10 +43,14 @@ def pass1_at_k(looper, adapter, tok, items, k, batch=8, max_new=220,
enc["input_ids"] = torch.cat([enc["input_ids"], pcol], 1)
enc["attention_mask"] = torch.cat(
[enc["attention_mask"], torch.ones_like(pcol)], 1)
cv = {} if halt else None
gen = looper.generate_frozen_prompt(adapter, tok, enc["input_ids"], k,
max_new_tokens=max_new,
attention_mask=enc["attention_mask"],
feedforward=feedforward)
feedforward=feedforward,
conv_out=cv)
if halt:
k_convs.extend(cv.get("k_conv", []))
for j in range(len(chunk)):
txt = tok.decode(gen[j, enc["input_ids"].shape[1]:],
skip_special_tokens=True)
@@ -61,6 +66,9 @@ def pass1_at_k(looper, adapter, tok, items, k, batch=8, max_new=220,
d[1] += 1
per_item = [{"task_id": it["task_id"], "ok": bool(ok)}
for it, ok in zip(items, oks)]
if halt and k_convs:
for r, kc in zip(per_item, k_convs):
r["k_conv"] = kc
return (hits / len(items),
{l: c / n for l, (c, n) in per_label.items()}, per_item)
@@ -81,13 +89,19 @@ def main():
help="RecurrentAdapter (noise h0, learned A/B)")
ap.add_argument("--parcae", action="store_true",
help="ParcaeAdapter (rho(A)<1 by construction)")
ap.add_argument("--perdepth", action="store_true",
help="PerDepthAdapter (Bae-style per-iteration merges)")
ap.add_argument("--halt", action="store_true",
help="record per-item convergence depth (free-ACT probe)")
args = ap.parse_args()
ks = [int(x) for x in args.ks.split(",")]
model, tok = load_model(dtype=torch.bfloat16)
tok.padding_side = "left"
looper = BandLooper(model)
cls = (ParcaeAdapter if args.parcae
from loop_common import PerDepthAdapter
cls = (PerDepthAdapter if args.perdepth
else ParcaeAdapter if args.parcae
else RecurrentAdapter if args.rec
else AdaptiveMergeAdapter if args.adaptive else MergeAdapter)
kw = ({"alpha0": args.alpha} if args.adaptive else {"alpha": args.alpha})
@@ -106,7 +120,13 @@ def main():
t0 = time.time()
acc, by_label, per_item = pass1_at_k(looper, adapter, tok, items, k,
feedforward=args.feedforward,
pause=args.pause)
pause=args.pause, halt=args.halt)
if args.halt:
by_lbl_k = {}
for it, r in zip(items, per_item):
by_lbl_k.setdefault(it["label"], []).append(r.get("k_conv", k))
print(" mean k_conv:", {l: round(sum(v)/len(v), 2)
for l, v in by_lbl_k.items()}, flush=True)
res["ks"][k] = {"acc": acc, "by_label": by_label,
"per_item": per_item}
print(f"k={k}: pass@1={acc:.3f} "