suchirsalhan commited on
Commit
55a1aa7
·
verified ·
1 Parent(s): 435b4a7

Upload code/make_report.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. code/make_report.py +211 -41
code/make_report.py CHANGED
@@ -82,6 +82,66 @@ L.append("""## Read this first: what substrate, and what metric
82
  > below — and it does not hold.** SET 4 has no accuracy benchmark in this window (see Coverage).
83
  """)
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  if set1:
86
  L.append("\n## SET 1 · PolyPythia seed-merge (the pure-coordinate ceiling)\n")
87
  L.append(f"C(9,2) = 36 seed pairs per size. Predictors are computed **before** any merge; the "
@@ -287,30 +347,140 @@ is not a caveat to add to a positive result here; on this substrate it is the re
287
  L.append(md_table(["substrate", "n", "Spearman(Δfloor rescue, BLiMP rescue)",
288
  "mean Δfloor rescue (nats/tok)", "mean BLiMP rescue (acc)"], corr_rows))
289
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  L.append("\n## P0-2 · Do the pre-merge predictors predict the realised rescue?\n")
291
  if os.path.exists(f"{R}/predictor_auroc.csv"):
292
  rows = [l.rstrip("\n").split(",") for l in open(f"{R}/predictor_auroc.csv")]
293
  hdr, dat = rows[0], rows[1:]
294
  ix = {h: i for i, h in enumerate(hdr)}
 
 
 
295
  body = []
296
- for d in dat:
297
- if d[ix.get("outcome", 0)] != "rescue_frac" and "outcome" in ix and d[ix["outcome"]] != "dfloor_M1best":
298
- continue
299
- body.append([d[ix["substrate"]], d[ix["outcome"]] if "outcome" in ix else "rescue_frac",
300
- d[ix["predictor"]], d[ix["n_pairs"]],
301
- fmt(float(d[ix["spearman_rescue"]]) if d[ix["spearman_rescue"]] else None),
302
- fmt(float(d[ix["auroc_heldout_by_seed"]]) if d[ix["auroc_heldout_by_seed"]] else None),
303
- fmt(float(d[ix["perm_null_mean"]]) if d[ix["perm_null_mean"]] else None),
304
- fmt(float(d[ix["perm_null_p"]]) if d[ix["perm_null_p"]] else None),
305
- fmt(float(d[ix["bh_q"]]) if d[ix["bh_q"]] else None)])
306
- L.append("Outcome = **realised rescue** = the fraction of the naive Δfloor that the best M1 rung "
307
- "removes. Label = above the within-size median. Held out **by seed**: fold *k* is every "
308
- "pair touching seed *k*, trained on the pairs touching neither, so the predictor's sign "
309
- "(and, for the multivariate row, its coefficients) never see the held-out pairs. Null = "
310
- "**seed-cluster permutation** (2000 draws): permute the seed identities and re-map each "
311
- "pair's outcome to the permuted pair, leaving the predictor vector untouched — this "
312
- "preserves the pair-dependence structure that a plain label shuffle destroys. "
313
- "BH-corrected across the predictor family.\n")
314
  L.append(md_table(["substrate", "outcome", "predictor", "n", "Spearman",
315
  "AUROC (held out by seed)", "null mean", "perm p", "BH q"], body))
316
  if os.path.exists(f"{R}/predictor_transfer_across_size.csv"):
@@ -341,6 +511,29 @@ if os.path.exists(f"{R}/set4_predictors.csv"):
341
  for d in dat]))
342
 
343
  # coverage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
344
  abl = load("abl_*.jsonl")
345
  if abl:
346
  L.append("\n## Control · is the obstruction the INIT seed or the DATA order?\n")
@@ -380,29 +573,6 @@ and it also means SET 1's main grid conflates the two sources — its naive Δfl
380
  init-plus-data-order number, not an init-only one.
381
  """)
382
 
383
- L.append("""
384
- ### What P0-2 comes to
385
-
386
- **Within a single substrate, nothing predicts the realised rescue.** On pythia-14m — 36 seed pairs,
387
- a complete grid, a properly structured seed-cluster null — every pre-merge predictor we computed
388
- (weight cosine, QMD in weight space and in representation space, coordinate share, CKA, task-vector
389
- cosine) lands between AUROC 0.30 and 0.68 held out by seed, and **not one survives BH correction**.
390
- The multivariate ridge over all of them does no better. This is a negative transfer result and it is
391
- reported as one: the alignment-derived quantities that predict mergeability in the synthetic/S3
392
- setting do **not** rank real reseeded-LM pairs by how much alignment will actually rescue them.
393
-
394
- **Across substrates the picture is only slightly better and it is not consistent.** The
395
- block-normalised coordinate share does transfer to some held-out sizes and not to others. Read
396
- against the whole family that is one predictor doing well on part of the grid, not a validated
397
- instrument, and it should not be quoted as a headline number.
398
-
399
- Two honest caveats in the other direction. First, the *within-substrate* variance in rescue is small
400
- relative to the *between*-substrate variance — every pair at a given size is rescued by roughly the
401
- same amount — so there may simply be little signal left for a within-size predictor to find. Second,
402
- the seed-cluster null is conservative by construction. Neither rescues the positive claim: on this
403
- substrate, at this n, the predictors do not predict.
404
- """)
405
-
406
  L.append("\n## Coverage — what ran and what did not\n")
407
  cov = []
408
  for sz in ["14m", "70m", "160m"]:
 
82
  > below — and it does not hold.** SET 4 has no accuracy benchmark in this window (see Coverage).
83
  """)
84
 
85
+ # ---------------- headline summary (computed, so it cannot drift from the tables)
86
+ _bl = load("blimp_*.jsonl"); _rp = load("repair_*.jsonl"); _mb = load("set4_multiblimp.jsonl")
87
+ if set1:
88
+ hl = []
89
+ s14 = [r for r in set1 if r["size"] == sizes[0]]
90
+ dd = {}
91
+ for sz in sizes:
92
+ sub = [r for r in set1 if r["size"] == sz]
93
+ d0 = np.array([r["rungs"]["M0_naive_avg"]["delta_floor"] for r in sub])
94
+ db = np.array([min(r["rungs"]["M1_perm_avg"]["delta_floor"],
95
+ r["rungs"]["M1_orth_avg"]["delta_floor"]) for r in sub])
96
+ dd[sz] = (len(sub), d0.mean(), float(np.mean(1 - db / d0) * 100), db.mean())
97
+ hl.append(f"1. **Naive averaging of two seed-only-different real LMs is catastrophic, at every "
98
+ f"size.** Δfloor {' · '.join(f'{sz}: +{dd[sz][1]:.1f}' for sz in sizes)} nats/token "
99
+ f"against parent floors of 3–4.4 nats/token, i.e. above the uniform-over-vocabulary "
100
+ f"reference of 10.8 for all but the largest. n = "
101
+ f"{' / '.join(str(dd[sz][0]) for sz in sizes)} pairs.")
102
+ hl.append(f"2. **Unit alignment removes a large fraction of that gap and still does not produce a "
103
+ f"usable model.** Best of permutation / Procrustes removes "
104
+ f"{' · '.join(f'{sz}: {dd[sz][2]:.0f}%' for sz in sizes)} — leaving "
105
+ f"{' · '.join(f'{dd[sz][3]:.1f}' for sz in sizes)} nats/token above the better parent.")
106
+ hl.append(f"3. **The rescue shrinks monotonically with scale** ({sizes[0]}: {dd[sizes[0]][2]:.0f}% "
107
+ f"→ {sizes[-1]}: {dd[sizes[-1]][2]:.0f}%) while the naive gap shrinks too — so the "
108
+ f"coordinate-removable share of the obstruction is falling in exactly the direction the "
109
+ f"field is scaling. (Per-size n is listed in (1); the largest sizes carry the fewest "
110
+ f"pairs, so read the trend from the sizes with complete 36-pair grids and treat the "
111
+ f"largest as directional.)")
112
+ if _bl:
113
+ b14 = [b for b in _bl if b["size"] == sorted({x['size'] for x in _bl}, key=lambda x: int(x[:-1]))[0]]
114
+ pm = np.mean([np.mean(list(b["parent_acc"].values())) for b in b14])
115
+ m0 = np.mean([b["rungs"]["M0_naive_avg"]["blimp_acc"] for b in b14])
116
+ m1 = np.mean([max(b["rungs"][k]["blimp_acc"] for k in b["rungs"] if k.startswith("M1")) for b in b14])
117
+ hl.append(f"4. **The likelihood rescue does not transfer to accuracy.** On pythia-{b14[0]['size']} "
118
+ f"(n={len(b14)}), parents average {pm:.3f} on BLiMP; the naive merge {m0:.3f} and the "
119
+ f"aligned merge {m1:.3f}, against chance 0.500. A ~70% Δfloor rescue buys ~"
120
+ f"{(m1-m0):.3f} accuracy. Pairwise, the two rescues are uncorrelated.")
121
+ if set4:
122
+ d0e = np.mean([r["rungs"]["M0_naive_avg"]["delta_floor_eng"] for r in set4])
123
+ bst = np.mean([min(r["rungs"][k]["delta_floor_eng"] for k in r["rungs"] if k.startswith("M1")) for r in set4])
124
+ hl.append(f"5. **On the real bilingual-composition models the merge fails and alignment does not "
125
+ f"rescue it.** Goldfish eng×{{nld,spa,ell,pol}}: naive Δfloor on English text "
126
+ f"+{d0e:.2f} nats/byte against a 0.81 floor; the best M1 rung +{bst:.2f}. The binding "
127
+ f"constraint is the **vocabulary**, not the coordinate frame — the English tokenizer "
128
+ f"UNK-s 45% of Greek and 11% of Polish, and no permutation or rotation can address that.")
129
+ if _mb:
130
+ hl.append(f"6. **…and the accuracy dissociation runs the other way there.** The same "
131
+ f"likelihood-destroyed Goldfish merges retain "
132
+ f"{np.mean([r['rungs']['M0_naive_avg']['mb_eng'] for r in _mb]):.2f} on "
133
+ f"MultiBLiMP-English (parent {_mb[0]['parents']['eng_on_mb_eng']:.2f}, chance 0.50). "
134
+ f"Δfloor and benchmark accuracy dissociate in **both** directions; neither implies the other.")
135
+ hl.append("7. **P0-2: the pre-merge predictors do not predict the realised rescue.** Held out by "
136
+ "seed pair on a complete 36-pair grid with a seed-cluster permutation null, no predictor "
137
+ "survives BH correction. Reported as the negative transfer result it is.")
138
+ if _rp:
139
+ hl.append("8. **This is not an under-trying artifact.** REPAIR-style statistics correction on "
140
+ "top of the alignment — the strongest training-free merge here — improves the "
141
+ "likelihood further and still leaves BLiMP near chance.")
142
+ L.append("\n## Headline findings\n")
143
+ L.append("\n".join(hl) + "\n")
144
+
145
  if set1:
146
  L.append("\n## SET 1 · PolyPythia seed-merge (the pure-coordinate ceiling)\n")
147
  L.append(f"C(9,2) = 36 seed pairs per size. Predictors are computed **before** any merge; the "
 
347
  L.append(md_table(["substrate", "n", "Spearman(Δfloor rescue, BLiMP rescue)",
348
  "mean Δfloor rescue (nats/tok)", "mean BLiMP rescue (acc)"], corr_rows))
349
 
350
+ # ---------------- REPAIR
351
+ rep = load("repair_*.jsonl")
352
+ if rep:
353
+ L.append("\n## Did we try hard enough? · REPAIR on top of the alignment\n")
354
+ L.append("The obvious objection to a negative merging result is that averaging is a weak merge: it "
355
+ "halves the variance of every pre-activation, and REPAIR (Jordan et al., ICLR 2023) shows "
356
+ "that restoring those statistics recovers most of the remaining barrier on vision nets. "
357
+ "This rung adds it, training-free: after the permutation-aligned average, walk the layers "
358
+ "in order and affine-correct each Linear's per-unit pre-activation mean and std to the "
359
+ "average of the two parents' own statistics on the same corpus. `M5` applies the same "
360
+ "correction to the *naive* merge, to separate what alignment contributes from what "
361
+ "statistics-repair contributes.\n")
362
+ rk = ["M0_naive_avg", "M1_perm_avg", "M4_perm_repair", "M5_naive_repair"]
363
+ body = []
364
+ for sz in sorted({r["size"] for r in rep}, key=lambda x: int(x[:-1])):
365
+ sub = [r for r in rep if r["size"] == sz]
366
+ fl = np.mean([r["floor"] for r in sub]); ce = np.mean([r["blimp_ceiling"] for r in sub])
367
+ for k in rk:
368
+ if k not in sub[0]["rungs"]: continue
369
+ d = np.array([r["rungs"][k]["delta_floor"] for r in sub])
370
+ a = np.array([r["rungs"][k]["blimp_acc"] for r in sub])
371
+ body.append([f"pythia-{sz}", len(sub), k, fmt(d.mean(), 2), fmt(np.median(d), 2),
372
+ fmt(a.mean()), fmt((a.mean() - 0.5) / (ce - 0.5) * 100, 1) + "%"])
373
+ body.append([f"pythia-{sz}", len(sub), "**parents**", "0.00", "0.00", fmt(ce), "100.0%"])
374
+ L.append(md_table(["substrate", "n pairs", "rung", "mean Δfloor (nats/tok)", "median Δfloor",
375
+ "BLiMP accuracy", "% of the parents' above-chance margin retained"], body))
376
+ L.append("""
377
+ REPAIR does help the likelihood — it takes a further bite out of the aligned merge's Δfloor, and it
378
+ is the best training-free merge in this report. It does **not** change the conclusion. The repaired
379
+ aligned merge is still many nats/token above the better parent, still above the
380
+ uniform-over-vocabulary reference at the small sizes, and still close to chance on BLiMP. Applied to
381
+ the *naive* merge it barely moves anything, which is the expected pattern: variance repair is only
382
+ useful once the units correspond.
383
+
384
+ So the negative result is not an artifact of using a deliberately weak merge operator. Naive
385
+ averaging, unit-aligned averaging, orthogonal alignment, task arithmetic, TIES and REPAIR-corrected
386
+ alignment were all tried on the same pairs; the best of them recovers most of the likelihood gap at
387
+ 14M, a quarter of it at 160M, and grammatical competence in none of them.
388
+ """)
389
+
390
+ # ---------------- SET 4 accuracy arm
391
+ mb = load("set4_multiblimp.jsonl")
392
+ if mb:
393
+ L.append("\n## SET 4 · the accuracy arm (MultiBLiMP 1.0)\n")
394
+ L.append("`jumelet/multiblimp` covers exactly the four partner languages plus English. Minimal "
395
+ "pairs are `sen` vs `wrong_sen`; correct when the grammatical member gets the higher "
396
+ "total log-probability. **Chance = 0.500.** The merged models live in the **English** "
397
+ "parent's token-id space, so partner-language items are scored through the English "
398
+ "tokenizer — the UNK column says how badly that hurts, and where it is large the "
399
+ "partner-language number is a tokenizer artifact, not a competence measurement.\n")
400
+ rk = list(mb[0]["rungs"])
401
+ body = []
402
+ for r in mb:
403
+ body.append([f"eng–{r['lang']}", r["n_items_x"], f"{r['unk_rate_eng_tok_on_x_items']:.1%}",
404
+ fmt(r["parents"]["eng_on_mb_eng"]), fmt(r["parents"]["x_on_mb_x"]),
405
+ fmt(r["parents"]["eng_on_mb_x"])])
406
+ L.append("**Parents** (each on its own tokenizer except the last column):\n")
407
+ L.append(md_table(["pair", "n items (partner)", "UNK rate, English tok on partner items",
408
+ "English parent, MultiBLiMP-eng", "partner parent, MultiBLiMP-partner",
409
+ "English parent, MultiBLiMP-partner"], body))
410
+ L.append("\n**Merged models, MultiBLiMP-English accuracy** (the clean cell — 0.04% UNK; English "
411
+ "parent ceiling in the first column):\n")
412
+ L.append(md_table(["pair", "English parent"] + rk,
413
+ [[f"eng–{r['lang']}", fmt(r["parents"]["eng_on_mb_eng"])] +
414
+ [fmt(r["rungs"][k]["mb_eng"]) for k in rk] for r in mb]))
415
+ L.append("\n**Merged models, MultiBLiMP-partner accuracy** (partner parent ceiling in the first "
416
+ "column; rows with a high UNK rate are struck through in interpretation, not in the "
417
+ "numbers):\n")
418
+ L.append(md_table(["pair", "partner parent", "UNK"] + rk,
419
+ [[f"eng–{r['lang']}", fmt(r["parents"]["x_on_mb_x"]),
420
+ f"{r['unk_rate_eng_tok_on_x_items']:.0%}"] +
421
+ [fmt(r["rungs"][k]["mb_x"]) for k in rk] for r in mb]))
422
+ L.append("""
423
+ **What the accuracy arm adds, and it cuts the other way from SET 1.**
424
+
425
+ - The English-side accuracy of the naive merge (mean 0.680, parent 0.962) is far below the parent
426
+ but **far above chance** — while its Δfloor on the same text is roughly a nat per byte, i.e. by the likelihood
427
+ metric the model is destroyed. A merge can look annihilated in nats and still retain a large
428
+ fraction of an agreement benchmark.
429
+ - The unit-aligned rungs are a **wash** against the naive merge on accuracy. Averaged over the four
430
+ pairs the naive merge scores 0.680 on MultiBLiMP-English against 0.645–0.671 for the aligned rungs,
431
+ and 0.536 on the partner side (Greek excluded) against 0.527–0.556. Individual cells go both ways —
432
+ the vocabulary-transported rungs help Spanish and hurt Dutch — with no consistent direction and a
433
+ spread far smaller than the ~0.30 gap to the parents. Nothing in the M1 family recovers
434
+ composition; they reshuffle a uniformly bad result.
435
+ - Greek is the clean illustration of the tokenizer wall: at a 45% UNK rate the English parent scores
436
+ 0.03 on MultiBLiMP-Greek — far *below* chance, because `<unk>`-collapsed sentences make the
437
+ ungrammatical member the likelier string. Nothing about Greek grammar is being measured there. Any
438
+ cross-tokenizer merge that keeps one parent's vocabulary inherits this, and it is a property of the
439
+ vocabulary, not of the coordinate frame — no alignment over the permutation or orthogonal group
440
+ can touch it.
441
+ - Taken with SET 1: **Δfloor and benchmark accuracy dissociate in both directions.** In SET 1 a large
442
+ likelihood rescue buys almost no accuracy. In SET 4 a catastrophic likelihood loss leaves a lot of
443
+ accuracy standing. Whichever of the two you report, the other does not follow from it.
444
+ """)
445
+
446
+ rev = load("set4_reverse.jsonl")
447
+ if rev:
448
+ L.append("\n## SET 4 · reverse direction (the partner language is the anchor)\n")
449
+ L.append("Identical rungs, but the merged model lives in the **partner** language's tokenizer and "
450
+ "residual basis and English is transported into it. If the failure were an artifact of "
451
+ "anchoring on English it would not survive the swap.\n")
452
+ rk = list(rev[0]["rungs"])
453
+ L.append(md_table(["anchor", "floor (anchor lang)", "floor (English)"] + rk,
454
+ [[r["lang"], fmt(r["floor_x"]), fmt(r["floor_eng"])] +
455
+ [fmt(r["rungs"][k]["delta_floor_mean"]) for k in rk] for r in rev]))
456
+ L.append("\nΔfloor, mean over the two languages, nats/UTF-8 byte. The failure is symmetric: "
457
+ "anchoring on the partner language does not make the merge work either.\n")
458
+
459
  L.append("\n## P0-2 · Do the pre-merge predictors predict the realised rescue?\n")
460
  if os.path.exists(f"{R}/predictor_auroc.csv"):
461
  rows = [l.rstrip("\n").split(",") for l in open(f"{R}/predictor_auroc.csv")]
462
  hdr, dat = rows[0], rows[1:]
463
  ix = {h: i for i, h in enumerate(hdr)}
464
+ def _f(d, k):
465
+ try: return float(d[ix[k]])
466
+ except Exception: return float("nan")
467
  body = []
468
+ for oc in ("rescue_frac", "dfloor_M1best"):
469
+ sel = [d for d in dat if d[ix["outcome"]] == oc]
470
+ for sub_ in sorted({d[ix["substrate"]] for d in sel}, key=lambda x: int(x.split("-")[1][:-1])):
471
+ ss = [d for d in sel if d[ix["substrate"]] == sub_]
472
+ mv = [d for d in ss if d[ix["predictor"]].startswith("MULTIV")]
473
+ uv = sorted([d for d in ss if not d[ix["predictor"]].startswith("MULTIV")],
474
+ key=lambda d: -abs(_f(d, "auroc_heldout_by_seed") - 0.5))[:6]
475
+ for d in uv + mv:
476
+ body.append([sub_, oc, d[ix["predictor"]], d[ix["n_pairs"]],
477
+ fmt(_f(d, "spearman_rescue")), fmt(_f(d, "auroc_heldout_by_seed")),
478
+ fmt(_f(d, "perm_null_mean")), fmt(_f(d, "perm_null_p")),
479
+ fmt(_f(d, "bh_q"))])
480
+ L.append("Showing, per substrate and per outcome, the **six predictors with the largest "
481
+ "|AUROC 0.5|** plus the multivariate ridge. The full table (every predictor, both "
482
+ "outcomes, every substrate) is `results/predictor_auroc.csv`; selecting the extremes "
483
+ "here is deliberately generous to the positive claim.\n")
 
 
484
  L.append(md_table(["substrate", "outcome", "predictor", "n", "Spearman",
485
  "AUROC (held out by seed)", "null mean", "perm p", "BH q"], body))
486
  if os.path.exists(f"{R}/predictor_transfer_across_size.csv"):
 
511
  for d in dat]))
512
 
513
  # coverage
514
+ L.append("""
515
+ ### What P0-2 comes to
516
+
517
+ **Within a single substrate, nothing predicts the realised rescue.** On pythia-14m — 36 seed pairs,
518
+ a complete grid, a properly structured seed-cluster null — every pre-merge predictor we computed
519
+ (weight cosine, QMD in weight space and in representation space, coordinate share, CKA, task-vector
520
+ cosine) lands between AUROC 0.30 and 0.68 held out by seed, and **not one survives BH correction**.
521
+ The multivariate ridge over all of them does no better. This is a negative transfer result and it is
522
+ reported as one: the alignment-derived quantities that predict mergeability in the synthetic/S3
523
+ setting do **not** rank real reseeded-LM pairs by how much alignment will actually rescue them.
524
+
525
+ **Across substrates the picture is only slightly better and it is not consistent.** The
526
+ block-normalised coordinate share does transfer to some held-out sizes and not to others. Read
527
+ against the whole family that is one predictor doing well on part of the grid, not a validated
528
+ instrument, and it should not be quoted as a headline number.
529
+
530
+ Two honest caveats in the other direction. First, the *within-substrate* variance in rescue is small
531
+ relative to the *between*-substrate variance — every pair at a given size is rescued by roughly the
532
+ same amount — so there may simply be little signal left for a within-size predictor to find. Second,
533
+ the seed-cluster null is conservative by construction. Neither rescues the positive claim: on this
534
+ substrate, at this n, the predictors do not predict.
535
+ """)
536
+
537
  abl = load("abl_*.jsonl")
538
  if abl:
539
  L.append("\n## Control · is the obstruction the INIT seed or the DATA order?\n")
 
573
  init-plus-data-order number, not an init-only one.
574
  """)
575
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
576
  L.append("\n## Coverage — what ran and what did not\n")
577
  cov = []
578
  for sz in ["14m", "70m", "160m"]: