Skip to content

Commit e5fcb2b

Browse files
committed
transformerless_lm: v78 self-reflection + revision (A + B)
v77 showed that measuring momentum alone (passive scaling) isn't enough -- cycle 3 collapsed despite tracking the drop. True self-reflection requires acting on the measurement. A. Three-mode behavior based on momentum sign: momentum > +0.5 -> exploit: probs ^ phi (sharpen) momentum in [-0.5, +0.5] -> standard momentum < -0.5 -> escape: probs ^ (1/phi) (flatten) B. Backtrack-on-collapse: Track momentum_history (last F(7)=13 values). If max-recent minus current > 0.3 AND current < -0.2: boost newline_mask by phi^2 = 2.618 -- force substrate reset (sentence-end, fresh state counters next cycle). A modulates per-token behavior. B handles cliff drops (like v77 cycle 3). Together: momentum acts, not just measures. Omniweight already self-reflects via internal disagreement cancellation; momentum + A + B add the action layer.
1 parent fb30ae0 commit e5fcb2b

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

experiments/transformerless_lm/train_self_recursive.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,7 @@ def autoregressive_generate(model, prompt: torch.Tensor, n_new: int,
14221422
recent_pairs = [] # (prev_tok, current_tok) bigram history
14231423
last_content_ends_s = False
14241424
creative_momentum = 0.0 # self-eval EMA register
1425+
momentum_history = [] # recent momentum values, F(7)=13 deep
14251426
if vocab is not None:
14261427
prompt_list = seq[0].tolist()
14271428
for idx_pl, tid in enumerate(prompt_list):
@@ -1545,6 +1546,30 @@ def autoregressive_generate(model, prompt: torch.Tensor, n_new: int,
15451546
probs = _omniweight_apply_split(
15461547
base, math_delta, lang_delta,
15471548
momentum=creative_momentum).unsqueeze(0)
1549+
# A. Three-mode behavior based on momentum sign.
1550+
if creative_momentum > 0.5:
1551+
# Exploit: sharpen distribution.
1552+
p = probs[0] ** _PHI_FOR_SAMPLING
1553+
probs[0] = p / (p.sum() + 1e-8)
1554+
elif creative_momentum < -0.5:
1555+
# Escape: flatten distribution.
1556+
p = probs[0] ** (1.0 / _PHI_FOR_SAMPLING)
1557+
probs[0] = p / (p.sum() + 1e-8)
1558+
# B. Backtrack-on-collapse: if recent momentum dropped
1559+
# >F(3)=2 mass over last F(5)=5 steps AND current is
1560+
# negative, force newline boost (substrate reset).
1561+
collapsed = False
1562+
if (len(momentum_history) >= _FIB_NUMS_FOR_BIGRAM[5]
1563+
and newline_mask is not None):
1564+
recent_window = momentum_history[-_FIB_NUMS_FOR_BIGRAM[5]:]
1565+
drop = max(recent_window) - creative_momentum
1566+
if drop > 0.3 and creative_momentum < -0.2:
1567+
collapsed = True
1568+
if collapsed and newline_mask is not None:
1569+
nm = newline_mask.to(probs[0].device).to(probs[0].dtype)
1570+
phi2 = _PHI_FOR_SAMPLING ** 2
1571+
probs[0] = probs[0] * (1.0 + nm * (phi2 - 1.0))
1572+
probs[0] = probs[0] / (probs[0].sum() + 1e-8)
15481573
# Vocab curriculum (HARD mask, post-omniweight).
15491574
if active_vocab_size is not None:
15501575
probs[0] = substrate_vocab_curriculum(
@@ -1593,6 +1618,10 @@ def autoregressive_generate(model, prompt: torch.Tensor, n_new: int,
15931618
inv_phi = 1.0 / _PHI_FOR_SAMPLING
15941619
creative_momentum = (inv_phi * creative_momentum
15951620
+ (1.0 - inv_phi) * insight)
1621+
# Track momentum history for backtrack detection.
1622+
momentum_history.append(creative_momentum)
1623+
if len(momentum_history) > 13:
1624+
momentum_history = momentum_history[-13:]
15961625
model.train()
15971626
return seq
15981627

0 commit comments

Comments
 (0)