Files
leleka/docs/experiments/codex-compare-speed-gap.md
T

15 KiB

Codex compare: why Leleka decodes slower than vanilla Strata, and the ranked levers (RTX 5090, 2026-11-07)

Branch claude/speed-vs-strata-08143a. Phase 1 = analysis of existing logs, no new GPU run, no performance claim. Phase 2 (measurements) is in section 6 once it has data. Sources (server /data/leleka-e2e/): codex-compare/runs/main/{LEL,VAN,VANL}/stack-r{1,2,3}/engine.log (LEL: JSON request events of the engine; VAN/VANL: strata serve: prompt ... generated ... drafts accepted a of b lines), spd-gap/runs/main/{A,B,E,K*,KA*,KS*,P,T*,VANLP,VANL-noprof} (replay of the recorded VANL nestng-crm-r2 prompts), docs/ledger.md, docs/roofline.md, docs/experiments/codex-compare-5090-results.md (branch claude/codex-compare). Arms: LEL = release package leleka-0.1.0-17e372944279, VANL = vanilla 0.2.6 with route tail skip and CPU prefill share off (reference), VAN = vanilla shipped defaults (both on). Analysis scripts are not kept in Git (run over ssh from stdin; formulas below).

1. Where the time goes (all requests with prompt > 200 tokens of the 9 stack logs per arm, ttt + nestng-crm together)

Rounds of vanilla are estimated as generated - drafts accepted (one bonus token per window); LEL logs rounds itself.

metric LEL VANL (reference) VAN LEL vs VANL
requests (3 stacks) 531 246 271
decode tok/s (sum output / sum decode ms) 177.5 217 238 -18 %
tokens per round 3.22-3.34 2.92-3.00 2.91-3.02 +12 % (adaptive window)
ms per round 18.1-18.8 13.5-13.9 12.3-12.5 +36 %
prefill tok/s over uncached tokens 930-1050 1460-1560 1320-1660 -35 %
prefill share of request time 9.5 % 7.1 % 7.3 % +2.4 points
request time per output token, prefill + decode (ms) 0.59 + 5.63 = 6.22 0.36 + 4.61 = 4.97 0.33 + 4.20 = 4.53 gap 1.25 ms: decode 82 %, prefill 18 %

Reading: Leleka gets more tokens per round than vanilla (+12 %), but a round costs +5 ms. With vanilla's round time Leleka would be ~10 % faster than VANL. The whole gap is the time per round, plus a smaller prefill share.

Prefill latency by size of the uncached part (median ms): the fixed cost per request is about +200-300 ms, and large reads are 2x slower.

uncached tokens LEL VANL VAN share of LEL requests
< 64 430 268 210 19 %
64-256 530 292 251 31 %
256-1024 722 435 397 35 %
1024-4096 1002 715 695 11 %
>= 4096 4405 2184 2044 4 % (19 % of LEL prefill time)

2. Same prompts replayed (spd-gap; nestng-crm-r2 of VANL, first 30 requests, requests are identical across variants; dec_tps = output tokens / decode ms)

variant what dec tok/s tok/round ms/round VRAM / PCIe / CPU % of routed
VANL (vanilla, lossless) --spec 4 --spec-min-p 0.5 208.3 (2 runs equal) 2.95 14.2 hit 92.8 / 2.0 / 5.2
A ours shipped (adaptive window, floor 0) 183.8 3.55 19.3 90.2 / 3.0 / 6.7
B ours with vanilla's window (fixed 4, floor 0.5) 178.8 2.90 16.2 90.8 / 2.7 / 6.6
E A + our lossy tail skip 206.7 3.58 17.3 93.7 / 1.7 / 4.6
T45 E, repeat 205.8 3.59 17.4 94.0 / 1.6 / 4.4
KAa E + sm_120 ATTN_DAILY + GU_SWIGLU 209.7 3.51 16.7 93.6 / 1.7 / 4.7

Over requests 4-30 only (whole runs of 27 requests, n = 1-4 per variant, not a paired design): T45 family 207.8 / 210.1 / 213.3 / 209.0 (mean 210.1), K (all three sm_120 sets) 214.0 / 215.8 / 218.3 (216.0), KA 212.0 / 217.6 (214.8), KS (side mixer only) 208.3 / 210.5 (209.4), T30/T35/T40 (PCIe fraction) 204.0 / 206.8 / 207.2. So: ATTN_DAILY + GU_SWIGLU ~ +2.3 %; the side mixer adds nothing; the PCIe fraction 0.45 is not worse than 0.30-0.40. Run-to-run spread inside one variant is +-1.5 %: these are indications, not A/B results.

Step profile (P = ours with LELEKA_SERVE_PROFILE=1, vanilla STRATA_DECODE_TIMING=1; ms per window, GDN layers + QSA layers, 30 profile lines each):

step (ms/window) ours, miss-heavy (lines 1, 2, 7, 8, 26) vanilla, miss-heavy (lines 8, 9, 12, 22, 27) ours, quiet (16, 17) vanilla, quiet (17, 18)
total per window 21-26 16-17 12.0 10.7
waitB (GDN + QSA) 4.3-5.9 3.9-4.6 0.45 0.5
waitCPU (GDN + QSA) 3.1-4.0 0.4-1.3 0.8 0.2
PCIe group 0.6-0.9 0.3 0.4 0.1
VRAM hits 1.7-2.8 1.4-1.9 1.5 1.4

The windows differ by 5-9 ms only in states with misses, and almost all of it is waitCPU + PCIe group (+2.5 ms of 21 in a miss-heavy window, +0.6 ms in a quiet one) and a hit rate that is lower in ours (90.2 % against 92.8 % of the routed experts). Cache size: ours 12,192 expert slots (23.24 GiB), vanilla 12,575 (23.87 GiB, +3.1 %), vanilla leaves 389 MiB VRAM free (and warns); vanilla draft head over 106,299 tokens (212.9 MiB), ours the full 248,320-row head (ledger section 5). Draft + commit outside the window: ours about 2.5 ms/round (draft.finish 1.7, apply_pending 0.6, commit 0.4), vanilla 1.2 (draft 1.17 in its timing line); ledger section 5 measured +1.5 ms/round. The vanilla server drifts with uptime: 13.5-16 ms/round at 11-13 h, 10.1-11.7 after a fresh boot (codex-lossy-delta.md); every A/B must alternate inside one boot.

3. Ranked levers

Gain = estimated change of end-to-end tok/s on the Codex workload (contexts 30-120k), E = estimate from the numbers above, not measured as an A/B. Lossy = changes output; "placement-class" = changes which experts run on the GPU (GPU and CPU round differently), so output differs slightly without being a bug.

# lever expected gain risk class evidence
1 sm_120 sets ATTN_DAILY + GU_SWIGLU default on (the vanilla 0.1.50 defaults) +2-3 % (E from KA vs T45: 214.8 vs 210.1) low non-lossy: byte-identical in the probe and 243-row replay section 2
2 Remove the CPU/PCIe wait of the miss leg (waitCPU + PCIe group: why is the CPU-expert result late: pool wake/hand-off, per-layer dispatch, split rule with pcie_frac, CPU kernel speed per expert) +4-10 % (E: 1.0-3.1 ms of 19 ms/round; the quiet-state excess is already 0.6 ms) medium (host threading) non-lossy if the numerics of each expert stay (same device decides the rounding) step profile
3 Fewer misses: slots 12,192 -> 12,575 (headroom policy), adaptive tier timing, draft-head VRAM +2-6 % (E: miss rate 9.8 % -> 7.2 % removes up to a quarter of the miss leg) medium: VRAM headroom (vanilla warns at 389 MiB), OOM/paging risk placement-class (quality gate against control placement) slots, hit rates
4 Per-round draft + commit overhead (merge small graphs, fewer launches, cheaper chain step: 0.68 vs 0.42 ms, mtp_original_finite guards) +3-6 % (E: -1.3 ms of 19) medium non-lossy, bitwise (same kernels; draft vocabulary subset is a separate sub-lever, ledger: prompt-dependent -4 %..+19 %) ledger 5, profile
5 Prefill fixed latency per request (+200-300 ms per small tail; vanilla reads <= 64 tokens through verify windows) and 2x slower large reads +2-3 % (E: prefill share 9.5 % -> 7.1 %) medium tail through windows is a different kernel path: placement-class numerics; faster large chunks are bitwise section 1
6 Adaptive window policy: A vs B is +2.8 % net (+0.65 tokens per round for +3.1 ms); tune floor / ceiling (variants C, D of spd_replay_job never ran) +1-3 % (E) low non-lossy (exact speculative decoding) section 2
7 Route tail skip (lossy): E vs A +12.5 % (206.7 vs 183.8), vanilla VAN vs VANL +9.7 % real +10-12 %, shrinks lever 2 and 3 quality: rounds growth unknown (codex-compare rounds CV 20-30 %) lossy, experimental, stays off until the owner gate section 2
8 CPU prefill share (vanilla default, KL ~0.004) ~0 (VAN prefill share 7.3 % vs VANL 7.1 %) lossy section 1 - do not pursue

Total of the non-lossy levers 1, 2, 4, 5, 6 if additive: about +12-25 %; the gap to VANL is +22 % (217 / 177.5), to VAN +34 %. Lever 3 and 7 are the way past parity with vanilla's shipped defaults. The levers interact: tail skip removes most of the miss leg, so lever 2 and 3 are measured with tail skip off (the default).

4. Gates, per lever (AGENTS.md; nothing changes a default before its gate)

lever A/B quality / identity gate
1 switch on/off, same boot byte-identical outputs and R hashes on a full replay of a Codex session (all 56 requests of nestng-crm-r2, plus the earlier 243-row replay); then default on
2 switch on/off per-step output identical on a frozen tier (--adapt-every 0 and a frozen placement, because the adaptive tier is not reproducible run to run); a distribution comparison of the adaptive runs
3 slots / headroom / profile variants placement-class gate: deviation against the control placement not worse than between two control placements (>= 1000 rows), zero OOM/paging in the 256k run, VRAM free >= the policy floor
4 switch on/off greedy output and tensor identity (the kernels are the same); chain graph timing in the model-free probe first
5 switch on/off, tails of 1-64 / 64-256 tokens R hash identity for the unchanged path; the window-tail path under the placement-class gate
6 variants of floor/ceiling on the same replay identical greedy output (speculation is exact); tokens/round and ms/round reported
7 E against A on the replay + real Codex sessions the owner criterion: rounds growth <= speed gain in %, game playable, CRM 56/56; stays experimental until it passes

5. Measurement protocol for phase 2

  • Workload: the recorded VANL nestng-crm-r2 requests (proxy/rounds/NNNN.fwd.json.gz) through scripts/e2e/codex/compare/spd_replay_job.sh (server copy spd-gap/tools/spd_replay_job7.sh), whole cell (56 requests); requests 1-3 are warm-up and dropped.
  • Design: blocks of leleka up per variant, order A B B A A B ..., n >= 10 blocks per variant in one boot (uptime drift above), GPU lock and holder queue as for all jobs; the metric per block: dec tok/s, tok/round, ms/round, end-to-end tok/s (otok / (pf + dec)), tier %; paired difference per adjacent block pair with a 95 % CI.
  • Record per run: GPU, driver, CUDA, host, model digest (8f59b4aa... profile, model files), binary sha256 and commit, the switches, cache state (prefix cache and expert tier start state: engine restarted per block, prefix cache empty at start), token counts and the distributions (per-request dec tok/s).
  • Binary: lever 1 is a pure switch (LELEKA_SM120_ATTN_DAILY, LELEKA_SM120_GU_SWIGLU), so its paired A/B runs the same codex-compare release package on and off (sha256 in the job log); the default flip itself is a commit on the hexagonal head e4993d151 and needs one confirmation block pair on that head. Levers that change code (2, 4, 5) are measured as head build against head build with the same switch off.
  • Tools (this branch, scripts/e2e/codex/speed/): spd_ab_job.sh (holder job; variant names NAME.BLOCK, new variant L), replay_hash.py (adds out_sha per request), ab_report.py RUN_DIR BASE VAR (paired differences with 95 % t intervals and the identity count). Copies live in /data/leleka-e2e/spd-gap/tools/.

6. Phase 2 results

Not run yet: the GPU queue holds the hexagonal identity/A-B jobs (hx-abg1 running, hx-abc3..5, hx-id6, hx-abd1..5 behind it, ~30 min each) ahead of this program. Queued at the end of PRIORITY (2026-11-07 18:30 UTC): spd-l1a (blocks 1-5) and spd-l1b (blocks 6-10) = lever 1, A (shipped lossless) against L (A + ATTN_DAILY + GU_SWIGLU), 10 blocks per arm, 30 requests of the recorded cell per block, ~12 min per block. Read the result with python3 -I - RUN_DIR A L < scripts/e2e/codex/speed/ab_report.py on /data/leleka-e2e/spd-gap/runs/ab-l1. Smoke test of the report on three old block pairs (tail skip on, no hashes): L +1.9 % decode tok/s, CI -2.1..+6.0 % (n = 3, which is why n >= 10). Entries are added below, one per lever, as each paired A/B finishes.

Lever 1, interim (blocks 1-5 of 10, spd-l1a; spd-l1b was running, so no final numbers yet)

metric A L L - A (95 % CI)
decode tok/s 187.10 190.05 +1.6 % (-0.3..+3.4 %)
end-to-end tok/s 170.18 169.67 -0.3 % (-3.2..+2.6 %)
ms/round 19.60 19.21 -2.0 % (-6.6..+2.6 %)

n = 5 pairs: not significant, gain below the +2-3 % of the estimate. Identity gate cannot use two boots: out_sha is equal for only 2 of 30 requests even between two runs of the same arm (A.1 vs A.2, A.2 vs A.3; L.1 vs L.2: 3 of 30), because the adaptive tier / placement is not reproducible run to run (as codex-lossy-delta.md noted). So the byte-identity of lever 1 must be shown on a frozen placement (--adapt-every 0, static tier, one boot, switch toggled per request or two boots with the same frozen tier), not by this A/B; the A/B above is the speed record only. Queue order (orchestrator request 2026-11-07): hx-abg2..5 (cumulative refactor A/B) are on top of PRIORITY; the running spd-l1b was left to finish.

Lever 1, final speed result (10 pairs, spd-l1a + spd-l1b, 2026-11-08)

Release package leleka-0.1.0-17e372944279-5090, RTX 5090, VANL nestng-crm-r2, 30 requests per block (27 after the 3-request warm-up skip), engine restarted per block, order alternated, only the switch differs.

metric A (shipped lossless) L (+ ATTN_DAILY + GU_SWIGLU) L - A (95 % CI)
decode tok/s 186.58 190.03 +1.85 % (+0.97..+2.73 %)
end-to-end tok/s 168.87 170.07 +0.71 % (-1.01..+2.44 %)
tokens/round 3.66 3.63 -0.66 % (-3.13..+1.82 %)
ms/round 19.61 19.13 -2.46 % (-4.47..-0.46 %)
VRAM % of routed 90.37 90.34 -0.03 % (-0.27..+0.21 %)

Decode gain is real and small (+1.85 %, CI excludes zero), inside the +2-3 % estimate's lower end; it does not reach the end-to-end number (prefill is untouched; CI crosses zero). The cross-boot out_sha identity is 22 of 300 and is not the gate (A against A is as low, adaptive tier and window). Default stays off until the frozen-placement gate passes: spd-l1id (variants FA/FL = tier swaps off + fixed window 4, with and without the two sets; FA.1 vs FA.2 is the A/A floor, then FA.n vs FL.n must be byte-identical), output /data/leleka-e2e/spd-gap/runs/id-l1, queued on top of PRIORITY.

Lever 1, identity gate: HTTP replay cannot decide, teacher-forced harness used (2026-11-08)

spd-l1id (release package, leleka up, tier swaps off, fixed window 4, 30 requests, 4 boots FA.1 FL.1 FA.2 FL.2): out_sha equal for 10/30 (FA.1 vs FA.2), 10/30 (FL.1 vs FL.2), 11/30 (FA.1 vs FL.1), 9/30 (FA.2 vs FL.2). The A/A floor is as low as the A-vs-L pairs, so the live HTTP replay is not a deterministic probe even on a frozen tier and window (the remaining sources are not isolated: host-thread timing of the CPU/PCIe split, the persisted prefix-cache state between boots; the frozen tier also runs at 63 % VRAM hits, ~104 tok/s, so these four boots say nothing about speed). The gate is therefore the repository's teacher-forced harness (scripts/e2e/decode/draftround-id.sh, the 256k-class capture night5-long-256k, top-16 logprob rows, A/A floor inside each process): spd-l1id2, P1 = release kernels, P2 = P1 + ATTN_DAILY + GU_SWIGLU, test binary rt-dr2, output /data/leleka-e2e/spd-gap/runs/id-l1-tf.