Upload scripts/mk_scale_plot.py with huggingface_hub
Browse files- scripts/mk_scale_plot.py +89 -0
scripts/mk_scale_plot.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""The scale sweep: retrieval vs YaRN scale, and the two-factor grid.
|
| 3 |
+
Every number read from the summary.csv files this session produced."""
|
| 4 |
+
import csv, os, glob
|
| 5 |
+
import matplotlib; matplotlib.use("Agg")
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
+
|
| 8 |
+
S={"surface":"#fcfcfb","ink":"#0b0b0b","ink2":"#52514e","grid":"#e4e4e1"}
|
| 9 |
+
def style(ax):
|
| 10 |
+
ax.set_facecolor(S["surface"])
|
| 11 |
+
for s in ax.spines.values(): s.set_color(S["grid"])
|
| 12 |
+
ax.grid(True,color=S["grid"],lw=.7,alpha=.9); ax.tick_params(colors=S["ink2"],labelsize=9)
|
| 13 |
+
|
| 14 |
+
def read(path,model):
|
| 15 |
+
if not os.path.exists(path): return None
|
| 16 |
+
r=list(csv.reader(open(path)))
|
| 17 |
+
if len(r)<2: return None
|
| 18 |
+
hdr=r[0]
|
| 19 |
+
for row in r[1:]:
|
| 20 |
+
if row and row[0]=="niah_single" and model in hdr:
|
| 21 |
+
try: return float(row[hdr.index(model)])
|
| 22 |
+
except Exception: return None
|
| 23 |
+
return None
|
| 24 |
+
|
| 25 |
+
# (scale, prompt) -> dir
|
| 26 |
+
SRC={(4,1024):"eshort_cache16k_len1024",(8,1024):"eshort_cache32k_len1024",
|
| 27 |
+
(4,4096):"eshort_cache16k_len4096",(8,4096):"eshort_cache32k_len4096",
|
| 28 |
+
(16,4096):"e64k_len4096",(32,4096):"e128k_len4096",
|
| 29 |
+
(8,8192):"e32k_len8192",(8,16360):"e32k_len16360",(8,32744):"e32k_len32744",
|
| 30 |
+
(16,16360):"e64k_len16360",(16,32744):"e64k_len32744",(16,65512):"e64k_len65512",
|
| 31 |
+
(32,32744):"e128k_len32744",(32,65512):"e128k_len65512"}
|
| 32 |
+
PRIOR={(4,8192):84.0,(4,16360):40.0} # measured on the prior box, same haystack
|
| 33 |
+
base={}
|
| 34 |
+
for (sc,pl),d in SRC.items():
|
| 35 |
+
v=read(f"{d}/summary.csv","base680")
|
| 36 |
+
if v is not None: base[(sc,pl)]=v
|
| 37 |
+
base.update(PRIOR)
|
| 38 |
+
|
| 39 |
+
fig,(axA,axB,axC)=plt.subplots(1,3,figsize=(19.5,5.6),facecolor=S["surface"])
|
| 40 |
+
PL=[1024,4096,8192,16360,32744,65512]
|
| 41 |
+
cols=plt.cm.viridis([i/(len(PL)-1) for i in range(len(PL))])
|
| 42 |
+
for pl,c in zip(PL,cols):
|
| 43 |
+
pts=sorted((sc,v) for (sc,p),v in base.items() if p==pl)
|
| 44 |
+
if len(pts)<2: continue
|
| 45 |
+
axA.plot([p[0] for p in pts],[p[1] for p in pts],"o-",color=c,lw=2,ms=6,
|
| 46 |
+
label=f"{pl:,} tok")
|
| 47 |
+
style(axA); axA.set_xscale("log",base=2); axA.set_xticks([4,8,16,32])
|
| 48 |
+
axA.set_xticklabels(["x4","x8","x16","x32"]); axA.set_ylim(0,100)
|
| 49 |
+
axA.set_xlabel("YARN_SCALE (ORIG_MAXPOS held at 4096)",color=S["ink2"],fontsize=10)
|
| 50 |
+
axA.set_ylabel("niah_single accuracy (%)",color=S["ink2"],fontsize=10)
|
| 51 |
+
axA.set_title("Same untrained weights. Only the RoPE scale changes.",
|
| 52 |
+
color=S["ink"],fontsize=12,loc="left",pad=10)
|
| 53 |
+
axA.legend(frameon=False,fontsize=8.5,labelcolor=S["ink2"],loc="lower right")
|
| 54 |
+
|
| 55 |
+
for pl,c in zip(PL,cols):
|
| 56 |
+
pts=sorted((pl/sc,v) for (sc,p),v in base.items() if p==pl)
|
| 57 |
+
if not pts: continue
|
| 58 |
+
axB.plot([p[0] for p in pts],[p[1] for p in pts],"o-",color=c,lw=2,ms=6,label=f"{pl:,} tok")
|
| 59 |
+
style(axB); axB.set_xscale("log",base=2); axB.set_ylim(0,100)
|
| 60 |
+
axB.set_xlabel("virtual position of last token (real / scale)",color=S["ink2"],fontsize=10)
|
| 61 |
+
axB.set_ylabel("niah_single accuracy (%)",color=S["ink2"],fontsize=10)
|
| 62 |
+
axB.axvspan(2000,4200,color="#f3eceb",zorder=0)
|
| 63 |
+
axB.text(2900,6,"pretrain p90\n~2,721 tok",ha="center",fontsize=7.6,color=S["ink2"],style="italic")
|
| 64 |
+
axB.set_title("Collapses onto virtual position; spread = distractor load",
|
| 65 |
+
color=S["ink"],fontsize=12,loc="left",pad=10)
|
| 66 |
+
axB.legend(frameon=False,fontsize=8.5,labelcolor=S["ink2"],loc="lower left")
|
| 67 |
+
fig.text(.005,-.02,"680M base680, ZERO long-context training. niah_single N=100, greedy, "
|
| 68 |
+
"identical haystack (199,754,694 B) across every point. Wilson 95% CI is +/-9-13pp at N=100.",
|
| 69 |
+
fontsize=7.8,color=S["ink2"])
|
| 70 |
+
|
| 71 |
+
# ---- panel C: the 1.06B control -- config helps, but training still wins at 64k
|
| 72 |
+
PLC=[16360,32744,65512]
|
| 73 |
+
own=[70,50,31]; corr=[78,73,65]; cliff_own=[54,31,18]; cliff_corr=[66,70,65]
|
| 74 |
+
m680=[92,79,46]
|
| 75 |
+
x=range(len(PLC))
|
| 76 |
+
axC.plot(x,own,"o--",color="#b0b0aa",lw=1.6,ms=6,label="1.06B, its own config")
|
| 77 |
+
axC.plot(x,corr,"o-",color="#b3243b",lw=2.4,ms=7,label="1.06B, corrected config")
|
| 78 |
+
axC.plot(x,cliff_corr,"s--",color="#eb6834",lw=1.6,ms=6,label='1.06B "collapsed", corrected')
|
| 79 |
+
axC.plot(x,m680,"^-",color="#12508f",lw=2.4,ms=8,label="680M base, no long-ctx training")
|
| 80 |
+
style(axC); axC.set_xticks(list(x)); axC.set_xticklabels(["16k","32k","64k"])
|
| 81 |
+
axC.set_ylim(0,100); axC.set_xlabel("prompt length",color=S["ink2"],fontsize=10)
|
| 82 |
+
axC.set_ylabel("niah_single accuracy (%)",color=S["ink2"],fontsize=10)
|
| 83 |
+
axC.set_title("Control: training wins where it trained (64k)",color=S["ink"],fontsize=12,loc="left",pad=10)
|
| 84 |
+
axC.annotate("1.06B trained to 64k\nbeats the 680M here\nby 19pp",xy=(2,65),xytext=(1.05,30),
|
| 85 |
+
fontsize=8.2,color=S["ink2"],arrowprops=dict(arrowstyle="->",color=S["ink2"],lw=1))
|
| 86 |
+
axC.legend(frameon=False,fontsize=8,labelcolor=S["ink2"],loc="upper right")
|
| 87 |
+
fig.tight_layout(); fig.savefig("plots_p1/scale_sweep.png",dpi=155,bbox_inches="tight")
|
| 88 |
+
print(" wrote plots_p1/scale_sweep.png")
|
| 89 |
+
print(f" points plotted: {len(base)}")
|