E1c: k*=0 routing + pre-loop halt target (item 19 scored, E1c pre-registered)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Nils
2026-07-15 23:51:44 +02:00
co-authored by Claude Fable 5
parent f2a48ce338
commit 684e793eef
3 changed files with 30 additions and 7 deletions
+13 -4
View File
@@ -78,17 +78,26 @@ def halting_loop_logits(looper, adapter, input_ids, k_max, attention_mask,
@torch.no_grad()
def halted_k_per_item(looper, adapter, input_ids, k_max, attention_mask,
prompt_last_idx, thresh=0.5):
prompt_last_idx, thresh=0.5, allow_k0=True):
"""Deploy-time halting: smallest k where cumulative halt mass >= thresh
(k_max if never). Returns (B,) ints in 1..k_max."""
(k_max if never). With allow_k0, the head is also consulted on the
pre-loop state s_0 — items it flags there get k*=0 (no looping at
all; the E0 lesson: easy items are safest untouched).
Returns (B,) ints in 0..k_max."""
calls, _ = looper.capture(input_ids, attention_mask, logits_to_keep=1)
e = looper._hin[looper.l0].detach()
B = e.shape[0]
bidx = torch.arange(B, device=e.device)
s = looper.band(e, calls)
keep = torch.ones(B, device=e.device)
cum = torch.zeros(B, device=e.device)
kstar = torch.full((B,), k_max, dtype=torch.long, device=e.device)
cum = torch.zeros(B, device=e.device)
keep = torch.ones(B, device=e.device)
if allow_k0:
p0 = adapter.halt_prob(e[bidx, prompt_last_idx],
s[bidx, prompt_last_idx])
kstar[p0 >= thresh] = 0
cum = cum + p0
keep = keep * (1 - p0)
for i in range(k_max):
x = adapter(e, s)
s = looper.band(x, calls)