Speed program: per-request split of the real-session gap LEL vs VANL (no gateway cost: 85% decode, 16% prefill) and session_split.py

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-11-08 14:31:27 +01:00
co-authored by Claude Sonnet 5.5
parent b686f6ab75
commit ede9542fd9
2 changed files with 144 additions and 0 deletions
@@ -232,3 +232,32 @@ D (adaptive window with `spec_min_p` floor 0.5, `leleka reconfigure`) against sh
### Lever 3 (fewer misses), plan (2026-11-08)
`docs/experiments/vram-footprint-5090.md` already holds the footprint work (dense slab default on; decode reserve 130 MiB and the prompt-embedding alias are opt-in, about +250 slots together, against vanilla's 12,575; our 12,192 now). Free VRAM at idle after load is about 1,040 MiB. The paired test queued here (`spd-l3a`, `spd-l3b`, variant `G` = `leleka up --gpu-budget-gib 31`, +0.43 GiB, about +190 slots, free VRAM after load about 600 MiB against vanilla's 389) measures the upper bound of what ~+200 slots are worth without any code change. If the gain is under 1 % the slot route is closed except for the larger prompt-buffer carve-out (+250..450 slots, needs code).
### Where the real-session gap goes, per request (existing cells only, no new run; `scripts/e2e/codex/speed/session_split.py`, 2026-11-08)
Source: `codex-compare/runs/main/{LEL,VANL,VAN}/{nestng-crm,ttt}-r1..3`. Proxy time per request (`proxy/rounds.jsonl`, `t_end - t_start`) joined by order with the engine's own prefill and decode milliseconds (the cell's `engine_log_start_offset` slice of the stack `engine.log`; join checked: request counts equal in all 18 cells per arm). Proxy "tok/s" = output tokens / proxy time = the `decode tok/s` of `compare.md`.
| nestng-crm (3 cells per arm) | LEL | VANL | VAN | LEL - VANL |
| --- | ---: | ---: | ---: | ---: |
| requests | 162 | 186 | 214 | |
| output tokens per request | 1,351 | 1,217 | 1,114 | |
| uncached prompt tokens per request | 583 | 609 | 441 | |
| proxy time per request, ms | 8,297 | 6,055 | 5,064 | |
| of it engine prefill, ms | 726 | 431 | 354 | **+295** |
| of it engine decode, ms | 7,549 | 5,592 | 4,674 | |
| of it rest (gateway, tokenizer, HTTP, SSE, prefix-cache work), ms | 22 | 32 | 36 | **-10** |
| pause between requests (tool run + Codex), ms | 713 | 1,405 | 1,013 | trajectory, not engine |
| ms per output token, proxy | 6.14 | 4.97 | 4.54 | **+1.17** |
| ... prefill / decode / rest | 0.54 / 5.59 / 0.02 | 0.35 / 4.59 / 0.03 | 0.32 / 4.19 / 0.03 | **+0.19 / +1.00 / -0.01** |
| proxy tok/s (the 163 vs 201 of `compare.md`) | 162.8 | 201.0 | 220.1 | -19.0 % |
| engine decode tok/s | 178.9 | 217.7 | 238.4 | -17.8 % |
At LEL's own 1,351 output tokens per request the 1.17 ms/token gap is **about 1,580 ms per request: decode 1,350 ms (85 %), prefill 257 ms (16 %), gateway and the rest -13 ms (0 %)**. `ttt` is the same: 6.10 against 4.96 ms/token (+1.14 = prefill +0.13, decode +1.01, rest 0). The wall-clock of a cell also contains the pauses (LEL 38 s, VANL 86 s per CRM cell: the vanilla sessions ran heavier tool commands), which differ with the trajectory and are not the engine.
So the 19 % (proxy) against the replay's 11-12 % (`dec tok/s` 183.8 against 208.3) is not a gateway, proxy, prefix-cache, tokenizer or serialization cost: the "rest" is 22 ms per request against 32 for vanilla. Two things make the gap look smaller in the replay: it counts decode only (the real-session proxy number adds the prefill gap, 0.19 of 1.17 ms/token, about 3 points), and the replay's two arms differ from the sessions by +-4 % each (LEL 186 in the replay against 178.9 in the sessions; VANL 208 against 217.7), i.e. a different text and a vanilla that ran at a different uptime. The decode gap itself is flat over the context: engine decode tok/s by prompt size (LEL / VANL): 0-20k 178.4 / 218.3 (-18.3 %), 20-40k 183.3 / 221.1 (-17.1 %), 40-70k 177.8 / 214.1 (-17.0 %), 70-100k 173.5 / 215.0 (-19.3 %), > 100k 155.8 / 206.7 (-24.6 %, 9 requests).
Where the decode time goes (ms per round, phase 1): LEL 18.1-18.8, VANL 13.5-13.9: **+4.7 ms**. Our adaptive window pays +3.1 ms for +0.65 tokens per round (net +2.8 %, kept); the step-profile excess is `waitCPU` + `PCIe group` (+2.5 ms in miss-heavy windows, +0.6 in quiet ones, tied to the hit rate 90.2 % against 92.8 %), draft + commit outside the window +1.3 ms (full 248,320-row draft head against vanilla's 106,299-token subset), and +1.3 ms in quiet windows (12.0 against 10.7: kernels; the sm_120 sets of lever 1 took a part of it, +1.85 %).
Prefill: +295 ms per request at equal uncached tokens (726 against 431); by size: < 64 tokens 430 against 268 ms, 64-256 530 against 292, >= 4096 4,405 against 2,184 (4 % of requests, 19 % of the prefill time). The known cause is old code work, not a switch: `docs/prefill-throughput.md` "Remaining gap" (8192-token chunks 2,830-2,930 tok/s against the Original's 5,400-5,900; tails of <= 64 tokens read through verify windows in the Original).
What is available without lossy (E, none measured as an A/B yet beyond lever 1): lever 1 done (+1.85 % decode); lever 3 upper bound queued (`spd-l3a/b`: +190 slots); lever 4 (draft + commit, up to -1.3 ms of 18 = up to +7 % decode if all of it went, but the fused-commit graph measured neutral and the draft-vocabulary route is prompt-dependent and not bitwise); lever 5 (prefill: up to 16 % of the gap, code-level, placement-class numerics for the window tails). Nothing identified so far closes the 18 % without the lossy tail skip (+12.6 % decode, gate not passed).
+115
View File
@@ -0,0 +1,115 @@
#!/usr/bin/env python3
"""Per-request split of real Codex sessions of the codex-compare run (offline analysis, stdlib only; never part of serving).
session_split.py RUNS_ROOT VARIANT [VARIANT ...]
For every cell RUNS_ROOT/<VARIANT>/<task>-r<k> (tasks ttt and nestng-crm) the proxy log `proxy/rounds.jsonl` gives per request the wall time in the proxy (t_end - t_start),
the output tokens and the pause before the next request (tool execution + Codex); the engine log of the stack, sliced from `engine_log_start_offset` of the cell, gives the
engine's own prefill and decode milliseconds (LEL: JSON `request` events; vanilla: `strata serve: prompt N tokens = R reused + P read in X ms ..., G generated in Y ms` lines).
The two are joined by order. Printed per variant and task: mean ms per request of proxy time, prefill, decode, remainder (= proxy - prefill - decode: tokenizer, HTTP, prefix-cache
work, SSE, response end), pause between requests, and the same per output token.
"""
import glob
import json
import os
import re
import sys
VAN = re.compile(r"strata serve: prompt (\d+) tokens = (\d+) reused \+ (\d+) read in (\d+) ms.*?, (\d+) generated in (\d+) ms")
def engine_events(path, offset, variant, n):
out = []
with open(path, "rb") as f:
f.seek(offset)
for raw in f:
line = raw.decode("utf-8", "replace")
if variant == "LEL":
if '"ev":"request"' in line and '"comp":"engine"' in line:
j = json.loads(line)
out.append({"ptok": j["ptok"], "cached": j["ctok"], "otok": j["otok"], "pf": j["pf_ms"], "dec": j["dec_ms"]})
else:
m = VAN.search(line)
if m:
out.append({"ptok": int(m[1]) , "cached": int(m[2]), "otok": int(m[5]), "pf": float(m[4]), "dec": float(m[6])})
if len(out) >= n:
break
return out
def cell(d, variant):
rounds = [json.loads(l) for l in open(os.path.join(d, "proxy", "rounds.jsonl"))]
rounds = [r for r in rounds if r.get("path", "").endswith("/responses") and r.get("status") == 200]
info = json.load(open(os.path.join(d, "cell.json")))
rep = info["rep"]
stack = os.path.join(os.path.dirname(d), "stack-r%s" % rep)
ev = engine_events(os.path.join(stack, "engine.log"), info["engine_log_start_offset"], variant, len(rounds))
return rounds, ev, info
def buckets(root, variants):
"""Engine decode tok/s and prefill ms per request by prompt size (ptok, both tasks together), pause excluded."""
edges = [0, 20000, 40000, 70000, 100000, 10**9]
print("prompt tokens bucket | " + " | ".join("%s: n, dec tok/s, pf ms/req, uncached/req" % v for v in variants))
acc = {v: [dict(n=0, o=0, d=0.0, p=0.0, u=0) for _ in edges[:-1]] for v in variants}
for v in variants:
for d in sorted(glob.glob(os.path.join(root, v, "*-r[0-9]"))):
if not os.path.basename(d).startswith(("ttt", "nestng-crm")):
continue
rounds, ev, _ = cell(d, v)
if len(ev) != len(rounds):
continue
for e in ev:
if e["ptok"] < 200:
continue
for i in range(len(edges) - 1):
if edges[i] <= e["ptok"] < edges[i + 1]:
a = acc[v][i]
a["n"] += 1; a["o"] += e["otok"]; a["d"] += e["dec"]; a["p"] += e["pf"]; a["u"] += e["ptok"] - e["cached"]
for i in range(len(edges) - 1):
cols = []
for v in variants:
a = acc[v][i]
cols.append("%4d %6.1f %6.0f %6.0f" % (a["n"], a["o"] / a["d"] * 1e3 if a["d"] else 0, a["p"] / a["n"] if a["n"] else 0, a["u"] / a["n"] if a["n"] else 0))
print("%6d-%-9d | %s" % (edges[i], edges[i + 1], " | ".join(cols)))
def main():
if sys.argv[1] == "--buckets":
return buckets(sys.argv[2], sys.argv[3:])
root, variants = sys.argv[1], sys.argv[2:]
for v in variants:
for task in ("nestng-crm", "ttt"):
agg = dict(n=0, proxy=0.0, pf=0.0, dec=0.0, pause=0.0, otok=0, ptok=0, uncached=0, cells=0, mismatch=0, pausen=0, wall=0.0, first=0.0)
for d in sorted(glob.glob(os.path.join(root, v, task + "-r[0-9]"))):
rounds, ev, info = cell(d, v)
if len(ev) != len(rounds):
agg["mismatch"] += 1
continue
agg["cells"] += 1
agg["wall"] += info["wall_s"] * 1e3
agg["first"] += rounds[0]["t_start_ms"]
for i, (r, e) in enumerate(zip(rounds, ev)):
agg["n"] += 1
agg["proxy"] += r["t_end_ms"] - r["t_start_ms"]
agg["pf"] += e["pf"]
agg["dec"] += e["dec"]
agg["otok"] += r["resp"]["output_tokens"] if r.get("resp") else e["otok"]
agg["ptok"] += e["ptok"]
agg["uncached"] += e["ptok"] - e["cached"]
if i + 1 < len(rounds):
agg["pause"] += rounds[i + 1]["t_start_ms"] - r["t_end_ms"]
agg["pausen"] += 1
n = agg["n"]
if not n:
print(v, task, "no joined cells (order mismatch in %d)" % agg["mismatch"])
continue
rest = agg["proxy"] - agg["pf"] - agg["dec"]
print("%-5s %-10s cells %d requests %3d | per request ms: proxy %7.0f = prefill %6.0f + decode %6.0f + rest %5.0f | pause %6.0f | per cell: wall %5.0f s, model %5.0f s, pauses %5.0f s | out tok/req %5.1f, uncached/req %6.0f | ms/out tok: proxy %.2f pf %.2f dec %.2f rest %.2f | proxy tok/s %.1f, engine decode tok/s %.1f" % (
v, task, agg["cells"], n, agg["proxy"] / n, agg["pf"] / n, agg["dec"] / n, rest / n, agg["pause"] / max(agg["pausen"], 1),
agg["wall"] / agg["cells"] / 1e3, agg["proxy"] / agg["cells"] / 1e3, agg["pause"] / agg["cells"] / 1e3, agg["otok"] / n, agg["uncached"] / n,
agg["proxy"] / agg["otok"], agg["pf"] / agg["otok"], agg["dec"] / agg["otok"], rest / agg["otok"], agg["otok"] / agg["proxy"] * 1e3, agg["otok"] / agg["dec"] * 1e3))
if __name__ == "__main__":
main()