diff --git a/docs/experiments/decode-tail-5090.md b/docs/experiments/decode-tail-5090.md index 34413a52..1d4376a9 100644 --- a/docs/experiments/decode-tail-5090.md +++ b/docs/experiments/decode-tail-5090.md @@ -1,81 +1,116 @@ -# 5090 decode at 247k: what the gap to vanilla Strata was (claude/decode-tail, STRA-245) - -Date 2026-10-29. RTX 5090 (32 GB), Ryzen 9 9950X3D, 121 GB RAM, driver 595.99, CUDA 13.2, Ubuntu 26.04; server `rnr5090`, one heavy job at a time under `/data/leleka-e2e/gpu.lock`, -the sealed 55 GB KAR memfd held by the holder. Ours = `leleka-inference` (original serve backend), pinned wave-1 build `bin-e2e4` unless a row says otherwise; vanilla = Strata 0.2.6 as -installed (`strata launch --model iq3_s --context 256k --kv int8`), tail skip as shipped. Greedy, 5-turn single conversation, 300 output tokens per turn, `--spec-min-p 0` for ours (the harness -shape; vanilla keeps its own 0.5), `--prefix-cache-mib auto`, prefill chunk 8192, 11,280 per-layer sized expert slots (11,365 global). - -Workload: `scripts/e2e/long_session.py` over the frozen corpus `/data/leleka-e2e/decode/corpus/src/crates` (782 `.rs` files, 14,132,376 chars, sha256 of the file list -`1152f45acaa9a62591e50d8f6807f50ce6fe1249db659cdb9e8e4a041ed119a7`); prompts 45.8k / 105k / 153k / 199k / 247k tokens. The earlier corpus (`~/work/leleka-head/src/crates`) no longer exists: every -245k number measured before 2026-10-29 00:40Z (including `s1-decode/o-def` and the STRA-258/259/260 tables) is unpaired with anything below. - -## 1. Headline - -| config (turns 1-4, mean of tokens over seconds) | runs | decode tok/s | -| --- | ---: | ---: | -| ours, seed ON (shipped default), upstream profile | 3 | 108.1 | -| ours, seed OFF, upstream profile | 3 | 137.2 | -| ours, seed OFF, global slot fill (11,365 slots) | 1 | 139.8 | -| vanilla, warm, tail skip as shipped (`v-def2`, `m-vanilla`) | 2 | 137.2, 127.5 | - -Per turn (tok/s): seed ON 107.0 108.6 109.6 110.1 / 110.3 103.3 104.0 113.9 / 107.0 108.5 108.9 107.2; seed OFF 134.6 139.6 148.7 131.6 / 134.2 138.4 151.0 126.3 / 132.6 138.1 140.5 134.3. -Vanilla: `v-def2` 139.2 160.7 138.6 117.4 123.4; `m-vanilla` 123.5 129.9 116.7 142.0 151.9 (the first vanilla arm after the reboot, `v-def`, ran on a cold page cache and is discarded). -Vanilla varies about 20 % run to run; ours about 3-8 % per turn. - -Turn 5 (the 247k prompt) is invalid for ours in every arm (16-41 tok/s): see section 4. - -## 2. The prompt-routing seed (placement class, NOT a default) - -`LELEKA_ORIGINAL_SERVE_SEED` (default on) swaps in, at the end of each prompt, the experts the prompt routed most. At 45k-247k prompt tokens it replaces the ranked profile's resident set by a worse one -(the prompt's top experts cover 9-10 % of the decode routing, `docs/original-serve.md`): - -| | seed ON | seed OFF | -| --- | ---: | ---: | -| VRAM share of routed entries | 80-85 % | 93-96 % | -| CPU / PCIe experts per window, windows 0-20 | ~240 / ~245 | 23-79 / 13-60 | -| ms per round | 16.9-20.0 | 13.4-15.4 | -| `apply_pending` / `begin_adaptation`, ms per round | 0.5 / 0.15 | 0.1 / 0.1 | - -Seed off and the cap `LELEKA_ORIGINAL_SERVE_SEED_MAX_ROWS` are experimental, off by default; they move experts between GPU and CPU, which round differently, so greedy ids are not bit-identical. -Quality gate: section 5 (pending). - -## 3. The harness profile was a placeholder - -`scripts/e2e/run-e2e.sh` defaulted `LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE` to `gpu-runs/baseline/profile.bin`, a bring-up placeholder in expert-id order (47 % overlap with the ranked upstream profile at 11,280 slots); -vanilla and the product deploy (`crates/deploy` `EXPERT_PROFILE_SHA256`) use the upstream `data/expert-profile.bin` (sha256 `8f59b4aa...388975baf`). With the seed ON the profile is overwritten anyway, so it made -no difference to the numbers above; with the seed off it is the starting set. The harness now defaults to the upstream file, records its digest, and refuses another one without `E2E_ALLOW_PROFILE_OVERRIDE=1`. -Every earlier ours-vs-vanilla 5090 measurement through `run-e2e.sh` used the placeholder (laptop runs used the upstream file). - -## 4. Turn 5: the PLE row cache evicts by scanning all of it - -`window.ple` (host time to gather the 16 PLE rows per verify row) is 0.1-0.2 ms per round in turns 1-3 and 9-11 s over the 153 rounds of turn 5 (about 70 ms per round); it shows as multiples of 53 ms. -Cause (code): `KarPleCache::gather` (`qwen_forward/kar_ple_cache.rs`) picks the victim of a missed row, once the 1,048,576-row device cache is full, with `entries.iter().filter(..).min_by_key(age)`: a scan of every entry, -once per missed row. The cache fills after about 1M distinct rows, i.e. around turn 4-5 of this session. Span check (`ple.read_rows` 0.2 s and `ple.device` 18 ms of the 10.8 s) and the memory sampler (swap, IO pressure, -direct reclaim flat; vanilla equally full at turn 5: anon 54.7 GB, MemAvailable 9 GB) rule the rest out; a prefix cache of 3000 MiB instead of 5.7 GiB does not change it. Vanilla keeps PLE in RAM and has no such structure. -The fix is owned by `claude/ple-stall`. Also `assign_slots` (prefill) collects every entry into a Vec per chunk once the cache is full. - -## 5. Quality gate, engine-commit A/B, greedy identity - -Pending at the time of writing; see the result sections appended below. - -## 6. Commits on claude/decode-tail - -| commit | change | class | -| --- | --- | --- | -| 286c2538, ea657e3e | `validate_snapshot` memo (the MTP ring snapshot was scanned page by page about 7 times per round); `LELEKA_MTP_SNAPSHOT_MEMO=off` control | lossless | -| ee4f2617 | chunked persistent page list for the ring snapshot (the per-round snapshot cloned 65,536 page Rcs at 256k) | lossless | -| 1c5a6c73 | profile spans in `begin_adaptation` | instrumentation | -| 0a3cda37 | `choose_swaps` selects instead of sorting (same swaps, same order; unit test against the kept reference) | lossless | -| bb47b296 | adaptive planning/queueing runs after the draft launch (`LELEKA_SERVE_ADAPT_DEFER=off` control) | lossless (same decisions, same order) | -| 5ef2c6eb, 359b4b5a | `LELEKA_ORIGINAL_SERVE_SEED_MAX_ROWS` (experimental, default 0) | placement | -| 69db3ab2, c84fcdcd | harness: upstream profile + digest guard; `long_session.py` refuses an empty/short corpus and records the corpus digest | tooling | -| 6fd2e897 | PLE cache profile spans | instrumentation | - -Per-round host cost before (o-def profile, seed ON, 245k): `apply_pending` 0.50 ms, `begin_adaptation` 0.15, `draft.launch` 0.23, `mtp.finish_ring` 0.14, `draft.finish` 1.49 of which the GPU chain steps ~1.1; -with the seed off `apply_pending` and `begin_adaptation` fall to about 0.1 ms each (fewer swaps). - -## 7. Not verified - -- No quality gate for the seed change yet; single-turn greedy identity of the engine commits not yet run (section 5). -- Vanilla was run with its shipped route tail skip (lossy); the skip-off pair `v-nsk` was dropped for GPU time. -- Per-commit engine A/B has no result yet; the micro numbers (e.g. `choose_swaps` 580 -> 480 us on the laptop) are not 5090 evidence. +# 5090 decode at 247k: what the gap to vanilla Strata was (claude/decode-tail, STRA-245) + +Date 2026-10-29. RTX 5090 (32 GB), Ryzen 9 9950X3D, 121 GB RAM, driver 595.99, CUDA 13.2, Ubuntu 26.04; server `rnr5090`, one heavy job at a time under `/data/leleka-e2e/gpu.lock`, +the sealed 55 GB KAR memfd held by the holder. Ours = `leleka-inference` (original serve backend), pinned wave-1 build `bin-e2e4` unless a row says otherwise; vanilla = Strata 0.2.6 as +installed (`strata launch --model iq3_s --context 256k --kv int8`), tail skip as shipped. Greedy, 5-turn single conversation, 300 output tokens per turn, `--spec-min-p 0` for ours (the harness +shape; vanilla keeps its own 0.5), `--prefix-cache-mib auto`, prefill chunk 8192, 11,280 per-layer sized expert slots (11,365 global). + +Workload: `scripts/e2e/long_session.py` over the frozen corpus `/data/leleka-e2e/decode/corpus/src/crates` (782 `.rs` files, 14,132,376 chars, sha256 of the file list +`1152f45acaa9a62591e50d8f6807f50ce6fe1249db659cdb9e8e4a041ed119a7`); prompts 45.8k / 105k / 153k / 199k / 247k tokens. The earlier corpus (`~/work/leleka-head/src/crates`) no longer exists: every +245k number measured before 2026-10-29 00:40Z (including `s1-decode/o-def` and the STRA-258/259/260 tables) is unpaired with anything below. + +## 1. Headline + +| config (turns 1-4, mean of tokens over seconds) | runs | decode tok/s | +| --- | ---: | ---: | +| ours, seed ON (shipped default), upstream profile | 3 | 108.1 | +| ours, seed OFF, upstream profile | 3 | 137.2 | +| ours, seed OFF, global slot fill (11,365 slots) | 1 | 139.8 | +| vanilla, warm, tail skip as shipped (`v-def2`, `m-vanilla`) | 2 | 137.2, 127.5 | + +Per turn (tok/s): seed ON 107.0 108.6 109.6 110.1 / 110.3 103.3 104.0 113.9 / 107.0 108.5 108.9 107.2; seed OFF 134.6 139.6 148.7 131.6 / 134.2 138.4 151.0 126.3 / 132.6 138.1 140.5 134.3. +Vanilla: `v-def2` 139.2 160.7 138.6 117.4 123.4; `m-vanilla` 123.5 129.9 116.7 142.0 151.9 (the first vanilla arm after the reboot, `v-def`, ran on a cold page cache and is discarded). +Vanilla varies about 20 % run to run; ours about 3-8 % per turn. + +Turn 5 (the 247k prompt) is invalid for ours in every arm without the PLE fix (16-41 tok/s): see section 4. With the fix (`plefix-noseed`, seed off, one run) all five turns are valid: +125.9 134.4 139.9 134.9 **131.8** tok/s, 133.2 over the five turns (tokens over seconds), against vanilla 134.2 (`v-def2`) and 131.6 (`m-vanilla`) over the same five turns. Ours with the seed on and the +fix was not measured; with the seed on, turns 1-4 are 108.1 (above), the whole difference to vanilla there is the seed. + +## 2. The prompt-routing seed (placement class, NOT a default) + +`LELEKA_ORIGINAL_SERVE_SEED` (default on) swaps in, at the end of each prompt, the experts the prompt routed most. At 45k-247k prompt tokens it replaces the ranked profile's resident set by a worse one +(the prompt's top experts cover 9-10 % of the decode routing, `docs/original-serve.md`): + +| | seed ON | seed OFF | +| --- | ---: | ---: | +| VRAM share of routed entries | 80-85 % | 93-96 % | +| CPU / PCIe experts per window, windows 0-20 | ~240 / ~245 | 23-79 / 13-60 | +| ms per round | 16.9-20.0 | 13.4-15.4 | +| `apply_pending` / `begin_adaptation`, ms per round | 0.5 / 0.15 | 0.1 / 0.1 | + +Seed off and the cap `LELEKA_ORIGINAL_SERVE_SEED_MAX_ROWS` are experimental, off by default; they move experts between GPU and CPU, which round differently, so greedy ids are not bit-identical. +Quality gate: section 5 (pending). + +## 3. The harness profile was a placeholder + +`scripts/e2e/run-e2e.sh` defaulted `LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE` to `gpu-runs/baseline/profile.bin`, a bring-up placeholder in expert-id order (47 % overlap with the ranked upstream profile at 11,280 slots); +vanilla and the product deploy (`crates/deploy` `EXPERT_PROFILE_SHA256`) use the upstream `data/expert-profile.bin` (sha256 `8f59b4aa...388975baf`). With the seed ON the profile is overwritten anyway, so it made +no difference to the numbers above; with the seed off it is the starting set. The harness now defaults to the upstream file, records its digest, and refuses another one without `E2E_ALLOW_PROFILE_OVERRIDE=1`. +Every earlier ours-vs-vanilla 5090 measurement through `run-e2e.sh` used the placeholder (laptop runs used the upstream file). + +## 4. Turn 5: the PLE row cache evicts by scanning all of it + +`window.ple` (host time to gather the 16 PLE rows per verify row) is 0.1-0.2 ms per round in turns 1-3 and 9-11 s over the 153 rounds of turn 5 (about 70 ms per round); it shows as multiples of 53 ms. +Cause (code): `KarPleCache::gather` (`qwen_forward/kar_ple_cache.rs`) picks the victim of a missed row, once the 1,048,576-row device cache is full, with `entries.iter().filter(..).min_by_key(age)`: a scan of every entry, +once per missed row. The cache fills after about 1M distinct rows, i.e. around turn 4-5 of this session. Span check (`ple.read_rows` 0.2 s and `ple.device` 18 ms of the 10.8 s) and the memory sampler (swap, IO pressure, +direct reclaim flat; vanilla equally full at turn 5: anon 54.7 GB, MemAvailable 9 GB) rule the rest out; a prefix cache of 3000 MiB instead of 5.7 GiB does not change it. Vanilla keeps PLE in RAM and has no such structure. +Also `assign_slots` (prefill) collected every entry into a Vec per chunk once the cache is full. + +Fix (`claude/ple-stall` a73d0906, a recency queue instead of the scan; cherry-picked here as b5d4a0db): `ple-ab`, seed off, same binary otherwise (`G-noseed` against `plefix-noseed`, one run each): +turn 5 24.5 -> 131.8 tok/s, `window.ple` 9,907 ms -> 58 ms over the request (63 -> 0.39 ms per round), `round.run_window` 11,861 -> 1,933 ms; turns 1-4 unchanged (126.1 134.5 138.0 129.9 against +125.9 134.4 139.9 134.9). Greedy identity (`ple-id`, static tier, teacher-forced replay of night5-long-256k, 353 rows): plefix against the unfixed build 353/353 identical, 0 argmax flips (A/A also exact). +The `dt-eng3` arms (A, F: no fix) show the stall again in 3 of 4 arms (turn 5: 28.5, 22.0, 25.9 tok/s; `F-nodefer` happened not to hit it, 136.5): the stall depends on how many new trigrams the +generated text contains once the cache is full. + +## 5. Quality gate, engine-commit A/B, greedy identity + +**Seed quality gate** (`dt-q2`/`dt-q3`; teacher-forced replay of night5-long-256k, 5 requests, 48 forced decode tokens each, static tier, top-16 logprobs, `rt-E`): the A/A noise floor is exact +(353/353 and 345/345 identical rows). Seed on against seed off (292 common rows): 0 identical, d_top1 median 0.0026 / p99 0.2241 / max 0.5875, argmax flips 4 (1.4 %). Control, a bigger placement change +(placeholder profile, VRAM share 48 % instead of 90 %, against the upstream profile, both seed off; 295 common rows): p99 0.2363, max 0.4378, flips 6 (2.0 %). Against the criterion (p99 and max +<= 1.5x the control, flips <= 2.8 %) the seed change passes on 292 rows (0.224 <= 0.354, 0.588 <= 0.657, 1.4 % <= 2.8 %), but the row count is below the 1,000 the criterion asks for, so `dt-q4` +(MAX_NEW 240, three processes) repeats it with >= 1000 rows; see "dt-q4" below. The Original's own envelope (p99 <= 0.22, max <= 0.43, flips <= 2.8 %, measured on ~100-token prompts) is marginally exceeded +by both the seed (p99 0.224, max 0.59) and the control (p99 0.236): any placement change at this context exceeds it by the same amount. + +**Engine-commit A/B without the PLE fix (`dt-eng3`, seed off, 245k frozen corpus, turns 1-4 tok/s; one run per arm)**: base 406b40a8 (`A-noseed`) 124.2 134.8 141.2 130.5; all commits (`F-noseed`) +123.2 137.0 131.8 134.4; F without the deferral 125.2 132.6 141.3 126.4; F again 126.1 134.5 138.0 120.8; 131.1 tok/s over the 16 turns of the four arms: no end-to-end difference is resolvable +(the spread per turn is 3-8 %). The spans of the same runs resolve the host-side effect directly (ms per round, turns 1-4, 585-609 rounds per arm): + +| span | base | all commits | all commits, no deferral | +| --- | ---: | ---: | ---: | +| `mtp.finish_ring` (snapshot publish) | 0.090 | 0.003 | 0.002 | +| `draft.launch` | 0.127 | 0.041 | 0.034 | +| `round.draft_committed` | 1.790 | 1.664 / 1.696 | 1.701 | +| `round.adapt` + `adapt_deferred` | 0.108 | 0.092 / 0.085 | 0.082 | +| `round.apply_pending` | 0.157 | 0.278 / 0.255 | 0.169 | +| apply + adapt, together | 0.265 | 0.370 / 0.340 | 0.251 | +| `adapt.choose` / `adapt.queue` | - | 0.035 / 0.056 | 0.033 / 0.049 | + +The snapshot memo and the chunked page list remove about 0.18 ms of host time per round in `draft.launch` + `mtp.finish_ring` (draft_committed falls by 0.09-0.13 ms); at 256k the saving grows with the +context. The deferral does not pay: the 0.09 ms it moves into the draft's shadow comes back as 0.10 ms more `apply_pending`, because the swap copies start later and are the critical path; it is now +opt-in (`LELEKA_SERVE_ADAPT_DEFER=on`, 9b03de2b). `choose_swaps` is 0.035 ms per round (0.14 ms per adaptation): the selection rewrite is not worth more than that. + +**With the PLE fix on both sides (`dt-eng4`)**, base + a73d0906 (`P`) against decode-tail + a73d0906 (`Q`): pending, see below. +**Greedy identity of the engine commits (`dt-id2`)**: pending, see below. + +## 6. Commits on claude/decode-tail + +| commit | change | class | +| --- | --- | --- | +| 286c2538, ea657e3e | `validate_snapshot` memo (the MTP ring snapshot was scanned page by page about 7 times per round); `LELEKA_MTP_SNAPSHOT_MEMO=off` control | lossless | +| ee4f2617 | chunked persistent page list for the ring snapshot (the per-round snapshot cloned 65,536 page Rcs at 256k) | lossless | +| 1c5a6c73 | profile spans in `begin_adaptation` | instrumentation | +| 0a3cda37 | `choose_swaps` selects instead of sorting (same swaps, same order; unit test against the kept reference) | lossless | +| bb47b296, 9b03de2b | adaptive planning/queueing after the draft launch; opt-in since 9b03de2b (net loss, section 5) | lossless (same decisions, same order) | +| b5d4a0db | cherry-pick of claude/ple-stall a73d0906: PLE row cache evicts from a recency queue (turn-5 stall) | lossless (cache only decides slots) | +| 5ef2c6eb, 359b4b5a | `LELEKA_ORIGINAL_SERVE_SEED_MAX_ROWS` (experimental, default 0) | placement | +| 69db3ab2, c84fcdcd | harness: upstream profile + digest guard; `long_session.py` refuses an empty/short corpus and records the corpus digest | tooling | +| 6fd2e897 | PLE cache profile spans | instrumentation | + +Per-round host cost before (o-def profile, seed ON, 245k): `apply_pending` 0.50 ms, `begin_adaptation` 0.15, `draft.launch` 0.23, `mtp.finish_ring` 0.14, `draft.finish` 1.49 of which the GPU chain steps ~1.1; +with the seed off `apply_pending` and `begin_adaptation` fall to about 0.1 ms each (fewer swaps). + +## 7. Not verified + +- No quality gate for the seed change yet; single-turn greedy identity of the engine commits not yet run (section 5). +- Vanilla was run with its shipped route tail skip (lossy); the skip-off pair `v-nsk` was dropped for GPU time. +- Per-commit engine A/B has no result yet; the micro numbers (e.g. `choose_swaps` 580 -> 480 us on the laptop) are not 5090 evidence.