Files
leleka/docs/serve-step-costs.md
T

6.1 KiB

Per-step host costs of the Original serve loop (claude/ms-trim)

Status: measurements and host-side trims, RTX 5090 server, jobs 901/902 (LELEKA_SERVE_PROFILE=1). Not a quality or throughput claim beyond the paired A/B rows below.

Method

  • LELEKA_SERVE_PROFILE=1 prints one DBG profile request: line per request. Besides the stack's spans it now carries the driver's host spans (drv.*, head.*, mtp.*; crates/cuda-driver/src/host_profile.rs) and the controller's (ctrl.*, round.verify_commit|emit|finish). Off, a span is one cached boolean test.
  • STRATA_VERIFY_PROFILE=1 now prints DBG verify-profile: per request: the GPU stage stamps of the window graphs (verify.cpp's profile_report, never wired before).
  • Bring-up DBG/eprintln! on the hot paths are all behind LELEKA_BRINGUP_TRACE or the profile switch (checked); three per-window env::var reads (LELEKA_TRACE_LOGPROBS, LELEKA_TRACE_RESIDUAL, LELEKA_TRACE_PLE) and STRATA_COMMIT_SYNC are read once now (microseconds, kept for hygiene).

Where a round goes (job 901, static residency, greedy corpus, 523 rounds, ms per round)

span ms note
round (round.verify_commit + round.finish) 49.8 1 / 50 ms = the decode rate
window (window.verifier) 47.4
- CPU pool compute (pool.cpu) 26.2 owner: claude/pool-zero-copy
- host spinning for the GPU's next doorbell (drv.doorbell_wait) 19.3 GPU critical path while the host is idle
- PCIe span lookup (pool.spans) 0.86 cached since this branch (0.06 once warm)
- split + plan publish + PLE rows + sampling history + stage + launch 0.37
- final GPU drain + head (drv.sync_compute, drv.head) 0.88 head validation scan 0.05
draft (draft.finish: first MTP graph 0.64, chain steps 0.98) 1.6 GPU-latency bound, one host sync per graph
commit wait + publish 0.5
emit, adapt (static), commit enqueue, controller < 0.05

GPU stage profile of one window (sum over the layers, ms): non-wait GPU work 12.3 (GDN 8.4, QSA 3.4, head 0.5; about 25 small kernels per layer, 0.26 ms per layer), waitB 48.8 (the PCIe copy-kernel stage of the layer, ~1.0 ms per layer for ~22 MB), waitA 1.6 (host split + plan publish), waitCPU 0.3. At pcie_frac 0.55 the PCIe staging, not the CPU pool (0.5 ms per layer), is the layer's critical path. SM clock while busy: median 2917 MHz, P1 (no clock problem).

Conclusion: the host work between GPU phases is < 1 ms of a 50 ms round; the rest is GPU latency (kernel count), the PCIe stage and the CPU pool.

Per request (ms)

span before after
lent-slot refill (prefill.refill) 48-50 (46 in the per-call span scan) 42 (21 enqueue with cached spans + 21 DMA wait); the DMA is 1.4 GB at ~34 GB/s, hidden only if nothing else uploads behind it
table clear of the suffix drafter (ctrl.begin_request, 262144-cell context) 1.0 0.0
canonical GDN intake (drv.canonical_gdn, 113 MB) 11.5 11.7 (H2D bound, single pass kept)
verifier assembly (decode.assemble) 61 unchanged (owner: claude/round-overhead)
prompt read (prefill.read) 520-570 for 60-100 token prompts unchanged (owner: claude/prefill-throughput)

Tokenizer: encode 1.0 Mtok/s (139K tokens in 130 ms), decode_bytes 0.06 us per token (examples/bench_encode.rs): not a cost. Token publication: one try_emit per token on a 16-slot channel, issued right after the commit is enqueued and before the draft: not a cost.

Changes (all greedy-neutral; controls in brackets)

  • PCIe / swap / refill source spans are looked up once per (layer, expert) and kept (LELEKA_SPAN_CACHE=off).
  • Suffix drafter clears the slots it claimed instead of the whole table (LELEKA_SUFFIX_RESET=full).
  • Lent-slot refill queued after the decode phase's intake uploads, on its own stream (LELEKA_REFILL_DEFER=on; EXPERIMENTAL, off by default: the end-of-prompt variant measured no gain, this one is unmeasured).
  • KAR PLE rows with pread (half the system calls), one write for the window PLE staging, one-pass canonical GDN intake.

Paired A/B (jobs 901, 902; RTX 5090, driver 595.99.02, CUDA 13.2, 6-prompt corpus x 2 passes, 128 new tokens, spec-min-p 0.5,

expert tier 2048 slots/layer, placeholder profile, KAR PLE, conversation cache on, 12 requests per arm; decode tok/s is the mean of the per-request rates of corpus 0-4, ttft the mean of all 10)

comparison (order) decode tok/s ttft ms corpus tokens
static tier: toggles off, on, on, off (901) 49.93, 50.03, 50.03, 49.91 766, 758, 751, 760 12/12 identical in every arm
adaptive tier: off, on, on, off (901) 65.80, 65.88, 65.43, 65.77 743, 737, 739, 739 placement differs per run (4/12 equal, as before)
head d777560 (rt-base2) against this branch (rt-ms5), static: base, new, new, base (902) 47.01*, 50.02, 50.03, 49.90 778, 750, 751, 771 new == base-2 12/12; base-1 differs from base-2 in corpus 4 at token 77 (a near tie flipping inside the base itself)
refill deferral, static: off, on, on, off (902) 50.07, 49.99, 50.01, 50.05 759, 756, 752, 758 12/12
chat template + adaptive tier: off, on, on, off (902) 66.60, 66.80, 66.50, 66.58 723, 723, 725, 723 -
sampled head + penalty window, chat (901) 50.13 (on) vs 49.97 (off) 734 vs 740 not comparable with greedy

(*) first arm after a long idle, an outlier of the base binary; the second base arm is 49.90.

Reading: the host trims move decode by 0.1-0.3 % (inside the arm-to-arm spread of 0.1 tok/s) and ttft by 8-20 ms. That is what the span table predicts: the per-round host work they remove is under 1 ms of 50 ms (the span cache converts 0.86 ms per round to 0.06 once every expert pair has been seen; 16 requests are not enough to warm 24,576 pairs).

pcie_frac probe (902, static tier, LELEKA_ORIGINAL_SERVE_PCIE_FRAC, owner claude/round-overhead): 0.55 gives 49.30 / 50.04 tok/s, 0.35 gives 56.40 / 57.04 (+14 %), 0.25 gives 53.87 / 54.96. Placement differs, so tokens do too. The GPU stage profile explains it: at 0.55 the PCIe copy-kernel stage (1.0 ms per layer) outlasts the CPU pool (0.5 ms per layer).