unparallelled commited on
Commit
73fb7d3
·
verified ·
1 Parent(s): e4a1c0b

Upload scripts/mk_lineage_680m.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/mk_lineage_680m.py +80 -0
scripts/mk_lineage_680m.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """680M phase-1 lineage: one parent (varybatch), four forks at 4k -> 16k.
3
+
4
+ All four arms read the same mix (b3 50 / b2 30 / b1 20, b3=320011377 tokens)
5
+ and all four start from loss 2.731203, so the curves are directly comparable.
6
+ Loss rows are parsed from each arm's own training log; nothing is transcribed.
7
+ """
8
+ import re, sys, os
9
+ import matplotlib; matplotlib.use("Agg")
10
+ import matplotlib.pyplot as plt
11
+
12
+ S = {"surface": "#fcfcfb", "ink": "#0b0b0b", "ink2": "#52514e", "grid": "#e4e4e1"}
13
+ D = os.path.dirname(os.path.abspath(__file__))
14
+
15
+ ARMS = [
16
+ ("p1final Muon WSD peak 1.8e-4", f"{D}/lineage_src/p1_train.log", "#eb6834", 1.7),
17
+ ("const Muon 8e-5 flat", f"{D}/lineage_src/abl_p1_const_train.log", "#12508f", 1.7),
18
+ ("cosine Muon 8e-5 -> 8e-6", f"{D}/lineage_src/abl_p1_cosine_train.log","#4a8fd4", 1.7),
19
+ ("const AdamW 8e-5 flat", f"{D}/p1_const_adamw_logs/train.log", "#b3243b", 2.2),
20
+ ]
21
+
22
+ def rows_of(p):
23
+ try: t = open(p, errors="ignore").read()
24
+ except Exception: return []
25
+ return [(int(a), float(b), float(c))
26
+ for a, b, c in re.findall(r"^step +(\d+) \| loss: ([0-9.]+) \| lr ([0-9.e+-]+)", t, re.M)]
27
+
28
+ def roll(rows, k=50):
29
+ d = {s: l for s, l, _ in rows}; xs = []; ys = []
30
+ for s, _, _ in rows:
31
+ w = [d[j] for j in range(s - k + 1, s + 1) if j in d]
32
+ if len(w) == k: xs.append(s); ys.append(sum(w) / k)
33
+ return xs, ys
34
+
35
+ fig, (axA, axB) = plt.subplots(2, 1, figsize=(11.5, 8.4), facecolor=S["surface"],
36
+ gridspec_kw={"height_ratios": [1.45, 1], "hspace": 0.22}, sharex=True)
37
+ parent_loss = None; cut = None; summary = []
38
+ for name, path, col, lw in ARMS:
39
+ rw = rows_of(path)
40
+ if not rw:
41
+ print(f" MISSING: {path}"); continue
42
+ parent_loss = rw[0][1] if parent_loss is None else parent_loss
43
+ axA.plot([s for s, _, _ in rw], [l for _, l, _ in rw], color=col, lw=.4, alpha=.16, zorder=2)
44
+ rx, ry = roll(rw)
45
+ axA.plot(rx, ry, color=col, lw=lw, zorder=5, label=f"{name} (50-step mean)")
46
+ axB.plot([s for s, _, _ in rw], [r[2] for r in rw], color=col, lw=lw, zorder=4, label=name)
47
+ if "AdamW" in name:
48
+ cut = rw[-1][0]
49
+ axA.scatter([rx[-1]], [ry[-1]], s=46, color=col, zorder=7, edgecolor=S["surface"], lw=1.2)
50
+ summary.append((name, rw[0][0], rw[-1][0], rw[-1][1], ry[-1] if ry else float("nan")))
51
+
52
+ axA.axhline(parent_loss, color=S["ink2"], lw=1.0, ls=":", alpha=.8, zorder=3)
53
+ axA.annotate(f"parent varybatch loss {parent_loss:.4f} (all four arms start here)",
54
+ xy=(6, parent_loss), xytext=(6, parent_loss + 0.013), color=S["ink2"], fontsize=8.6)
55
+ if cut:
56
+ for ax in (axA, axB):
57
+ ax.axvline(cut, color="#b3243b", lw=1.0, ls="--", alpha=.55, zorder=4)
58
+ axA.annotate(f"AdamW arm cut at {cut}", xy=(cut, parent_loss + 0.055),
59
+ xytext=(cut + 18, parent_loss + 0.055), color="#b3243b", fontsize=8.6)
60
+
61
+ for ax in (axA, axB):
62
+ ax.set_facecolor(S["surface"]); ax.grid(True, color=S["grid"], lw=.8, zorder=0); ax.set_axisbelow(True)
63
+ for k, sp in ax.spines.items():
64
+ sp.set_visible(k in ("left", "bottom")); sp.set_color(S["grid"])
65
+ ax.tick_params(colors=S["ink2"], labelsize=9)
66
+ axA.set_ylabel("training loss (nats)", color=S["ink2"], fontsize=10)
67
+ axA.set_title("680M phase 1: 4k -> 16k extension, one parent, four arms",
68
+ color=S["ink"], fontsize=12.5, loc="left", pad=11)
69
+ axA.legend(frameon=False, fontsize=9, labelcolor=S["ink2"], loc="upper right")
70
+ axB.set_yscale("log"); axB.set_ylabel("learning rate", color=S["ink2"], fontsize=10)
71
+ axB.set_xlabel("step (window 16,384 x grad-accum 32)", color=S["ink2"], fontsize=10)
72
+ axB.legend(frameon=False, fontsize=8.5, labelcolor=S["ink2"], loc="lower left", ncol=2)
73
+
74
+ out = f"{D}/plots_abl/lineage_680m_phase1.png"
75
+ os.makedirs(os.path.dirname(out), exist_ok=True)
76
+ fig.savefig(out, dpi=170, bbox_inches="tight", facecolor=S["surface"])
77
+ print(f"wrote {out}")
78
+ print(f"{'arm':34s} {'steps':>12s} {'final':>9s} {'50-step mean':>13s}")
79
+ for n, a, b, f, m in summary:
80
+ print(f"{n:34s} {a:5d}..{b:<5d} {f:9.4f} {m:13.4f}")