AbstractPhil commited on
Commit
d72be17
·
verified ·
1 Parent(s): 4477be2

anima_closeout v14: full resume rebuild — every arm now resolves LOCAL -> HUB -> train off one ARM_SHIP registry that drives shipping AND restoring, so a trained arm is never retrained and a fresh runtime costs a ~29MB download per arm. Restored arms carry their eval_curve.json (no tfevents exist), smokes skip when a full arm already proves the same thing, CELL 6 rebuilds the held-out cache itself (1-step cache_eval over the eval TOML) and resolves its own checkpoints, CELL 7 reads results from disk. exp017's surgical verdict gained an effect-size guard: the shipped mb3 gates sit at sigmoid(-3.6..-7.8), so a lesion ratio on a near-inert stack is reported VACUOUS, not PASS. Verified against the live hub: real restore of relay_s0/s1 + mb3, no training launched, newest_save refuses restored dirs, ship-skip stateless; builder now enforces cross-cell name resolution over 3 run orders.

Browse files
Files changed (1) hide show
  1. colab/anima_closeout.ipynb +329 -102
colab/anima_closeout.ipynb CHANGED
@@ -29,9 +29,27 @@
29
  "| **exp017** | multiband3 on the Anima DiT \u2014 first live run of the fork's mode | the band mechanism has never run on a DiT |\n",
30
  "| **the fix** | `bf16_master_weights = true` + declared `seed` | exp004's 28 gates were **quantization-frozen**: plain Adam stepped bf16 leaves directly; ~4.5e-4 updates vs 0.0078 half-ULP at \u22123.0 rounded to no-ops (proven from the salvaged Adam state) |\n",
31
  "\n",
32
- "Run cells top to bottom. Everything is idempotent: after a disconnect,\n",
33
- "re-run **CELL 0**, then re-run the interrupted run cell (checkpoints every\n",
34
- "30 min; pass `resume=True` to `run_arm`).\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  "\n",
36
  "**Needs:** Colab secret `HF_TOKEN` (notebook access ON) with write access\n",
37
  "to `AbstractPhil/geolip-aleph-diffusion`.\n",
@@ -410,11 +428,12 @@
410
  "# -- training TOMLs per arm -----------------------------------------------\n",
411
  "_AP = WORK / \"models\" / \"anima\" / \"split_files\"\n",
412
  "\n",
413
- "def _arm_toml(tag, seed, steps, mode=\"relay\", lora=False):\n",
 
414
  " out = RUNS / tag\n",
415
  " L = [f\"# {tag} \u2014 generated by anima_closeout.ipynb\",\n",
416
  " f\"output_dir = '{out}'\",\n",
417
- " f\"dataset = '{TOMLS}/dataset_train.toml'\",\n",
418
  " f\"seed = {seed}\",\n",
419
  " \"bf16_master_weights = true # the exp004 gate-freeze fix\",\n",
420
  " \"epochs = 1000\",\n",
@@ -427,12 +446,15 @@
427
  " \"checkpoint_every_n_minutes = 30\",\n",
428
  " \"activation_checkpointing = false # 96GB rider\",\n",
429
  " \"save_dtype = 'bfloat16'\",\n",
430
- " \"caching_batch_size = 8\",\n",
 
 
431
  " f\"eval_datasets = [{{name = 'heldout', config = '{TOMLS}/dataset_eval.toml'}}]\",\n",
432
  " \"eval_every_n_steps = 1000\",\n",
433
  " \"eval_before_first_step = true\",\n",
434
  " \"eval_micro_batch_size_per_gpu = 8\",\n",
435
- " \"eval_gradient_accumulation_steps = 1\",\n",
 
436
  " \"\", \"[model]\", \"type = 'anima'\",\n",
437
  " f\"transformer_path = '{_AP}/diffusion_models/anima-base-v1.0.safetensors'\",\n",
438
  " f\"llm_path = '{_AP}/text_encoders/qwen_3_06b_base.safetensors'\",\n",
@@ -472,6 +494,24 @@
472
  " \"e017_mb3_smoke\": _arm_toml(\"e017_mb3_smoke\", 0, 200, mode=\"multiband3\"),\n",
473
  " \"e017_mb3_s0\": _arm_toml(\"e017_mb3_s0\", 0, 10000, mode=\"multiband3\"),\n",
474
  " \"e017_mb3_s1\": _arm_toml(\"e017_mb3_s1\", 1, 10000, mode=\"multiband3\"),\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
  "}\n",
476
  "print(\"TOMLs written:\", \", \".join(ARMS))\n"
477
  ]
@@ -487,7 +527,7 @@
487
  "# flight (gates MUST move \u2014 the exact exp004 failure), prove eval wiring\n",
488
  "# (eval_before_first_step fires at step 0), build the latent cache\n",
489
  "# (~0.5h, reused by every later arm).\n",
490
- "import glob, io, json, os, subprocess, time\n",
491
  "from pathlib import Path\n",
492
  "import torch\n",
493
  "\n",
@@ -516,18 +556,89 @@
516
  " return proc.wait()\n",
517
  "\n",
518
  "def _arm_max_steps(tag):\n",
519
- " import tomllib\n",
 
 
 
520
  " return tomllib.loads(ARMS[tag].read_text())[\"max_steps\"]\n",
521
  "\n",
522
- "def run_arm(tag, resume=False):\n",
523
- " # IDEMPOTENT: an arm whose FINAL-step save already exists is never\n",
524
- " # retrained \u2014 after any crash the campaign resumes from local files,\n",
525
- " # skipping straight past every finished arm.\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
  " done = sorted(\n",
527
  " glob.glob(str(RUNS / tag / \"*\" / f\"step{_arm_max_steps(tag)}\")))\n",
528
- " if done:\n",
529
- " print(f\"[{tag}] already trained \u2014 reusing {done[-1]}\")\n",
530
- " return Path(done[-1])\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
531
  " log = RUNS / f\"{tag}.log\"\n",
532
  " flags = \" --resume_from_checkpoint\" if resume else \"\"\n",
533
  " t0 = time.time()\n",
@@ -537,18 +648,27 @@
537
  " print(f\"[{tag}] rc={rc} wall={(time.time() - t0) / 60:.1f} min\")\n",
538
  " if rc != 0:\n",
539
  " _die(tag, log, f\"train exited rc={rc}\")\n",
 
540
  " try:\n",
541
  " return newest_save(tag) # rc=0 but no run/save dir is ALSO death\n",
542
  " except AssertionError as e:\n",
543
  " _die(tag, log, str(e))\n",
544
  "\n",
545
- "def latest_run_dir(tag):\n",
546
- " run_dirs = sorted(glob.glob(str(RUNS / tag / \"*\")))\n",
547
- " assert run_dirs, f\"no run dir for {tag}\"\n",
548
- " return Path(run_dirs[-1])\n",
 
 
 
 
 
 
 
 
549
  "\n",
550
  "def newest_save(tag):\n",
551
- " rd = latest_run_dir(tag)\n",
552
  " saves = sorted(glob.glob(str(rd / \"epoch*\")) +\n",
553
  " glob.glob(str(rd / \"step*\")), key=os.path.getmtime)\n",
554
  " assert saves, f\"{tag}: run wrote no save dir\"\n",
@@ -566,12 +686,23 @@
566
  " out.extend(torch.as_tensor(g).float().flatten().tolist())\n",
567
  " return out\n",
568
  "\n",
569
- "def eval_curve(tag):\n",
570
- " \"\"\"The fork's deterministic eval scalars, parsed from tfevents.\"\"\"\n",
 
 
 
 
 
 
 
 
 
 
 
 
571
  " from tensorboard.backend.event_processing.event_accumulator import \\\n",
572
  " EventAccumulator\n",
573
- " acc = EventAccumulator(str(latest_run_dir(tag)),\n",
574
- " size_guidance={\"scalars\": 0})\n",
575
  " acc.Reload()\n",
576
  " out = {}\n",
577
  " for t in acc.Tags()[\"scalars\"]:\n",
@@ -579,8 +710,26 @@
579
  " out[t] = [(e.step, e.value) for e in acc.Scalars(t)]\n",
580
  " assert \"heldout/loss\" in out, \\\n",
581
  " f\"{tag}: no heldout/loss in tfevents ({acc.Tags()['scalars']})\"\n",
 
582
  " return out\n",
583
  "\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
584
  "def ship_arm(package, arm, save_dir, extra=None):\n",
585
  " \"\"\"Ship-on-completion: ckpt (+canonical safetensors) + TOML + log tail\n",
586
  " into the hub package immediately.\"\"\"\n",
@@ -617,30 +766,49 @@
617
  " operations=[CommitOperationAdd(path_in_repo=r, path_or_fileobj=s)\n",
618
  " for r, s in ops],\n",
619
  " commit_message=f\"{package}/{arm}: ship-on-completion from Colab\")\n",
 
620
  " print(f\"[ship] {package}/{arm}: {len(ops)} file(s) -> {HUB_REPO}\")\n",
621
  "\n",
622
- "# -- SMOKE ----------------------------------------------------------------\n",
623
  "# refuse to launch on stale dataset TOMLs from an earlier notebook version:\n",
624
  "# without distinct dp_cache paths, train+eval share one cache root and\n",
625
  "# corrupt each other (the ArrowIndexError crash / silent eval-swap hazard)\n",
626
  "for _dt in (\"dataset_train.toml\", \"dataset_eval.toml\"):\n",
627
  " assert \"dp_cache\" in (TOMLS / _dt).read_text(), (\n",
628
- " f\"{_dt} lacks the distinct cache path \u2014 RE-RUN CELL 1 (v8+) in \"\n",
629
- " \"THIS kernel before any arm; stale TOMLs corrupt the caches\")\n",
630
- "\n",
631
- "_save = run_arm(\"smoke\")\n",
632
- "_g = gate_values(_save)\n",
633
- "_moved = [x for x in _g if abs(x + 3.0) > 1e-3]\n",
634
- "print(f\"G-GATE: {len(_moved)}/{len(_g)} gates moved off -3.0 \"\n",
635
- " f\"(range {min(_g):+.4f} .. {max(_g):+.4f})\")\n",
636
- "assert _moved, (\n",
637
- " \"G-GATE FAILED: gates did not move \u2014 fp32 masters are not effective \"\n",
638
- " \"here. STOP. The designed fallback is the gate delta-reparam \"\n",
639
- " \"(gate = -3 + near-zero delta); do not burn full arms.\")\n",
640
- "_c = eval_curve(\"smoke\")\n",
641
- "print(f\"eval wiring OK: {len(_c)} heldout tags, \"\n",
642
- " f\"step-0 loss {_c['heldout/loss'][0][1]:.5f}\")\n",
643
- "print(\"SMOKE: ALL GREEN \u2014 masters proven, eval proven, cache built\")\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
644
  ]
645
  },
646
  {
@@ -667,44 +835,39 @@
667
  "outputs": [],
668
  "source": [
669
  "# \u2550\u2550\u2550 CELL 3 \u2014 exp004b: relay s0, relay s1, LoRA control \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n",
 
 
670
  "relay_saves = {}\n",
671
  "for _tag in (\"e004b_relay_s0\", \"e004b_relay_s1\"):\n",
672
- " _save = run_arm(_tag) # run_arm(_tag, resume=True) after\n",
673
- " _g = gate_values(_save) # a disconnect\n",
674
  " _mv = [x for x in _g if abs(x + 3.0) > 1e-3]\n",
675
  " print(f\"[{_tag}] P3 gates moved: {len(_mv)}/{len(_g)} \"\n",
676
- " f\"(range {min(_g):+.4f}..{max(_g):+.4f})\")\n",
677
  " assert _mv, f\"{_tag}: P3 FAILED \u2014 gates frozen at full scale\"\n",
678
- " _arm = _tag.replace(\"e004b_\", \"\")\n",
679
- " ship_arm(\"exp004b_anima_relay\", _arm, _save,\n",
680
- " extra={f\"exp004b_anima_relay/{_arm}/eval_curve.json\":\n",
681
- " eval_curve(_tag)})\n",
682
  " relay_saves[_tag] = str(_save)\n",
683
  "\n",
684
  "lora_saves = {\"e004b_lora_s0\": str(run_arm(\"e004b_lora_s0\"))}\n",
685
- "ship_arm(\"exp004b_anima_relay\", \"lora_s0\",\n",
686
- " Path(lora_saves[\"e004b_lora_s0\"]),\n",
687
- " extra={\"exp004b_anima_relay/lora_s0/eval_curve.json\":\n",
688
- " eval_curve(\"e004b_lora_s0\")})\n",
689
- "\n",
690
- "def _final(tag):\n",
691
- " return eval_curve(tag)[\"heldout/loss\"][-1][1]\n",
692
- "\n",
693
- "_r0, _r1 = _final(\"e004b_relay_s0\"), _final(\"e004b_relay_s1\")\n",
694
- "_l0 = _final(\"e004b_lora_s0\")\n",
695
- "_spread = abs(_r0 - _r1)\n",
696
- "_gap = abs(min(_r0, _r1) - _l0)\n",
697
- "print(f\"relay s0 {_r0:.5f} | s1 {_r1:.5f} (spread {_spread:.5f}) | \"\n",
698
- " f\"lora s0 {_l0:.5f} (gap {_gap:.5f})\")\n",
699
- "if _gap <= 2 * max(_spread, 1e-6):\n",
700
- " print(\"GATE: gap within 2x seed spread -> LoRA s1 REQUIRED\")\n",
701
- " lora_saves[\"e004b_lora_s1\"] = str(run_arm(\"e004b_lora_s1\"))\n",
702
- " ship_arm(\"exp004b_anima_relay\", \"lora_s1\",\n",
703
- " Path(lora_saves[\"e004b_lora_s1\"]),\n",
704
- " extra={\"exp004b_anima_relay/lora_s1/eval_curve.json\":\n",
705
- " eval_curve(\"e004b_lora_s1\")})\n",
706
  "else:\n",
707
- " print(\"GATE: ordering decisive at s0 -> LoRA s1 skipped (disclosed)\")\n"
 
 
 
 
 
 
 
 
 
708
  ]
709
  },
710
  {
@@ -731,24 +894,30 @@
731
  "# \u2550\u2550\u2550 CELL 4 \u2014 exp017: mb3 smoke, then both seeds \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n",
732
  "from amoe.io.checkpoint import load_diffusion_anchor\n",
733
  "\n",
734
- "_save = run_arm(\"e017_mb3_smoke\")\n",
735
- "_ck = load_diffusion_anchor(str(Path(_save) / \"aleph_relay.pt\"))\n",
736
- "assert _ck.kind == \"multiband3\", \\\n",
737
- " f\"mb3 smoke saved kind={_ck.kind} \u2014 the mode did not engage\"\n",
738
- "_g = gate_values(_save)\n",
739
- "_mv = [x for x in _g if abs(x + 3.0) > 1e-3]\n",
740
- "print(f\"mb3 smoke: kind OK, {_ck.n_sites} sites, gates moved \"\n",
741
- " f\"{len(_mv)}/{len(_g)}\")\n",
742
- "assert _mv, \"mb3 smoke: gates frozen \u2014 same STOP rule as the G-gate\"\n",
 
 
 
 
 
743
  "\n",
744
  "mb3_saves = {}\n",
745
  "for _tag in (\"e017_mb3_s0\", \"e017_mb3_s1\"):\n",
746
  " _save = run_arm(_tag)\n",
747
- " _arm = _tag.replace(\"e017_\", \"\")\n",
748
- " ship_arm(\"exp017_anima_multiband\", _arm, _save,\n",
749
- " extra={f\"exp017_anima_multiband/{_arm}/eval_curve.json\":\n",
750
- " eval_curve(_tag)})\n",
751
  " mb3_saves[_tag] = str(_save)\n",
 
752
  "print(\"exp017 arms complete:\", list(mb3_saves))\n"
753
  ]
754
  },
@@ -979,12 +1148,35 @@
979
  "# the fork caches under {path}/cache/{model_name} with model_name 'anima'\n",
980
  "# (cosmos_predict2.py:254 renames the pipeline when llm_path is a file)\n",
981
  "EVAL_CACHE = str(WORK / \"dp_cache\" / \"heldout\" / \"cache\" / \"anima\")\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
982
  "_buckets = sorted(glob.glob(str(Path(EVAL_CACHE) / \"cache_*\")))\n",
983
- "assert _buckets, (f\"no cache_* bucket dirs under {EVAL_CACHE} \u2014 the arms \"\n",
984
- " \"must have run (they build the eval cache) before the bed\")\n",
985
  "print(\"eval cache:\", EVAL_CACHE,\n",
986
  " \"| buckets:\", [Path(b).name for b in _buckets])\n",
987
  "\n",
 
 
 
 
 
 
 
 
 
988
  "_full = tomllib.loads(ARMS[\"e004b_relay_s0\"].read_text())\n",
989
  "_model = {k: v for k, v in _full[\"model\"].items()\n",
990
  " if not k.startswith(\"aleph_\") and not k.endswith(\"_lr\")}\n",
@@ -1024,30 +1216,36 @@
1024
  " \"mb3_s1\": {\"kind\": \"multiband3\", \"ckpt\": _pt(mb3_saves, \"e017_mb3_s1\")},\n",
1025
  "}}, \"results_exp017\")\n",
1026
  "\n",
1027
- "def _final(tag):\n",
1028
- " return eval_curve(tag)[\"heldout/loss\"][-1][1]\n",
1029
- "\n",
1030
  "RES4 = {\"bed\": r4,\n",
1031
- " \"fork_eval\": {t: eval_curve(t) for t in\n",
1032
- " (\"e004b_relay_s0\", \"e004b_relay_s1\", \"e004b_lora_s0\")},\n",
1033
  " \"split_manifest\": json.loads((DATA / \"split_manifest.json\")\n",
1034
  " .read_text())}\n",
1035
- "_rl = min(_final(\"e004b_relay_s0\"), _final(\"e004b_relay_s1\"))\n",
 
1036
  "_curve0 = RES4[\"fork_eval\"][\"e004b_relay_s0\"][\"heldout/loss\"]\n",
1037
  "_at3k = min(v for s, v in _curve0 if s <= 3000)\n",
1038
  "RES4[\"verdict\"] = {\n",
1039
- " \"P1_relay_vs_lora\": \"relay\" if _rl <= _final(\"e004b_lora_s0\") else \"lora\",\n",
 
 
 
1040
  " \"P2_toggle_bit_exact\": True, # the bed asserted, else it raised\n",
1041
  " \"P3_gates_moved\": True, # per-arm asserts in CELL 3\n",
1042
  " \"P4_3k_was_a_floor\": _curve0[-1][1] < _at3k,\n",
1043
  "}\n",
1044
  "(WORK / \"results_exp004b_full.json\").write_text(json.dumps(RES4, indent=1))\n",
1045
- "ship_arm(\"exp004b_anima_relay\", \"results\", newest_save(\"e004b_relay_s0\"),\n",
 
1046
  " extra={\"exp004b_anima_relay/results.json\": RES4})\n",
1047
  "print(\"exp004b verdict:\", RES4[\"verdict\"])\n",
1048
  "\n",
1049
  "_q = [str(x) for x in r17[\"quantiles\"]]\n",
1050
  "_allon = r17[\"arms\"][\"mb3_s0\"][\"loss_by_quantile\"]\n",
 
1051
  "_bandq = {0: [\"0.1\", \"0.3\"], 1: [\"0.5\", \"0.7\"], 2: [\"0.9\"]}\n",
1052
  "_surgical = {}\n",
1053
  "for _b, _own_q in _bandq.items():\n",
@@ -1057,16 +1255,34 @@
1057
  " _cross = sum(_les[x] - _allon[x] for x in _cq) / len(_cq)\n",
1058
  " _surgical[_b] = {\"own_damage\": _own, \"cross_damage\": _cross,\n",
1059
  " \"ratio\": (_own / _cross) if _cross > 0 else None}\n",
1060
- "RES17 = {\"bed\": r17, \"surgical\": _surgical,\n",
1061
- " \"P1_surgical_10x\": all(\n",
1062
- " (s[\"ratio\"] is None and s[\"own_damage\"] > 0) or\n",
 
 
 
 
 
 
 
1063
  " (s[\"ratio\"] is not None and s[\"ratio\"] >= 10)\n",
1064
- " for s in _surgical.values()),\n",
 
 
 
 
 
 
 
 
1065
  " \"P2_toggle_bit_exact\": True}\n",
1066
  "(WORK / \"results_exp017_full.json\").write_text(json.dumps(RES17, indent=1))\n",
1067
- "ship_arm(\"exp017_anima_multiband\", \"results\", newest_save(\"e017_mb3_s0\"),\n",
 
1068
  " extra={\"exp017_anima_multiband/results.json\": RES17})\n",
1069
- "print(\"exp017 surgical:\", json.dumps(_surgical, indent=1))\n"
 
 
1070
  ]
1071
  },
1072
  {
@@ -1102,6 +1318,15 @@
1102
  "\n",
1103
  "_BANDS = [\"fidelity/detail (LOW noise)\", \"continuity/semantics (MID)\",\n",
1104
  " \"diversity/structure (HIGH noise)\"]\n",
 
 
 
 
 
 
 
 
 
1105
  "_v = RES4[\"verdict\"]\n",
1106
  "_ops = []\n",
1107
  "for _seed, _tag in ((0, \"e004b_relay_s0\"), (1, \"e004b_relay_s1\")):\n",
@@ -1122,8 +1347,10 @@
1122
  " f\"Anima 2B DiT Multiband v1 (seed {_seed}) \u2014 NON-COMMERCIAL\",\n",
1123
  " \"Three sigma-band experts on the Anima DiT, step-gated \u2014 the \"\n",
1124
  " \"first multiband stack on a DiT-class trunk.\",\n",
1125
- " f\"exp017: P1 surgical(>=10x)={RES17['P1_surgical_10x']}; lesion \"\n",
1126
- " \"numbers in exp017_anima_multiband/results.json.\",\n",
 
 
1127
  " _seed,\n",
1128
  " [\"Non-commercial (derived from NC weights).\",\n",
1129
  " \"Needs an Anima checkpoint; band gating needs a step-gated \"\n",
 
29
  "| **exp017** | multiband3 on the Anima DiT \u2014 first live run of the fork's mode | the band mechanism has never run on a DiT |\n",
30
  "| **the fix** | `bf16_master_weights = true` + declared `seed` | exp004's 28 gates were **quantization-frozen**: plain Adam stepped bf16 leaves directly; ~4.5e-4 updates vs 0.0078 half-ULP at \u22123.0 rounded to no-ops (proven from the salvaged Adam state) |\n",
31
  "\n",
32
+ "## Nothing is ever trained twice\n",
33
+ "\n",
34
+ "Every arm resolves **LOCAL \u2192 HUB \u2192 train**:\n",
35
+ "\n",
36
+ "1. a final-step checkpoint on this disk is reused as-is;\n",
37
+ "2. else the arm is pulled back from its shipped hub package (a fresh\n",
38
+ " runtime after a pod cull costs a ~60 MB download per arm, not a\n",
39
+ " training run) \u2014 its eval curve rides along, since a restored arm has\n",
40
+ " no tfevents;\n",
41
+ "3. only a genuinely missing arm trains.\n",
42
+ "\n",
43
+ "CELL 2 prints the inventory (`local` / `hub` / `MISSING`) before anything\n",
44
+ "spends. The smokes are skipped when a full arm already proves the same\n",
45
+ "thing, CELL 6 rebuilds the held-out cache by itself if every arm was\n",
46
+ "restored, and CELLs 6\u20137 resolve their own checkpoints \u2014 so you can run\n",
47
+ "**0 \u2192 1 \u2192 2 \u2192 6 \u2192 7** in a brand-new runtime and get results without a\n",
48
+ "single training step.\n",
49
+ "\n",
50
+ "Run cells top to bottom. After a disconnect, re-run **CELL 0**, then the\n",
51
+ "interrupted cell (checkpoints land every 30 min; `run_arm(tag,\n",
52
+ "resume=True)` continues a half-finished run instead of restarting it).\n",
53
  "\n",
54
  "**Needs:** Colab secret `HF_TOKEN` (notebook access ON) with write access\n",
55
  "to `AbstractPhil/geolip-aleph-diffusion`.\n",
 
428
  "# -- training TOMLs per arm -----------------------------------------------\n",
429
  "_AP = WORK / \"models\" / \"anima\" / \"split_files\"\n",
430
  "\n",
431
+ "def _arm_toml(tag, seed, steps, mode=\"relay\", lora=False,\n",
432
+ " dataset=\"dataset_train.toml\", evals=True):\n",
433
  " out = RUNS / tag\n",
434
  " L = [f\"# {tag} \u2014 generated by anima_closeout.ipynb\",\n",
435
  " f\"output_dir = '{out}'\",\n",
436
+ " f\"dataset = '{TOMLS}/{dataset}'\",\n",
437
  " f\"seed = {seed}\",\n",
438
  " \"bf16_master_weights = true # the exp004 gate-freeze fix\",\n",
439
  " \"epochs = 1000\",\n",
 
446
  " \"checkpoint_every_n_minutes = 30\",\n",
447
  " \"activation_checkpointing = false # 96GB rider\",\n",
448
  " \"save_dtype = 'bfloat16'\",\n",
449
+ " \"caching_batch_size = 8\"]\n",
450
+ " if evals:\n",
451
+ " L += [\n",
452
  " f\"eval_datasets = [{{name = 'heldout', config = '{TOMLS}/dataset_eval.toml'}}]\",\n",
453
  " \"eval_every_n_steps = 1000\",\n",
454
  " \"eval_before_first_step = true\",\n",
455
  " \"eval_micro_batch_size_per_gpu = 8\",\n",
456
+ " \"eval_gradient_accumulation_steps = 1\"]\n",
457
+ " L += [\n",
458
  " \"\", \"[model]\", \"type = 'anima'\",\n",
459
  " f\"transformer_path = '{_AP}/diffusion_models/anima-base-v1.0.safetensors'\",\n",
460
  " f\"llm_path = '{_AP}/text_encoders/qwen_3_06b_base.safetensors'\",\n",
 
494
  " \"e017_mb3_smoke\": _arm_toml(\"e017_mb3_smoke\", 0, 200, mode=\"multiband3\"),\n",
495
  " \"e017_mb3_s0\": _arm_toml(\"e017_mb3_s0\", 0, 10000, mode=\"multiband3\"),\n",
496
  " \"e017_mb3_s1\": _arm_toml(\"e017_mb3_s1\", 1, 10000, mode=\"multiband3\"),\n",
497
+ " # cache-only: trains 1 throwaway step on the HELD-OUT set purely to\n",
498
+ " # materialize dp_cache/heldout (latents + text embeds) for the val bed\n",
499
+ " # on a runtime where every arm was restored and nothing else trains.\n",
500
+ " # Same dataset TOML -> same cache root/fingerprints as the real runs.\n",
501
+ " \"cache_eval\": _arm_toml(\"cache_eval\", 0, 1,\n",
502
+ " dataset=\"dataset_eval.toml\", evals=False),\n",
503
+ "}\n",
504
+ "\n",
505
+ "# THE registry: tag -> (hub package, arm folder). Drives BOTH shipping and\n",
506
+ "# restoring, so a trained arm and its hub copy can never disagree about\n",
507
+ "# where it lives. Arms absent here (the smokes) are local-only by design.\n",
508
+ "ARM_SHIP = {\n",
509
+ " \"e004b_relay_s0\": (\"exp004b_anima_relay\", \"relay_s0\"),\n",
510
+ " \"e004b_relay_s1\": (\"exp004b_anima_relay\", \"relay_s1\"),\n",
511
+ " \"e004b_lora_s0\": (\"exp004b_anima_relay\", \"lora_s0\"),\n",
512
+ " \"e004b_lora_s1\": (\"exp004b_anima_relay\", \"lora_s1\"),\n",
513
+ " \"e017_mb3_s0\": (\"exp017_anima_multiband\", \"mb3_s0\"),\n",
514
+ " \"e017_mb3_s1\": (\"exp017_anima_multiband\", \"mb3_s1\"),\n",
515
  "}\n",
516
  "print(\"TOMLs written:\", \", \".join(ARMS))\n"
517
  ]
 
527
  "# flight (gates MUST move \u2014 the exact exp004 failure), prove eval wiring\n",
528
  "# (eval_before_first_step fires at step 0), build the latent cache\n",
529
  "# (~0.5h, reused by every later arm).\n",
530
+ "import glob, io, json, os, shutil, subprocess, time\n",
531
  "from pathlib import Path\n",
532
  "import torch\n",
533
  "\n",
 
556
  " return proc.wait()\n",
557
  "\n",
558
  "def _arm_max_steps(tag):\n",
559
+ " try:\n",
560
+ " import tomllib\n",
561
+ " except ImportError:\n",
562
+ " import tomli as tomllib\n",
563
  " return tomllib.loads(ARMS[tag].read_text())[\"max_steps\"]\n",
564
  "\n",
565
+ "# \u2500\u2500 arm resolution: LOCAL -> HUB -> train \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n",
566
+ "# A trained arm is NEVER retrained. Local checkpoints win; otherwise a\n",
567
+ "# previously shipped arm is pulled back from the hub (so a fresh runtime\n",
568
+ "# after a pod cull costs a download, not a training run); only a genuinely\n",
569
+ "# missing arm trains. ARM_SOURCE records which path each arm took.\n",
570
+ "WEIGHT_FILES = (\"aleph_relay.pt\", \"adapter_model.safetensors\")\n",
571
+ "ARM_SOURCE = globals().get(\"ARM_SOURCE\", {})\n",
572
+ "\n",
573
+ "def _curve_cache(tag):\n",
574
+ " d = WORK / \"eval_curves\"\n",
575
+ " d.mkdir(exist_ok=True)\n",
576
+ " return d / f\"{tag}.json\"\n",
577
+ "\n",
578
+ "def _hub_files(refresh=False):\n",
579
+ " if refresh or \"HUB_FILES\" not in ANIMA:\n",
580
+ " from huggingface_hub import HfApi\n",
581
+ " ANIMA[\"HUB_FILES\"] = sorted(HfApi().list_repo_files(HUB_REPO))\n",
582
+ " return ANIMA[\"HUB_FILES\"]\n",
583
+ "\n",
584
+ "def local_save(tag):\n",
585
+ " \"\"\"The arm's FINAL-step save on this disk, or None.\"\"\"\n",
586
  " done = sorted(\n",
587
  " glob.glob(str(RUNS / tag / \"*\" / f\"step{_arm_max_steps(tag)}\")))\n",
588
+ " return Path(done[-1]) if done else None\n",
589
+ "\n",
590
+ "def restore_arm(tag):\n",
591
+ " \"\"\"Pull a shipped arm back from the hub into a local save dir, or None.\n",
592
+ " Also restores its eval curve, which no longer exists as tfevents.\"\"\"\n",
593
+ " if tag not in ARM_SHIP:\n",
594
+ " return None\n",
595
+ " from huggingface_hub import hf_hub_download\n",
596
+ " pkg, arm = ARM_SHIP[tag]\n",
597
+ " prefix = f\"{pkg}/{arm}/\"\n",
598
+ " files = [f for f in _hub_files() if f.startswith(prefix)]\n",
599
+ " if not any(f.rsplit(\"/\", 1)[-1] in WEIGHT_FILES for f in files):\n",
600
+ " return None\n",
601
+ " dest = RUNS / tag / \"from_hub\" / f\"step{_arm_max_steps(tag)}\"\n",
602
+ " dest.mkdir(parents=True, exist_ok=True)\n",
603
+ " for f in files:\n",
604
+ " name = f.rsplit(\"/\", 1)[-1]\n",
605
+ " # skip the log and the DERIVED duplicates of the .pt (canonical +\n",
606
+ " # fork-format safetensors): nothing downstream reads them, and they\n",
607
+ " # would triple the restore for every arm. They stay on the hub.\n",
608
+ " if name == \"log_tail.txt\" or name.endswith(\".canonical.safetensors\") \\\n",
609
+ " or name == \"aleph_relay.safetensors\":\n",
610
+ " continue\n",
611
+ " p = Path(hf_hub_download(HUB_REPO, f))\n",
612
+ " if name == \"eval_curve.json\":\n",
613
+ " _curve_cache(tag).write_text(p.read_text())\n",
614
+ " else:\n",
615
+ " shutil.copy(p, dest / name)\n",
616
+ " print(f\"[{tag}] restored from hub: {prefix} -> {dest}\")\n",
617
+ " return dest\n",
618
+ "\n",
619
+ "def arm_save(tag, allow_hub=True):\n",
620
+ " \"\"\"Resolve a finished arm WITHOUT ever training. None if unavailable.\"\"\"\n",
621
+ " p = local_save(tag)\n",
622
+ " if p is not None:\n",
623
+ " ARM_SOURCE.setdefault(tag, \"local\")\n",
624
+ " return p\n",
625
+ " if allow_hub:\n",
626
+ " p = restore_arm(tag)\n",
627
+ " if p is not None:\n",
628
+ " ARM_SOURCE[tag] = \"hub\"\n",
629
+ " return p\n",
630
+ " return None\n",
631
+ "\n",
632
+ "def arm_available(tag):\n",
633
+ " return arm_save(tag) is not None\n",
634
+ "\n",
635
+ "def run_arm(tag, resume=False, force=False):\n",
636
+ " if not force:\n",
637
+ " p = arm_save(tag)\n",
638
+ " if p is not None:\n",
639
+ " print(f\"[{tag}] NOT retraining \u2014 reusing \"\n",
640
+ " f\"{ARM_SOURCE[tag]} checkpoint {p}\")\n",
641
+ " return p\n",
642
  " log = RUNS / f\"{tag}.log\"\n",
643
  " flags = \" --resume_from_checkpoint\" if resume else \"\"\n",
644
  " t0 = time.time()\n",
 
648
  " print(f\"[{tag}] rc={rc} wall={(time.time() - t0) / 60:.1f} min\")\n",
649
  " if rc != 0:\n",
650
  " _die(tag, log, f\"train exited rc={rc}\")\n",
651
+ " ARM_SOURCE[tag] = \"trained\"\n",
652
  " try:\n",
653
  " return newest_save(tag) # rc=0 but no run/save dir is ALSO death\n",
654
  " except AssertionError as e:\n",
655
  " _die(tag, log, str(e))\n",
656
  "\n",
657
+ "def latest_run_dir(tag, with_events=False, trained_only=False):\n",
658
+ " dirs = sorted(glob.glob(str(RUNS / tag / \"*\")))\n",
659
+ " if with_events or trained_only:\n",
660
+ " # 'from_hub' is a restored checkpoint, not a run: no tfevents, and\n",
661
+ " # it must never be mistaken for what a training launch just wrote\n",
662
+ " dirs = [d for d in dirs if os.path.basename(d) != \"from_hub\"]\n",
663
+ " if with_events:\n",
664
+ " dirs = [d for d in dirs if glob.glob(\n",
665
+ " os.path.join(d, \"**\", \"events.out.tfevents*\"), recursive=True)]\n",
666
+ " assert dirs, (f\"no run dir for {tag}\"\n",
667
+ " + (\" containing tfevents\" if with_events else \"\"))\n",
668
+ " return Path(dirs[-1])\n",
669
  "\n",
670
  "def newest_save(tag):\n",
671
+ " rd = latest_run_dir(tag, trained_only=True)\n",
672
  " saves = sorted(glob.glob(str(rd / \"epoch*\")) +\n",
673
  " glob.glob(str(rd / \"step*\")), key=os.path.getmtime)\n",
674
  " assert saves, f\"{tag}: run wrote no save dir\"\n",
 
686
  " out.extend(torch.as_tensor(g).float().flatten().tolist())\n",
687
  " return out\n",
688
  "\n",
689
+ "def eval_curve(tag, required=True):\n",
690
+ " \"\"\"The fork's deterministic eval scalars. Prefers the cached/restored\n",
691
+ " JSON (a hub-restored arm has no tfevents at all), else parses this\n",
692
+ " runtime's tfevents and caches the result. None when unavailable and\n",
693
+ " not required.\"\"\"\n",
694
+ " cached = _curve_cache(tag)\n",
695
+ " if cached.exists():\n",
696
+ " return json.loads(cached.read_text())\n",
697
+ " try:\n",
698
+ " rd = latest_run_dir(tag, with_events=True)\n",
699
+ " except AssertionError:\n",
700
+ " if required:\n",
701
+ " raise\n",
702
+ " return None\n",
703
  " from tensorboard.backend.event_processing.event_accumulator import \\\n",
704
  " EventAccumulator\n",
705
+ " acc = EventAccumulator(str(rd), size_guidance={\"scalars\": 0})\n",
 
706
  " acc.Reload()\n",
707
  " out = {}\n",
708
  " for t in acc.Tags()[\"scalars\"]:\n",
 
710
  " out[t] = [(e.step, e.value) for e in acc.Scalars(t)]\n",
711
  " assert \"heldout/loss\" in out, \\\n",
712
  " f\"{tag}: no heldout/loss in tfevents ({acc.Tags()['scalars']})\"\n",
713
+ " cached.write_text(json.dumps(out))\n",
714
  " return out\n",
715
  "\n",
716
+ "def final_loss(tag):\n",
717
+ " \"\"\"Last held-out loss of an arm's fork eval curve, or None.\"\"\"\n",
718
+ " c = eval_curve(tag, required=False)\n",
719
+ " return c[\"heldout/loss\"][-1][1] if c else None\n",
720
+ "\n",
721
+ "def ship_tag(tag, save_dir):\n",
722
+ " \"\"\"Ship an arm under its registry identity \u2014 skipped when the arm CAME\n",
723
+ " from the hub (re-uploading a restored copy is pure waste). The dir name\n",
724
+ " is checked too, so the skip survives a kernel restart.\"\"\"\n",
725
+ " if ARM_SOURCE.get(tag) == \"hub\" or Path(save_dir).parent.name == \"from_hub\":\n",
726
+ " print(f\"[ship] {tag}: skipped (restored from hub, already there)\")\n",
727
+ " return\n",
728
+ " pkg, arm = ARM_SHIP[tag]\n",
729
+ " curve = eval_curve(tag, required=False)\n",
730
+ " ship_arm(pkg, arm, save_dir,\n",
731
+ " extra=({f\"{pkg}/{arm}/eval_curve.json\": curve} if curve else None))\n",
732
+ "\n",
733
  "def ship_arm(package, arm, save_dir, extra=None):\n",
734
  " \"\"\"Ship-on-completion: ckpt (+canonical safetensors) + TOML + log tail\n",
735
  " into the hub package immediately.\"\"\"\n",
 
766
  " operations=[CommitOperationAdd(path_in_repo=r, path_or_fileobj=s)\n",
767
  " for r, s in ops],\n",
768
  " commit_message=f\"{package}/{arm}: ship-on-completion from Colab\")\n",
769
+ " ANIMA.pop(\"HUB_FILES\", None) # listing is now stale\n",
770
  " print(f\"[ship] {package}/{arm}: {len(ops)} file(s) -> {HUB_REPO}\")\n",
771
  "\n",
772
+ "# -- campaign inventory ---------------------------------------------------\n",
773
  "# refuse to launch on stale dataset TOMLs from an earlier notebook version:\n",
774
  "# without distinct dp_cache paths, train+eval share one cache root and\n",
775
  "# corrupt each other (the ArrowIndexError crash / silent eval-swap hazard)\n",
776
  "for _dt in (\"dataset_train.toml\", \"dataset_eval.toml\"):\n",
777
  " assert \"dp_cache\" in (TOMLS / _dt).read_text(), (\n",
778
+ " f\"{_dt} lacks the distinct cache path \u2014 RE-RUN CELL 1 in THIS \"\n",
779
+ " \"kernel before any arm; stale TOMLs corrupt the caches\")\n",
780
+ "\n",
781
+ "INVENTORY = {}\n",
782
+ "for _t in ARM_SHIP: # resolves + materializes each arm\n",
783
+ " INVENTORY[_t] = ARM_SOURCE[_t] if arm_save(_t) else \"MISSING\"\n",
784
+ "print(\"campaign inventory:\")\n",
785
+ "for _t, _w in INVENTORY.items():\n",
786
+ " print(f\" {_t:<18} {_w}\")\n",
787
+ "_todo = [t for t, w in INVENTORY.items() if w == \"MISSING\"]\n",
788
+ "print(f\"arms needing training: {_todo or 'NONE \u2014 everything is available'}\")\n",
789
+ "\n",
790
+ "# -- SMOKE ----------------------------------------------------------------\n",
791
+ "# Its jobs: prove gates move under fp32 masters (exp004's exact failure),\n",
792
+ "# prove eval wiring, build the latent cache. All three are SUPERSEDED once\n",
793
+ "# a full aleph arm exists \u2014 so it only runs when one is actually needed.\n",
794
+ "_ALEPH = (\"e004b_relay_s0\", \"e004b_relay_s1\", \"e017_mb3_s0\", \"e017_mb3_s1\")\n",
795
+ "if any(INVENTORY[t] != \"MISSING\" for t in _ALEPH):\n",
796
+ " print(\"SMOKE SKIPPED \u2014 a full aleph arm is already available, which \"\n",
797
+ " \"proves the gate fix at 10k steps (a stronger result than 200).\")\n",
798
+ "else:\n",
799
+ " _save = run_arm(\"smoke\")\n",
800
+ " _g = gate_values(_save)\n",
801
+ " _moved = [x for x in _g if abs(x + 3.0) > 1e-3]\n",
802
+ " print(f\"G-GATE: {len(_moved)}/{len(_g)} gates moved off -3.0 \"\n",
803
+ " f\"(range {min(_g):+.4f} .. {max(_g):+.4f})\")\n",
804
+ " assert _moved, (\n",
805
+ " \"G-GATE FAILED: gates did not move \u2014 fp32 masters are not effective \"\n",
806
+ " \"here. STOP. The designed fallback is the gate delta-reparam \"\n",
807
+ " \"(gate = -3 + near-zero delta); do not burn full arms.\")\n",
808
+ " _c = eval_curve(\"smoke\")\n",
809
+ " print(f\"eval wiring OK: {len(_c)} heldout tags, \"\n",
810
+ " f\"step-0 loss {_c['heldout/loss'][0][1]:.5f}\")\n",
811
+ " print(\"SMOKE: ALL GREEN \u2014 masters proven, eval proven, cache built\")\n"
812
  ]
813
  },
814
  {
 
835
  "outputs": [],
836
  "source": [
837
  "# \u2550\u2550\u2550 CELL 3 \u2014 exp004b: relay s0, relay s1, LoRA control \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n",
838
+ "# Every arm resolves LOCAL -> HUB -> train, so re-running this cell after a\n",
839
+ "# crash (or on a fresh runtime) costs downloads, not GPU-hours.\n",
840
  "relay_saves = {}\n",
841
  "for _tag in (\"e004b_relay_s0\", \"e004b_relay_s1\"):\n",
842
+ " _save = run_arm(_tag) # run_arm(_tag, resume=True) to\n",
843
+ " _g = gate_values(_save) # continue a half-done run\n",
844
  " _mv = [x for x in _g if abs(x + 3.0) > 1e-3]\n",
845
  " print(f\"[{_tag}] P3 gates moved: {len(_mv)}/{len(_g)} \"\n",
846
+ " f\"(range {min(_g):+.4f}..{max(_g):+.4f}) [{ARM_SOURCE[_tag]}]\")\n",
847
  " assert _mv, f\"{_tag}: P3 FAILED \u2014 gates frozen at full scale\"\n",
848
+ " ship_tag(_tag, _save)\n",
 
 
 
849
  " relay_saves[_tag] = str(_save)\n",
850
  "\n",
851
  "lora_saves = {\"e004b_lora_s0\": str(run_arm(\"e004b_lora_s0\"))}\n",
852
+ "ship_tag(\"e004b_lora_s0\", Path(lora_saves[\"e004b_lora_s0\"]))\n",
853
+ "\n",
854
+ "_r0, _r1 = final_loss(\"e004b_relay_s0\"), final_loss(\"e004b_relay_s1\")\n",
855
+ "_l0 = final_loss(\"e004b_lora_s0\")\n",
856
+ "if None in (_r0, _r1, _l0):\n",
857
+ " print(\"results gate SKIPPED \u2014 missing eval curve(s) for \"\n",
858
+ " f\"{[t for t, v in zip(('relay_s0','relay_s1','lora_s0'), (_r0,_r1,_l0)) if v is None]}\"\n",
859
+ " \" (arms restored without one); LoRA s1 decision deferred to CELL 6\")\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
860
  "else:\n",
861
+ " _spread = abs(_r0 - _r1)\n",
862
+ " _gap = abs(min(_r0, _r1) - _l0)\n",
863
+ " print(f\"relay s0 {_r0:.5f} | s1 {_r1:.5f} (spread {_spread:.5f}) | \"\n",
864
+ " f\"lora s0 {_l0:.5f} (gap {_gap:.5f})\")\n",
865
+ " if _gap <= 2 * max(_spread, 1e-6):\n",
866
+ " print(\"GATE: gap within 2x seed spread -> LoRA s1 REQUIRED\")\n",
867
+ " lora_saves[\"e004b_lora_s1\"] = str(run_arm(\"e004b_lora_s1\"))\n",
868
+ " ship_tag(\"e004b_lora_s1\", Path(lora_saves[\"e004b_lora_s1\"]))\n",
869
+ " else:\n",
870
+ " print(\"GATE: ordering decisive at s0 -> LoRA s1 skipped (disclosed)\")\n"
871
  ]
872
  },
873
  {
 
894
  "# \u2550\u2550\u2550 CELL 4 \u2014 exp017: mb3 smoke, then both seeds \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n",
895
  "from amoe.io.checkpoint import load_diffusion_anchor\n",
896
  "\n",
897
+ "# the smoke exists to prove the mode ENGAGES before spending two seeds on\n",
898
+ "# it; a real mb3 arm already in hand proves the same thing more strongly\n",
899
+ "if all(arm_available(t) for t in (\"e017_mb3_s0\", \"e017_mb3_s1\")):\n",
900
+ " print(\"mb3 smoke SKIPPED \u2014 both mb3 seed arms are already available\")\n",
901
+ "else:\n",
902
+ " _save = run_arm(\"e017_mb3_smoke\")\n",
903
+ " _ck = load_diffusion_anchor(str(Path(_save) / \"aleph_relay.pt\"))\n",
904
+ " assert _ck.kind == \"multiband3\", \\\n",
905
+ " f\"mb3 smoke saved kind={_ck.kind} \u2014 the mode did not engage\"\n",
906
+ " _g = gate_values(_save)\n",
907
+ " _mv = [x for x in _g if abs(x + 3.0) > 1e-3]\n",
908
+ " print(f\"mb3 smoke: kind OK, {_ck.n_sites} sites, gates moved \"\n",
909
+ " f\"{len(_mv)}/{len(_g)}\")\n",
910
+ " assert _mv, \"mb3 smoke: gates frozen \u2014 same STOP rule as the G-gate\"\n",
911
  "\n",
912
  "mb3_saves = {}\n",
913
  "for _tag in (\"e017_mb3_s0\", \"e017_mb3_s1\"):\n",
914
  " _save = run_arm(_tag)\n",
915
+ " _ck = load_diffusion_anchor(str(Path(_save) / \"aleph_relay.pt\"))\n",
916
+ " assert _ck.kind == \"multiband3\", \\\n",
917
+ " f\"{_tag}: kind={_ck.kind} \u2014 not a multiband3 stack\"\n",
918
+ " ship_tag(_tag, _save)\n",
919
  " mb3_saves[_tag] = str(_save)\n",
920
+ " print(f\"[{_tag}] OK ({ARM_SOURCE[_tag]}), {_ck.n_sites} sites\")\n",
921
  "print(\"exp017 arms complete:\", list(mb3_saves))\n"
922
  ]
923
  },
 
1148
  "# the fork caches under {path}/cache/{model_name} with model_name 'anima'\n",
1149
  "# (cosmos_predict2.py:254 renames the pipeline when llm_path is a file)\n",
1150
  "EVAL_CACHE = str(WORK / \"dp_cache\" / \"heldout\" / \"cache\" / \"anima\")\n",
1151
+ "\n",
1152
+ "def ensure_eval_cache():\n",
1153
+ " \"\"\"The bed reads the fork's OWN eval cache. On a runtime where every\n",
1154
+ " arm was restored from the hub, nothing has trained, so that cache does\n",
1155
+ " not exist \u2014 rebuild it with a 1-step throwaway run over the held-out\n",
1156
+ " TOML (same TOML -> same root, same fingerprints; ~1 min, 512 rows).\n",
1157
+ " The throwaway checkpoint is never read by anything.\"\"\"\n",
1158
+ " if sorted(glob.glob(str(Path(EVAL_CACHE) / \"cache_*\"))):\n",
1159
+ " return\n",
1160
+ " print(\"eval cache absent (all arms restored) \u2014 building it now\")\n",
1161
+ " run_arm(\"cache_eval\", force=True)\n",
1162
+ " assert sorted(glob.glob(str(Path(EVAL_CACHE) / \"cache_*\"))), \\\n",
1163
+ " f\"cache_eval ran but produced nothing under {EVAL_CACHE}\"\n",
1164
+ "\n",
1165
+ "ensure_eval_cache()\n",
1166
  "_buckets = sorted(glob.glob(str(Path(EVAL_CACHE) / \"cache_*\")))\n",
1167
+ "assert _buckets, f\"no cache_* bucket dirs under {EVAL_CACHE}\"\n",
 
1168
  "print(\"eval cache:\", EVAL_CACHE,\n",
1169
  " \"| buckets:\", [Path(b).name for b in _buckets])\n",
1170
  "\n",
1171
+ "# resolve every arm independently of CELLs 3/4 having run in THIS kernel\n",
1172
+ "relay_saves = {t: str(arm_save(t)) for t in\n",
1173
+ " (\"e004b_relay_s0\", \"e004b_relay_s1\")}\n",
1174
+ "mb3_saves = {t: str(arm_save(t)) for t in (\"e017_mb3_s0\", \"e017_mb3_s1\")}\n",
1175
+ "assert all(relay_saves.values()) and all(mb3_saves.values()), \\\n",
1176
+ " \"run CELLs 3 and 4 first \u2014 some arms are neither local nor on the hub\"\n",
1177
+ "print(\"arms resolved:\", {t: ARM_SOURCE[t] for t in\n",
1178
+ " list(relay_saves) + list(mb3_saves)})\n",
1179
+ "\n",
1180
  "_full = tomllib.loads(ARMS[\"e004b_relay_s0\"].read_text())\n",
1181
  "_model = {k: v for k, v in _full[\"model\"].items()\n",
1182
  " if not k.startswith(\"aleph_\") and not k.endswith(\"_lr\")}\n",
 
1216
  " \"mb3_s1\": {\"kind\": \"multiband3\", \"ckpt\": _pt(mb3_saves, \"e017_mb3_s1\")},\n",
1217
  "}}, \"results_exp017\")\n",
1218
  "\n",
1219
+ "_curves = {t: eval_curve(t, required=False) for t in\n",
1220
+ " (\"e004b_relay_s0\", \"e004b_relay_s1\",\n",
1221
+ " \"e004b_lora_s0\", \"e004b_lora_s1\")}\n",
1222
  "RES4 = {\"bed\": r4,\n",
1223
+ " \"fork_eval\": {t: c for t, c in _curves.items() if c},\n",
1224
+ " \"arm_source\": {t: ARM_SOURCE.get(t) for t in ARM_SHIP},\n",
1225
  " \"split_manifest\": json.loads((DATA / \"split_manifest.json\")\n",
1226
  " .read_text())}\n",
1227
+ "_rl = min(final_loss(\"e004b_relay_s0\"), final_loss(\"e004b_relay_s1\"))\n",
1228
+ "_l0 = final_loss(\"e004b_lora_s0\")\n",
1229
  "_curve0 = RES4[\"fork_eval\"][\"e004b_relay_s0\"][\"heldout/loss\"]\n",
1230
  "_at3k = min(v for s, v in _curve0 if s <= 3000)\n",
1231
  "RES4[\"verdict\"] = {\n",
1232
+ " # bed loss is the paired instrument; the fork curve decides P1/P4\n",
1233
+ " \"P1_relay_vs_lora\": (\"relay\" if _rl <= _l0 else \"lora\")\n",
1234
+ " if _l0 is not None else \"UNDECIDED (no LoRA control)\",\n",
1235
+ " \"P1_numbers\": {\"relay_best\": _rl, \"lora_s0\": _l0},\n",
1236
  " \"P2_toggle_bit_exact\": True, # the bed asserted, else it raised\n",
1237
  " \"P3_gates_moved\": True, # per-arm asserts in CELL 3\n",
1238
  " \"P4_3k_was_a_floor\": _curve0[-1][1] < _at3k,\n",
1239
  "}\n",
1240
  "(WORK / \"results_exp004b_full.json\").write_text(json.dumps(RES4, indent=1))\n",
1241
+ "ship_arm(\"exp004b_anima_relay\", \"results\",\n",
1242
+ " Path(relay_saves[\"e004b_relay_s0\"]),\n",
1243
  " extra={\"exp004b_anima_relay/results.json\": RES4})\n",
1244
  "print(\"exp004b verdict:\", RES4[\"verdict\"])\n",
1245
  "\n",
1246
  "_q = [str(x) for x in r17[\"quantiles\"]]\n",
1247
  "_allon = r17[\"arms\"][\"mb3_s0\"][\"loss_by_quantile\"]\n",
1248
+ "_off = r17[\"arms\"][\"mb3_s0_toggled_off\"][\"loss_by_quantile\"]\n",
1249
  "_bandq = {0: [\"0.1\", \"0.3\"], 1: [\"0.5\", \"0.7\"], 2: [\"0.9\"]}\n",
1250
  "_surgical = {}\n",
1251
  "for _b, _own_q in _bandq.items():\n",
 
1255
  " _cross = sum(_les[x] - _allon[x] for x in _cq) / len(_cq)\n",
1256
  " _surgical[_b] = {\"own_damage\": _own, \"cross_damage\": _cross,\n",
1257
  " \"ratio\": (_own / _cross) if _cross > 0 else None}\n",
1258
+ "# EFFECT SIZE GUARD. The bed is bit-deterministic, so any lesion delta is\n",
1259
+ "# \"real\" \u2014 but a stack whose gates trained shut barely moves the loss at\n",
1260
+ "# all, and then a beautiful ratio is measuring nothing. The shipped mb3\n",
1261
+ "# gates sit at sigmoid(-3.6..-7.8) = 0.027..0.0004, so this is the live\n",
1262
+ "# risk, not a hypothetical: report the adapter's own effect and refuse to\n",
1263
+ "# call a lesion surgical when the stack it lesions is inert.\n",
1264
+ "_effect = sum(_off[x] - _allon[x] for x in _q) / len(_q)\n",
1265
+ "_own_mean = sum(s[\"own_damage\"] for s in _surgical.values()) / len(_surgical)\n",
1266
+ "_vacuous = abs(_effect) < 1e-6 or abs(_own_mean) < 0.01 * abs(_effect)\n",
1267
+ "_clean = all((s[\"ratio\"] is None and s[\"own_damage\"] > 0) or\n",
1268
  " (s[\"ratio\"] is not None and s[\"ratio\"] >= 10)\n",
1269
+ " for s in _surgical.values())\n",
1270
+ "RES17 = {\"bed\": r17, \"surgical\": _surgical,\n",
1271
+ " \"adapter_effect_mean\": _effect, # toggled_off - all_on\n",
1272
+ " \"own_damage_mean\": _own_mean,\n",
1273
+ " \"P1_surgical_10x\": bool(_clean and not _vacuous),\n",
1274
+ " \"P1_verdict\": (\"VACUOUS \u2014 the stack is near-inert (gates trained \"\n",
1275
+ " \"shut); lesion ratios measure nothing\"\n",
1276
+ " if _vacuous else\n",
1277
+ " (\"SURGICAL\" if _clean else \"NOT SURGICAL\")),\n",
1278
  " \"P2_toggle_bit_exact\": True}\n",
1279
  "(WORK / \"results_exp017_full.json\").write_text(json.dumps(RES17, indent=1))\n",
1280
+ "ship_arm(\"exp017_anima_multiband\", \"results\",\n",
1281
+ " Path(mb3_saves[\"e017_mb3_s0\"]),\n",
1282
  " extra={\"exp017_anima_multiband/results.json\": RES17})\n",
1283
+ "print(\"exp017 surgical:\", json.dumps(_surgical, indent=1))\n",
1284
+ "print(f\"exp017 P1: {RES17['P1_verdict']} | adapter effect \"\n",
1285
+ " f\"{_effect:+.3e} | mean own-band damage {_own_mean:+.3e}\")\n"
1286
  ]
1287
  },
1288
  {
 
1318
  "\n",
1319
  "_BANDS = [\"fidelity/detail (LOW noise)\", \"continuity/semantics (MID)\",\n",
1320
  " \"diversity/structure (HIGH noise)\"]\n",
1321
+ "# survive a kernel that ran CELL 6 in an earlier session\n",
1322
+ "RES4 = globals().get(\"RES4\") or json.loads(\n",
1323
+ " (WORK / \"results_exp004b_full.json\").read_text())\n",
1324
+ "RES17 = globals().get(\"RES17\") or json.loads(\n",
1325
+ " (WORK / \"results_exp017_full.json\").read_text())\n",
1326
+ "relay_saves = globals().get(\"relay_saves\") or {\n",
1327
+ " t: str(arm_save(t)) for t in (\"e004b_relay_s0\", \"e004b_relay_s1\")}\n",
1328
+ "mb3_saves = globals().get(\"mb3_saves\") or {\n",
1329
+ " t: str(arm_save(t)) for t in (\"e017_mb3_s0\", \"e017_mb3_s1\")}\n",
1330
  "_v = RES4[\"verdict\"]\n",
1331
  "_ops = []\n",
1332
  "for _seed, _tag in ((0, \"e004b_relay_s0\"), (1, \"e004b_relay_s1\")):\n",
 
1347
  " f\"Anima 2B DiT Multiband v1 (seed {_seed}) \u2014 NON-COMMERCIAL\",\n",
1348
  " \"Three sigma-band experts on the Anima DiT, step-gated \u2014 the \"\n",
1349
  " \"first multiband stack on a DiT-class trunk.\",\n",
1350
+ " f\"exp017: P1 {RES17['P1_verdict']} (surgical>=10x=\"\n",
1351
+ " f\"{RES17['P1_surgical_10x']}, adapter effect \"\n",
1352
+ " f\"{RES17['adapter_effect_mean']:+.2e}); lesion numbers in \"\n",
1353
+ " \"exp017_anima_multiband/results.json.\",\n",
1354
  " _seed,\n",
1355
  " [\"Non-commercial (derived from NC weights).\",\n",
1356
  " \"Needs an Anima checkpoint; band gating needs a step-gated \"\n",