Speed program: time-weighted hit-rate gap and gap by context from the real Codex sessions (ceiling of the hit-rate levers 1.8-2.6 % of task time)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-11-08 21:40:39 +01:00
co-authored by Claude Sonnet 5.5
parent cac5802fe6
commit e7dde84ea9
3 changed files with 69 additions and 0 deletions
@@ -0,0 +1,28 @@
import re,json,glob
root="/data/leleka-e2e/codex-compare/runs/main"
B=[(0,30000),(30000,60000),(60000,100000),(100000,160000),(160000,10**9)]
def cells(arm,task): return [c for c in sorted(glob.glob(f"{root}/{arm}/{task}-r*")) if not c.endswith(".out")]
def lel(c):
for l in open(c+"/engine-slice.log",errors="replace"):
if l.startswith("{") and '"ev":"request"' in l and '"comp":"engine"' in l:
j=json.loads(l); yield j["ptok"],j["otok"],j["dec_ms"],j["pf_ms"]
def van(c):
for l in open(c+"/engine-slice.log",errors="replace"):
m=re.search(r"prompt (\d+) tokens = (\d+) reused \+ (\d+) read in ([\d.]+) ms.*?(\d+) generated in ([\d.]+) ms",l)
if m: yield int(m.group(1)),int(m.group(5)),float(m.group(6)),float(m.group(4))
for task in ("nestng-crm","ttt"):
res={}
for arm,f in (("LEL",lel),("VANL",van)):
acc={b:[0,0,0,0] for b in B}
for c in cells(arm,task):
for p,o,d,pf in f(c):
for b in B:
if b[0]<=p<b[1]: a=acc[b];a[0]+=d;a[1]+=o;a[2]+=pf;a[3]+=1
res[arm]=acc
print(task)
TL=sum(a[0]+a[2] for a in res["LEL"].values())
for b in B:
l=res["LEL"][b];v=res["VANL"][b]
if l[3]==0: continue
lt=l[1]/l[0]*1e3 if l[0] else 0; vt=v[1]/v[0]*1e3 if v[0] else 0
print(" ctx %6d-%-8d LEL n=%3d decode+prefill share %5.1f%% dec tok/s %6.1f | VANL n=%3d tok/s %6.1f gap %+5.1f%% | ms/tok %5.2f vs %5.2f"%(b[0],b[1],l[3],100*(l[0]+l[2])/TL,lt,v[3],vt,100*(lt/vt-1) if vt else 0,1e3/lt if lt else 0,1e3/vt if vt else 0))
+33
View File
@@ -0,0 +1,33 @@
import re,json,glob,sys
root="/data/leleka-e2e/codex-compare/runs/main"
def lel(cell):
r=[]
for l in open(cell+"/engine-slice.log",errors="replace"):
if l.startswith("{") and '"ev":"request"' in l and '"comp":"engine"' in l:
j=json.loads(l)
r.append((j["otok"],j["dec_ms"],j["tier_vram_pct"],j["ptok"]-j["ctok"]))
return r
def van(cell):
hits=[];gen=[]
for l in open(cell+"/engine-slice.log",errors="replace"):
m=re.search(r"decode expert cache hit rate: [\d.]+% \((\d+) hits / (\d+) lookups\); (\d+) more.*?of all (\d+) routed",l)
if m: hits.append(100*int(m.group(1))/int(m.group(4)))
m=re.search(r"(\d+) generated in ([\d.]+) ms",l)
if m: gen.append((int(m.group(1)),float(m.group(2))))
return list(zip(gen,hits))
buckets=[(0,600),(600,2000),(2000,10**9)]
for task in ("nestng-crm","ttt"):
for arm in ("LEL","VANL"):
tot=0;acc={b:[0,0,0] for b in buckets} # time, time*hit, count
for cell in sorted([c for c in glob.glob(f"{root}/{arm}/{task}-r*") if not c.endswith(".out")]):
if arm=="LEL": rows=[(o,d,h) for o,d,h,_ in lel(cell)]
else: rows=[(g[0],g[1],h) for g,h in van(cell)]
for o,d,h in rows:
for b in buckets:
if b[0]<=o<b[1]:
acc[b][0]+=d;acc[b][1]+=d*h;acc[b][2]+=1
T=sum(a[0] for a in acc.values())
print(task,arm,"decode time %.0f s"%(T/1e3))
for b,a in acc.items():
if a[0]: print(" otok %5d-%-9d requests %3d time share %5.1f%% time-weighted vram-hit %.2f"%(b[0],b[1],a[2],100*a[0]/T,a[1]/a[0]))
print(" total time-weighted hit %.2f"%(sum(a[1] for a in acc.values())/T))