docs: cpu-service page (window attribution, register-built IQ3 single-token dot + vectorized scan: bitwise 353/353, +6.34% tok/s / -0.27 ms/round over 5 blocks; open cache neutral; pcie 0.35 negative; harness runs pcie 0.55)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-10-31 21:38:37 +01:00
co-authored by Claude Sonnet 5.5
parent 829036be71
commit a6fa596f62
+82
View File
@@ -0,0 +1,82 @@
# 5090 decode: CPU expert service inside the verify window (claude/cpu-service)
Date 2026-10-31. RTX 5090, Ryzen 9 9950X3D, frozen corpus, upstream ranked profile, 5 turns to ~245k, seed OFF, auto slots (12,192). Base = `main` 8c8c6725d. Labels: M measured in the run named, E estimate.
Follows [vram-footprint3-5090](vram-footprint3-5090.md) section 5 ("the ~3 ms window deficit is not a hit-rate deficit").
## 1. Result
| item | class | status | effect (paired, 5 rotated blocks) |
| --- | --- | --- | --- |
| register-built single-token IQ3_S / IQ3_XXS dot (`rust_iq::dot_single_iq3`) + vectorized finiteness scan of the group's CPU output (`all_finite`) | lossless, bitwise (353/353 rows) | **default ON** on the branch; `LELEKA_IQ_SINGLE=legacy` and `LELEKA_SINK_SCAN=legacy` restore main | tok/s **+6.34 %** (5/5 blocks, +3.8..+10.3), ms/round **-0.27** (5/5, -0.03..-0.41), ms/token -5.7 % |
| `LELEKA_OPEN_CACHE=on` (existing opt-in) on top | lossless, bitwise | stays opt-in | over the new path: +0.75 % tok/s (2/5 positive), ms/round -0.01: neutral |
| PCIe share 0.35 (vanilla's PcieAuto value) on top | placement | stays off, no gate run | over the new path: **-1.37 %** tok/s (2/5), ms/round **+0.43** (5/5 worse): negative |
Harness caveat found on the way: `scripts/e2e/run-e2e.sh` exports `LELEKA_ORIGINAL_SERVE_PCIE_FRAC=0.55` by default, so every harness A/B of ours (footprint2/3, this one, the baseline pair) ran PCIe share 0.55, not the product default 0.45 (`original_serve_residency.rs`). M (file read).
## 2. Attribution of the window deficit (before the change)
Per round, turns 3-5, the 9 base runs of `runs/footprint3-ab` (27 requests), from `DBG profile request` spans. M.
| span | ms/round | note |
| --- | ---: | --- |
| `window.verifier` | 12.00 | |
| `drv.doorbell_wait` (GPU reaches the next layer's router) | 8.15 | vanilla "GPU-reach wait" 8.5-9.0 (`runs/s1-decode/v-nsk-prof`) |
| host work in the 48 layer callbacks | 3.31 | vanilla "per-layer host" 1.24-1.48 incl. its CPU 1.10-1.33 |
| - `cpu.compute` (the two pool phases) | 1.99 | **~81 us per CPU expert** (window regression, 6,637 windows); vanilla 44 us (its PcieAuto line) |
| - `cpu.sink` minus compute and zero (the `any(!is_finite)` scan of rows x 10 x 2,560 floats, every layer) | 0.59 | 0.30 ms per window per row; vanilla has no such scan |
| - `cpu.open` (per-expert source scope) | 0.33 | |
| - `pool.spans` + `pool.publish_plan` + `pool.split` + `cpu.zero` | 0.39 | |
| `drv.sync_compute` (last layer + head) | 0.45 | |
Window-level regression (base windows; total = GPU wait + host): +81 us host per CPU expert but only +38 us on the window, because the GPU's own MoE work after the doorbell (~55 us a layer:
shared expert, VRAM experts) runs under the host's callback; +67 us per PCIe expert; +1.13 ms per extra row. So host time pays fully only on layers whose CPU work outlasts the GPU's.
Cause of the 81 us: `dot_single` (one token per expert, ~90 % of CPU experts) decoded every 32 weights into stack arrays (`decode` -> `decoded`, a store-forward stall per half and a runtime
format `match`) before loading them: 0.94-1.0 GB/s per core on the laptop i9-11900H against 3.4-3.7 GB/s for the same tree with the grid words placed with `_mm256_setr_epi32`
(`iq3_single_bench`, 48 experts past L3, gate+up 1,430 -> 400 us per expert per core). M (laptop).
## 3. Change
* `crates/native-cpu-expert/src/rust_iq.rs`: `dot_single_iq3::<21|18>`: the same byte layout (lane l = grid word l), the same `signs32` mask, the same per-half scale broadcast, the same two i32 accumulators,
per-block FMA and `hsum_ggml`; only the decode-to-register path changes. Test `iq3_single_trees_are_bitwise_equal` (random blocks, 8 activation magnitudes, both formats, bit compare).
* `crates/cuda-driver/src/original_verify_mapped.rs`: `all_finite`, the same predicate as a branch-free exponent fold (vectorizes; 4.3x faster on the laptop for 76,800 floats). Test against `is_finite` with all special values.
## 4. Identity, `runs/cpu-service-id` (job `cpu-service-id`, ends 2026-10-31T19:17Z)
Replay of `night5-long-256k` (5 requests, 48 forced tokens), static tier, 8,000 slots (7.3 % of entries on the CPU, 4.6 % PCIe), one test binary `dt/rt-cpuservice`:
| comparison (`q_pair`, 353 rows) | identical | different | flips |
| --- | ---: | ---: | ---: |
| legacy A/A | 353 | 0 | 0 |
| new A/A | 353 | 0 | 0 |
| new vs legacy (both arms) | 353 | 0 | 0 |
| open cache vs legacy (both arms) | 353 | 0 | 0 |
`q_tail_gate` PASS (all zeros) in each process. The paths did differ: `cpu.compute` 929 -> 587 ms (request 1, one CPU worker), replay decode 19.7-20.0 -> 22.8 tok/s. M.
## 5. Paired A/B, `runs/cpu-service-ab` (job `cpu-service-ab`, 20 VALID runs, one binary `dt/bin-cpuservice` = code bba658f20)
Blocks of four (cs-base, cs-new, cs-oc, cs-p35), order rotated, arms by environment only. M.
| arm | runs | all-turn tok/s (range, SD) | tokens/round T1..T5 | ms/round mean | windows 20+ of T3-5: total / host pool / GPU wait / CPU experts / PCIe experts |
| --- | ---: | --- | --- | ---: | --- |
| cs-base (= main) | 5 | 140.8 (139.2-141.8, 0.86 %) | 2.10 1.96 2.00 1.85 2.02 | 14.09 | 11.9-12.2 / 3.45-3.72 / 8.24-8.31 / 24.5-27.1 / 11.4-13.6 |
| cs-new | 5 | 149.7 (147.1-153.5, 1.57 %) | 2.02 2.24 2.17 1.87 2.03 | 13.82 | 11.5-11.8 / 2.40-2.70 / 8.82-9.00 / 25.5-28.6 / 11.8-14.7 |
| cs-oc | 5 | 150.8 (148.3-153.4, 1.43 %) | 2.02 2.24 2.18 1.96 2.02 | 13.81 | 11.4-11.8 / 2.35-2.59 / 8.86-9.09 |
| cs-p35 | 5 | 147.6 (146.5-148.5, 0.45 %) | 2.07 2.31 2.25 1.84 2.04 | 14.25 | 11.5-12.2 / 2.45-3.23 / 8.78-8.86 / 29-40 / 4.1-7.8 |
Reading it:
* Host time in the window fell by ~1.0 ms (pool 3.5 -> 2.5 per window; per round `cpu.compute` 1.9-2.1 -> 1.5-1.7, scan overhead ~0.95 -> ~0.25), but the GPU wait rose by ~0.6 ms: on many layers the
host now finishes before the GPU's own MoE work, which was hidden before. Net window -0.4 ms, round -0.27 ms (-1.9 %). M.
* The rest of the tok/s gain is tokens/round (1.99 -> 2.07 averaged over turns): with a cheaper CPU leg the adaptive window policy picks wider windows (rows per window 2.34-2.43 -> 2.42-2.63). The
greedy arithmetic is unchanged (section 4); the end-to-end text differs between runs of every arm (also between base runs) because window width and swap timing are timing-dependent policies.
ms/token: 7.08 -> 6.68 (-5.7 %). E for the causal split, M for the numbers.
* `LELEKA_OPEN_CACHE=on` is bitwise and saves ~0.05 ms of `cpu.open` per round: inside the noise. Not a default change from this result.
* PCIe 0.35 moves 5-8 PCIe experts a window to the CPU and is slower than 0.55 with the new kernel (+0.43 ms/round, 5/5): our PCIe leg is cheaper than vanilla's relative to its CPU. Not gated, not proposed.
## 6. What remains against vanilla (E, from the spans)
Window: ours 11.5-11.8 ms against vanilla 10.5-10.7. GPU reach is equal (8.4-9.0 both); the remaining ~1 ms is host work on CPU layers: `cpu.compute` 1.5-1.7 ms for ~26 experts
(~61 us each against vanilla's 44 us; the down projection, the per-group token quantization and two pool barriers per layer are the candidates, not attributed), `cpu.open` 0.3,
spans/publish/split 0.3, scan 0.25. Outside the window: draft round 1.4 against 0.9 ms, untouched here. The multi-token path (`dot_multi512_tn`, ~10 % of CPU experts) still decodes through stack arrays.