fidelity factorial arms (randk / noises0 / hidden-capacity) + pre-registration item 15

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Nils
2026-07-15 02:47:14 +02:00
co-authored by Claude Fable 5
parent d39e02f4b9
commit 0e6d6adcb9
4 changed files with 60 additions and 9 deletions
+20 -7
View File
@@ -21,8 +21,8 @@ import torch
import torch.nn.functional as F
from loop_common import (AdaptiveMergeAdapter, BandLooper, MergeAdapter,
ParcaeAdapter, PerDepthAdapter, RecurrentAdapter,
TiedAlphaAdapter)
NoisyMergeAdapter, ParcaeAdapter, PerDepthAdapter,
RecurrentAdapter, TiedAlphaAdapter)
from prep_mbpp import DIRECT_SUFFIX, mbpp_prompt
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
@@ -62,6 +62,13 @@ ap.add_argument("--recmax", type=int, default=16)
ap.add_argument("--parcae", action="store_true",
help="rec regime with rho(A)<1 by construction "
"(diag-negative-exp ZOH parameterization)")
ap.add_argument("--randk", action="store_true",
help="factorial cell: standard MergeAdapter but rec-style "
"log-uniform random depth (isolates the curriculum)")
ap.add_argument("--noises0", action="store_true",
help="factorial cell: standard merge + noise s0")
ap.add_argument("--hidden", type=int, default=512,
help="adapter MLP hidden width (capacity control)")
ap.add_argument("--tiedalpha", action="store_true",
help="merge with learned per-dim constant alpha, B tied "
"to (1-a); standard curriculum")
@@ -71,7 +78,7 @@ ap.add_argument("--perdepth", type=int, default=0,
ARGS, _ = ap.parse_known_args()
if ARGS.parcae:
ARGS.rec = True
if ARGS.rec and not ARGS.bptt:
if (ARGS.rec or ARGS.randk) and not ARGS.bptt:
ARGS.bptt = 4
SEED = ARGS.seed
LR = ARGS.lr
@@ -85,7 +92,10 @@ SUFFIX = ((f"_s{SEED}" if SEED else "")
+ (("_parcae" if ARGS.parcae else "_rec") + str(ARGS.recmax)
if ARGS.rec else "")
+ (f"_pd{ARGS.perdepth}" if ARGS.perdepth else "")
+ ("_ta" if ARGS.tiedalpha else ""))
+ ("_ta" if ARGS.tiedalpha else "")
+ (f"_rk{ARGS.recmax}" if ARGS.randk else "")
+ ("_ns" if ARGS.noises0 else "")
+ (f"_h{ARGS.hidden}" if ARGS.hidden != 512 else ""))
PAUSE_ID = 6 # <unused0>
@@ -144,8 +154,11 @@ def main():
p.requires_grad_(False)
looper = BandLooper(model)
d = model.config.get_text_config().hidden_size
H = ARGS.hidden
if ARGS.tiedalpha:
adapter = TiedAlphaAdapter(d=d, alpha=ARGS.alpha).cuda()
adapter = TiedAlphaAdapter(d=d, alpha=ARGS.alpha, hidden=H).cuda()
elif ARGS.noises0:
adapter = NoisyMergeAdapter(d=d, alpha=ARGS.alpha, hidden=H).cuda()
elif ARGS.perdepth:
adapter = PerDepthAdapter(d=d, alpha=ARGS.alpha,
n_depth=ARGS.perdepth).cuda()
@@ -156,7 +169,7 @@ def main():
elif ARGS.adaptive:
adapter = AdaptiveMergeAdapter(d=d, alpha0=ARGS.alpha).cuda()
else:
adapter = MergeAdapter(d=d, alpha=ARGS.alpha).cuda()
adapter = MergeAdapter(d=d, alpha=ARGS.alpha, hidden=H).cuda()
if ARGS.warm:
adapter.load_state_dict(torch.load(ARGS.warm, map_location="cuda"))
print("warm-started from", ARGS.warm, flush=True)
@@ -183,7 +196,7 @@ def main():
log = []
t0 = time.time()
for step in range(STEPS):
if ARGS.rec:
if ARGS.rec or ARGS.randk:
# randomized depth, log-uniform in [1, recmax], any difficulty
k = min(ARGS.recmax,
max(1, int(math.exp(rng.uniform(0, math.log(ARGS.recmax))))))