unparallelled commited on
Commit
fda8831
·
verified ·
1 Parent(s): 0154b2d

Upload scripts/mk_recipe.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/mk_recipe.py +52 -0
scripts/mk_recipe.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """The recipe figure: compression helps at INFERENCE, destroys at TRAINING."""
3
+ import matplotlib; matplotlib.use("Agg")
4
+ import matplotlib.pyplot as plt
5
+ S={"surface":"#fcfcfb","ink":"#0b0b0b","ink2":"#52514e","grid":"#e4e4e1"}
6
+ def sty(ax):
7
+ ax.set_facecolor(S["surface"])
8
+ for s in ax.spines.values(): s.set_color(S["grid"])
9
+ ax.grid(True,color=S["grid"],lw=.7,alpha=.9); ax.tick_params(colors=S["ink2"],labelsize=9)
10
+ fig,(a,b,c)=plt.subplots(1,3,figsize=(17.4,5.4),facecolor=S["surface"])
11
+
12
+ # A: inference-side -- compression helps
13
+ sc=[8,16,32,64]; v=[34,54,79,79]; v2=[None,32,46,75]
14
+ a.plot(sc,v,"o-",color="#12508f",lw=2.4,ms=8,label="32,744 tokens")
15
+ a.plot(sc[1:],v2[1:],"s-",color="#4a8fd4",lw=2.4,ms=8,label="65,512 tokens")
16
+ sty(a); a.set_xscale("log",base=2); a.set_xticks(sc); a.set_xticklabels([f"x{s}" for s in sc])
17
+ a.set_ylim(0,100); a.set_xlabel("YARN_SCALE at INFERENCE",color=S["ink2"],fontsize=10)
18
+ a.set_ylabel("niah_single (%)",color=S["ink2"],fontsize=10)
19
+ a.set_title("At INFERENCE, compression HELPS",color=S["ink"],fontsize=12,loc="left",pad=10)
20
+ a.legend(frameon=False,fontsize=9,labelcolor=S["ink2"],loc="lower right")
21
+ a.text(9,12,"content moves into angles\nthe model saw in pretraining",fontsize=8,color=S["ink2"],style="italic")
22
+
23
+ # B: training-side -- compression destroys
24
+ labels=["pretrain\nT=4096 x1","p1final train\nT=16k x4\n(invariant)","t32 train\nT=32k x32\n(invariant BROKEN)"]
25
+ dens=[1,4,32]; res=[None,90,51]
26
+ bars=b.bar(range(3),dens,color=["#b0b0aa","#12508f","#b3243b"])
27
+ sty(b); b.set_yscale("log",base=2); b.set_xticks(range(3)); b.set_xticklabels(labels,fontsize=8.4)
28
+ b.set_ylabel("tokens per virtual position unit",color=S["ink2"],fontsize=10)
29
+ b.set_title("At TRAINING, compression DESTROYS",color=S["ink"],fontsize=12,loc="left",pad=10)
30
+ for i,(d,r) in enumerate(zip(dens,res)):
31
+ b.text(i,d*1.25,f"{d}x",ha="center",fontsize=10,color=S["ink2"])
32
+ if r: b.text(i,1.05,f"scores {r}",ha="center",fontsize=9.5,color="white",
33
+ bbox=dict(fc="#12508f" if r>70 else "#b3243b",ec="none",pad=2.6))
34
+
35
+ # C: the recipe
36
+ c.axis("off"); c.set_facecolor(S["surface"])
37
+ c.text(.02,.95,"THE RECIPE",fontsize=13,color=S["ink"],weight="bold",va="top")
38
+ c.text(.02,.845,"TRAIN with the invariant intact:\n SCALE x ORIG == CP_T\n"
39
+ " -> uses the FULL virtual range 0..4095\n -> minimum compression for that length\n"
40
+ " -> positional sensitivity preserved",
41
+ fontsize=10,color=S["ink2"],va="top",family="monospace")
42
+ c.text(.02,.545,"INFER at a HIGHER scale:\n SCALE ~= prompt_len / 1500\n"
43
+ " -> lands content near virtual 1000-2000\n -> worth up to +52pp, free",
44
+ fontsize=10,color=S["ink2"],va="top",family="monospace")
45
+ c.text(.02,.31,"p1final does exactly this:\n trained T=16,384 x4 (invariant OK)\n evaluated at x64 -> 95 / 90 / 82",
46
+ fontsize=10,color="#12508f",va="top",family="monospace")
47
+ c.text(.02,.13,"What I did wrong:\n trained T=32,768 x32 (invariant broken)\n 90 -> 51, collapsed by step 800",
48
+ fontsize=10,color="#b3243b",va="top",family="monospace")
49
+ fig.text(.005,.005,"680M, niah_single, N=100, identical haystack. Compression = tokens per virtual position unit = SCALE.",
50
+ fontsize=8,color=S["ink2"])
51
+ fig.tight_layout(); fig.savefig("results_2026-09-16/recipe.png",dpi=150,bbox_inches="tight")
52
+ print(" wrote results_2026-09-16/recipe.png")