File size: 6,951 Bytes
ba0faed | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | import matplotlib; matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import csv, glob, os
HERE=os.path.dirname(os.path.abspath(__file__))
E=os.environ.get("MOS_EVAL_DIR",os.path.normpath(os.path.join(HERE,"..","eval_csv")))
# ---- 颜色宪法(固定,勿改):gen灰 merge橙 route蓝 A绿 B紫 C金 D青 ----
CG="#8a8f98"; CM="#E8590C"; CR="#1971C2"; CA="#2F9E44"; CB="#9C36B5"; CC="#E8B117"; CD="#0B7285"
CRW="#4DABF7"; CAW="#D6336C"; CSG="#C92A2A"; CSD="#5F3DC4"
def loadal(p):
d={}
for r in csv.reader(open(p)):
if not r or r[0].startswith("ckpt"): continue
try: d[int(r[1])]=float(r[3])
except: pass
return d
v2=loadal(f"{E}/mv2c89/al_curve.csv"); v3={**loadal(f"{E}/mv3x89/al_curve.csv"),**loadal(f"{E}/merge89/al_curve.csv")}
rc=loadal(f"{E}/rc89/al_curve.csv"); rw={**loadal(f"{E}/rw89x/al_curve.csv"),**loadal(f"{E}/route89/al_curve.csv")}
gen={}
for f in glob.glob(f"{E}/gendense_l*/*.csv"):
for r in csv.reader(open(f)):
if len(r)>=4 and r[2]=="code":
try: gen[int(r[1])]=float(r[3])
except: pass
S=64/1e6; PRE=3.2; V2E=49936; RB=31210
gx=[k*S for k in sorted(gen)]; gy=[gen[k] for k in sorted(gen)]
mx=[PRE+k*S for k in sorted(v2)]+[PRE+(V2E+k)*S for k in sorted(v3)]; my=[v2[k] for k in sorted(v2)]+[v3[k] for k in sorted(v3)]
rck=[k for k in sorted(rc) if k<=30000]
rx=[PRE+k*S for k in rck]+[PRE+(RB+k)*S for k in sorted(rw)]; ry=[rc[k] for k in rck]+[rw[k] for k in sorted(rw)]
rx+=[7.19,7.59,7.99]; ry+=[3.487,3.517,3.537] # WR-2
rx+=[8.39,8.79,9.19]; ry+=[3.518,3.510,3.544] # WR-3
rx+=[9.59,9.99,10.39]; ry+=[3.518,3.553,3.568] # WR-4 峰 3.568
rx+=[10.79,11.19,11.59]; ry+=[3.562,3.549,3.542] # WR-5 衰减,确认到顶
A=[3.312,3.473,3.549,3.610,3.645,3.616,3.655,3.640]; ax_=[0.8*(i+1) for i in range(len(A))]
B=[3.477,3.586,3.626,3.657,3.709,3.719,3.716,3.710]; bx_=[PRE+0.8*(i+1) for i in range(len(B))]
C=[3.185,3.315,3.395,3.420,3.433,3.440,3.461,3.473,3.466,3.471,3.468]; cx_=[0.8*(i+1) for i in range(11)]
D=[3.471,3.536,3.553,3.606,3.629,3.611,3.648,3.626]; dx_=[PRE+0.8*(i+1) for i in range(8)]
RW=[3.466,3.463,3.473,3.541,3.504,3.549,3.557,3.563,3.550,3.563,3.564,3.562,3.556,3.579,3.589,3.574,3.589]; rwx=[3.2+0.4*(i+1) for i in range(17)]
AW=[3.411,3.391,3.438,3.457,3.446,3.472,3.471,3.462]; awx=[3.2+0.4*(i+1) for i in range(8)]
SG=[3.411,3.490,3.519,3.587,3.563,3.607,3.618,3.581]; sgx=[3.2+0.4*(i+1) for i in range(8)]
SD=[3.186,3.295,3.372,3.421,3.448,3.514,3.488,3.487]; sdx=[0.4*(i+1) for i in range(8)]
# AW/SD are retained for reproducibility but omitted from this compact recipe
# overview; the most relevant G-init. complete code specialist is shown directly,
# while the remaining controls stay in the paper table and supplement.
# 每条曲线:(x, y, 颜色, marker, 线型, 线宽);颜色仅作辅助,灰度下由 marker/线型区分
E2E=2.6; CTX=1.7 # 端到端加粗,其余作背景
CURVES=[
(gx,gy,CG,"s",":",CTX),
(mx,my,CM,"P","-.",CTX),
(rx,ry,CR,"o","--",CTX),
(rwx,RW,CRW,"X",(0,(6,2)),CTX),
(cx_,C,CC,"D",(0,(3,1,1,1)),E2E),
(dx_,D,CD,"v",(0,(6,2)),E2E),
(sgx,SG,CSG,"^",(0,(1,1)),CTX),
(ax_,A,CA,"o","-",E2E),
(bx_,B,CB,"s","-",E2E),
]
fig,ax=plt.subplots(figsize=(6.8,3.8))
for sp in ["top","right"]: ax.spines[sp].set_visible(False)
for sp in ["left","bottom"]:
ax.spines[sp].set_color("#666")
ax.spines[sp].set_linewidth(0.6)
ax.grid(axis="y",alpha=0.55,lw=0.5,color="#c9ced6")
ax.tick_params(colors="#333",labelsize=9.2,width=0.6,length=3)
# generalist 预训练竖线 + 从 generalist 热启的三条连线(虚线)
ax.axvline(PRE,ls=(0,(2,3)),lw=1.1,color="#c2c7cf")
ax.text(PRE-0.05,3.785,"3.2M pretraining",color="#333",fontsize=9.0,ha="right")
G0=(3.2,3.4075)
for x1,y1,cc in [(bx_[0],B[0],CB),(dx_[0],D[0],CD),(rwx[0],RW[0],CRW)]:
ax.plot([G0[0],x1],[G0[1],y1],ls=(0,(2,2)),lw=1.1,color=cc,alpha=0.45,zorder=2)
ax.plot([G0[0]],[G0[1]],"o",ms=5,color="#8a8f98",mfc="white",mew=1.2,zorder=3)
for xs,ys,c,mk,ls,lw in CURVES:
ax.plot(xs,ys,color=c,ls=ls,marker=mk,lw=lw,ms=5.0 if lw==E2E else 4.0,
mfc="white",mec="#222",mew=0.8,alpha=1.0,zorder=5 if lw==E2E else 3)
pk=max(ys); i=ys.index(pk)
ax.plot([xs[i]],[pk],marker="*",ls="none",ms=7.5,mfc=c,mec="#222",mew=0.6,zorder=6)
ax.set_xlim(0,11.9); ax.set_ylim(3.10,3.80)
ax.set_xlabel("Cumulative training samples (millions)",fontsize=10.0)
ax.set_ylabel("Code acceptance length",fontsize=10.0)
# ---- 右下角:结果排行图例表(按峰值降序) ----
# (颜色, marker, 线型, 线宽, 名称, 峰值字符串, 是否冠军)
ROWS=[
(CB,"s","-",E2E,"G-init. MoS, shared updated","3.719",True),
(CA,"o","-",E2E,"D0-init. MoS, shared updated","3.655",False),
(CD,"v",(0,(6,2)),E2E,"G-init. MoS, shared frozen","3.648",False),
(CSG,"^",(0,(1,1)),CTX,"G-init. complete code specialist","3.618",False),
(CRW,"X",(0,(6,2)),CTX,"Frozen generalist, G-init. MLPs","3.589",False),
(CR,"o","--",CTX,"Frozen generalist, D0-init. MLPs","3.568",False),
(CC,"D",(0,(3,1,1,1)),E2E,"D0-init. MoS, shared frozen","3.473",False),
(CM,"P","-.",CTX,"RegMean-style attention merge","3.470",False),
(CG,"s",":",CTX,"Generalist","3.435",False),
]
LX0,LX1=0.455,0.995; LTOP,LBOT=0.455,0.025
n=len(ROWS); hh=0.060 # header 高
rh=(LTOP-LBOT-hh)/n
# 背景框
ax.add_patch(plt.Rectangle((LX0,LBOT),LX1-LX0,LTOP-LBOT,transform=ax.transAxes,
facecolor="#fbfcfd",edgecolor="#dfe3e8",lw=1.0,zorder=8,clip_on=False,
joinstyle="round"))
# 表头
hy=LTOP-hh*0.58
ax.text(LX0+0.090,hy,"Recipe",transform=ax.transAxes,
fontsize=9.0,color="#222",fontweight="bold",va="center",zorder=9)
ax.text(LX1-0.018,hy,"Peak AL",transform=ax.transAxes,fontsize=9.0,color="#222",
fontweight="bold",va="center",ha="right",zorder=9)
ax.plot([LX0+0.015,LX1-0.015],[LTOP-hh,LTOP-hh],transform=ax.transAxes,
color="#dfe3e8",lw=1.0,zorder=9,clip_on=False)
# 行
for j,(c,mk,ls,lw,name,pk,champ) in enumerate(ROWS):
yy=LTOP-hh-rh*(j+0.5)
if champ:
ax.add_patch(plt.Rectangle((LX0+0.006,yy-rh*0.46),LX1-LX0-0.012,rh*0.92,
transform=ax.transAxes,facecolor="#eceff3",edgecolor="none",zorder=8.5,clip_on=False))
# 色样(短线+marker)
ax.plot([LX0+0.022,LX0+0.068],[yy,yy],color=c,ls=ls,marker=mk,lw=lw,ms=5.0,
mfc="white",mec="#222",mew=0.8,transform=ax.transAxes,zorder=9,clip_on=False)
ax.text(LX0+0.090,yy,name,transform=ax.transAxes,fontsize=9.0,color="#222",
va="center",zorder=9,fontweight="bold" if champ else "normal")
ax.text(LX1-0.018,yy,pk,transform=ax.transAxes,fontsize=9.0,color="#222",
fontweight="bold",va="center",ha="right",zorder=9)
OUT=os.environ.get("MOS_RECIPE_BUDGET_OUT",os.path.normpath(os.path.join(HERE,"..","figs","recipe_budget.png")))
plt.tight_layout(pad=0.3); plt.savefig(OUT,dpi=330,bbox_inches="tight")
print("saved")
|