Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
11 KiB
CPU expert pool: thread trace (2026-11-12)
Question (stage 6b): the CPU leg of the expert path has a longer tail than vanilla (T=3, layers 0-15: p75/p90 117/182 us against 69/99; layers 16-47: 95/151 against 66/92). Is it the time per expert (the CPU kernel) or the pool (queue, wake, straggler)?
Tool: LELEKA_POOL_TIMING=layers (crates/native-cpu-expert/src/rust_pool/trace.rs, engine line leleka-serve pool-layer {json} per layer window, report scripts/e2e/codex/prefill/pool_layer_report.py). Off by default; the pool then reads no clock.
Run: pool-thread-trace-default-release-0ac612d2df74-d1-pt1-pt2 (release 0ac612d2df = 83bdd85bb4 + trace, owner default placement quota=no + PCIe 0.65, replay VANL/nestng-crm-r2, 30 requests; blocks D.1 without the trace, PT.1 and PT.2 with it). Results: /data/leleka-e2e/prefill-latency/runs/pool-thread-trace-default-release-0ac612d2df74-d1-pt1-pt2/.
Caveats
- The PT blocks carry an INVALID marker that is FALSE: the arm guard read
leleka-serve meta: configfromengine.log, but the engine log is a bounded tail and the trace lines (about 2.6 KB each) pushed the start of the log out (4,883 and 10,755 pool-layer lines are left, 15,638 together; the line is the START of the run). The config is proven by theengine environmentline ofup-foreground.txt(EXPERT_PER_LAYER=no, PCIE_FRAC=0.65) and by D.1 (same profile,meta: configexpert_per_layer=0 pcie_frac=0.65). The traced window is the tail of each replay. - Tracing costs time: replay wall (30 requests, sum
wall_s) D.1 263.7 s, PT.1 301.5 s, PT.2 284.5 s (+8..14 %; n = 1 each, no A/A: indicative). The cost is the one engine-log line per window, not the timers (two clock reads per task, 28-72 us tasks). Times inside the pool are valid; absolute round times of PT blocks are not comparable with D.
Result (T = 1..4 tokens, microseconds, p50)
The pool always has 48 tasks (3 x 16 threads: 15 workers + host), whatever the expert count; every thread takes exactly 3 tasks; wake (publication to a thread's first task, slowest thread) 0.7-1.3 us; publish 0.3, park 0.1, requant 0.4-0.6, pre/post 3-4 us.
| experts in window | windows | group wall p50 / p75 / p90 | m5 gate/up wall | m5 task | m6 down wall | m6 task | m5 tail (last - median thread) p50 / p90 |
|---|---|---|---|---|---|---|---|
| 1 | 916 | 82 / 90 / 97 | 58 | 15.3 | 20 | 5.3 | 9 / 14 |
| 2 | 581 | 159 / 171 / 185 | 111 | 30 | 40 | 11 | 17 / 27 |
| 3 | 185 | 236 / 250 / 270 | 162 | 45 | 70 | 21 | 23 / 41 |
| 4 | 62 | 306 / 337 / 360 | 215 | 71 | 101 | 31 | 19 / 52 |
| 5 | 29 | 382 / 411 / 425 | 240 | 69 | 127 | 39 | 32 / 56 |
Reading
- The group time is LINEAR in the number of experts: about 76-80 us per expert (82 -> 159 -> 236 -> 306 -> 382), with a fixed part of only about 5 us. The pool's own overhead (wake 1 us, publish/park under 1 us, requant 0.5 us) is under 10 % at one expert and under 3 % at four. It is not the queue and not the wake.
- What a window costs is the kernel time per task: 3 tasks per thread, 15.5 us per gate/up task for one expert (1.36 MB of IQ3_S for gate+up, about 28 KB per task: 1.8 GB/s per thread, about 29 GB/s for the pool) and 5.3 us per down task (about 34 GB/s). One expert (2.047 MB) costs about 76 us across 16 threads = about 27 GB/s. The gate/up phase is about 25 % slower per byte than the down phase. Whether this is the memory bus (sustained DDR bandwidth of the machine, the PCIe DMA reads the same pinned bank) or the IQ3_S dequantisation arithmetic needs a one-thread kernel microbenchmark; it is the open question.
- The straggler is the granularity of the tasks: tail (last thread minus median thread) is about 0.55-0.6 x the task time (9 us at 15 us tasks, 17 at 30, 23 at 45), and p90 reaches 14-55 us. With 3 tasks per thread the last claimed task of a thread can end one task later than the median.
gu_wait_doneis 10-23 us (p50). That is the only part of the pool that can be improved by the pool: 6-12 us per window at 1-2 experts, i.e. 5-10 % of the group. - Compared with vanilla (T=3: 69/99 and 66/92 us p75/p90): our windows with ONE expert take 90/97 us at p75/p90 (above vanilla's p75 of 66-69, level with its p90 of 92-99); with two or more experts we are above it by construction (linear in the expert count). The gap of stage 6b is therefore at least partly the NUMBER of CPU experts per window (placement, and our quota=no changes it), not the pool; to separate it from the per-expert kernel cost the vanilla trace must be split by expert count (it has the same per-layer-window grouping). The pool trace does not implicate the pool, so no vanilla strace is needed.
Candidate fixes (none applied; each needs a paired A/B and the quality gate)
- Finer tasks at the end of a phase (guided / halving chunk: 3 -> 5-6 tasks per thread, claim cost about 50 ns each): expected tail 17 -> about 9 us at two experts, 6-12 us per window; non-lossy (same arithmetic, same outputs), numerical identity by tensor compare.
- Gate/up kernel (58 us per expert against down 20 us for half the bytes): compare with the vanilla C++ kernel per task (Rust vs C++ were within 6 % in the earlier kernel bench), look at the activation quantisation shared by the 48 tasks and at prefetching the next task's rows.
- Fewer CPU experts per window (more VRAM slots, higher PCIe share) moves the cost out of this linear regime; the quota=no + PCIe 0.65 default is exactly this lever (about 10 % fewer non-resident experts).
Follow-up (orchestrator, 2026-11-12): kernel micro-benchmarks, no GPU
- The vanilla
STRATA_POOL_TRACElog (host-vanilla-tier-experts-per-layer-pool-trace, 153 MB) has NO timestamps (pool trace: layer L run n), so a per-expert time of the Original cannot be read from it; it gives counts only. Instead: the Original's C++ kernel is timed bykab time(resident against streamed) and our Rust twin bykernel_ab time; the Original pool is structurally the same as ours (pool.cpp phase_tasks= 3 tasks per thread; the Rust pool is its port), so the window time of the Original is the same function of the expert count unless the kernel or the memory differ. Existing C++ record (/data/leleka-e2e/runs/kernel-ab-317/t-18-20-r1.json, case IQ3_XXS/IQ4_NL, one row, one thread, pinned, 2.176 MB per expert): RESIDENT 211.6 us, STREAMED (67 MB over a 32 MB LLC) 217.7 us (+3 %): the one-thread kernel is arithmetic-bound (about 10 GB/s per thread, memory adds 3 %). The pool needs about 990 us of thread time per expert (16 threads x (3 x 15.3 us gate/up + 3 x 5.3 us down)): 4-5 times the one-thread kernel. Candidate causes: cold bank (TLB, DRAM latency of the first touch of each 2 MB expert), SMT/clock when 16 threads run, other busy threads. Decided by step 2. kernel_ab pool-window(crates/native-cpu-expert/examples/kernel_ab/cmd_pool_window.rs, test tooling): the real pool on a 4.4 GiB role-major bank of one verified case, HOT windows (same experts) against COLD windows (random experts), k = 1..4, workers 15 / 7 / 3. Stubscripts/e2e/codex/prefill/kernel/cpu-expert-kernel-resident-vs-streamed-and-pool-window-hot-vs-cold-iq3s.sh(CPU only, queued behind the KAR e2e; also runskab timeandkernel_ab timeon case 21-20 = IQ3_S + IQ4_NL). Reading: HOT about the same as COLD means compute/pool; COLD much above HOT means the memory system.- Finer tasks need no code:
LELEKA_POOL_TASKS_PER_THREAD(1..16, default 3) already exists and changes only the row-to-task split ("every row is computed by the same code whatever task holds it, so the output does not depend on it"). The same stub measures 6 and 1 in the pool bench; the identity (tensor compare of the pool output across the knob, then the 2057/1036 identity jobs) and the section delta in a group A/B follow if the bench shows a gain.
Result of the kernel/pool bench (stub 1, 2026-11-12, CPU only, Ryzen 9 9950X3D, case 21-20 = IQ3_S + IQ4_NL, one row)
/data/leleka-e2e/prefill-latency/runs/cpu-expert-kernel-resident-vs-streamed-and-pool-window-hot-vs-cold-iq3s/.
| window of k experts, 15 workers, p50 us | k=1 | k=2 | k=3 | k=4 |
|---|---|---|---|---|
| HOT (same experts, cache) | 63.7 | 129.3 | 191.5 | 243.8 |
| COLD (random experts of a 4.5 GiB bank) | 77.7 | 136.6 | 197.2 | 271.5 |
- Linear, about 63 us per expert, intercept about 0: the pool adds nothing per window.
LELEKA_POOL_TASKS_PER_THREAD1 / 3 / 6 gives the same wall (HOT k=1 66.6 / 63.7 / 66.5): finer tasks do not help. - Scaling in threads is perfect: thread time per expert is about 800 us at 4 (k=1: 199 us), 8 (103 us) and 16 threads (64 us). Not SMT, not the memory bus. HOT against COLD costs +14..35 us per window (mostly the down phase 13.7 -> 21 us).
- The Original's kernel, one thread, no pool (
kab time): 377 us RESIDENT / 395 us STREAMED (+5 %) for case 21-20-r1, 461 / 463 us for r3. Our pool path spends about 800 us of thread time per expert: about 2.1 x. The 2026-10-28 alternation record of case 18-20-r1 (IQ3_XXS) shows the same ratio (C++ 214 us, Rust twin 467 us, 60 runs each). The twinkernel_ab timeruns through DirectCpuPool(1) with a spinning worker on the same pinned CPU, so it is not an equivalent harness; a clean one-thread number (spin off) is queued (cpu-expert-kernel-one-thread-without-spin-and-window-amortisation-iq3s). parity-audit-5090.md row 9 says +6 % per CPU entry (job 980, 37 vs 35 us), which contradicts 63 us per expert here; that run most likely used larger groups.
Follow-up (2026-11-13): new CPU expert kernels in the real pool, base against new
Run cpu-expert-kernel-register-indices-pool-thread-trace-base-vs-new (blocks PTB.1, PTB.2 = release c1f15db2fa99 without the kernel commit 0c48c823e, PTK.1, PTK.2 = release bcbfa2c994 with it; owner default profile, replay VANL/nestng-crm-r2, 30 requests, LELEKA_POOL_TIMING=layers). The blocks cover different expert counts per window (placement changes between boots), so the table is by T and number of experts in the window (pool_layer_report.py --by-experts; p50, base = PTB.1/PTB.2, new = PTK.1/PTK.2, T = 2..4 pooled by eye, the columns agree within 1 us).
| experts in window | group wall p50 / p75 / p90 base (us) | new | m5 gate/up task p50 base -> new | m6 down task p50 |
|---|---|---|---|---|
| 1 | 82 / 89 / 97 (PTB.2: 88 / 98 / 104) | 70 / 86 / 95 | 15.2-15.7 -> 10.6-11.1 us | 5.2-5.4 -> 5.0-5.3 |
| 2 | 160 / 170 / 186 (PTB.2: 168 / 185 / 195) | 138-143 / 159-168 / 176-185 | 30.5-31.3 -> 24-25 | 11.0-11.5 -> 11.1-11.3 |
| 3 | 241 / 255 / 274 | 218-227 / 239-248 / 258-278 | 44.5-46 -> 36-39 | 18-22 -> 21-23 |
Reading: the gate/up task time fell by 30 % and the median window by 12-20 us (about 15 %), the down task did not change (the IQ4_NL accumulator change is on the single-row path; the pool decodes 2..5 rows, multi512). The tail did not follow: p75 -3..-9 us, p90 -2..-9 us. The earlier note that the tail comes from the number of CPU experts and from memory (COLD against HOT +25-80 us in the kernel bench) stands; the next steps are the 2048 B prefetch ahead of the Original and the multi-row down path. Group A/B at 243k: decode -0.34 % (CI -3.33..+2.65), A/A twin -0.43 % (docs/experiments/step-ledger.md).