feat(optimizations): Luce Spark — calibrated hot/cold expert residency

Merged
DA
6mo ago
+2423-114

Adds optimizations/spark/, the placement + caching product layer on top of the merged hot/cold MoE offload engine (server/src/common/moe_hybrid_*), plus the single-graph hybrid-decode engine (commit 31ce93c) that makes offloaded laguna decode run at near all-GPU speed.

What Spark is

A 33B-total MoE only fires ~8 of 256 experts/token, but naive hot/cold offload still hits the CPU tier ~36% of the time if it keeps the wrong experts resident. Spark:

  1. Calibrates the hot set from the traffic you actually serve (replays real agent sessions, accumulates per-(layer,expert) routing → placement profile).
  2. Caches the per-session tail in a bounded ring of spare GPU slots (LRU swap), driving cold-misses down in fixed VRAM.
  3. Single-graph decode (new): runs the whole token in one fused graph so the offloaded path keeps near all-GPU throughput.

Single-graph hybrid decode engine (commit 31ce93c)

The laguna hybrid-offload decode was rebuilt to run the whole token in one fused graph (laguna_step_hybrid + build_laguna_moe_block_hybrid): the routed FFN is served from the hot expert stack via per-layer residency LUTs (batched into one H2D / one D2H), instead of 40 separate per-layer graphs. That removes ~3.2 ms/token of per-layer host glue — the real cap on the multi-graph fused path. Default-on under offload (DFLASH_LAGUNA_NO_SINGLE_GRAPH=1 to fall back). The bounded expert-cache swap is now async on cudaStreamPerThread with a pinned cold store (ggml_backend_cuda_host_buffer_type) so cold-tail re-fetch overlaps compute; shared storage, so qwen35moe benefits too.

Measured (RTX 3090, single-token decode)

Configtok/svs all-GPU
laguna all-resident118100% (96/96 bit-exact)
laguna true-60% residency97–101~85–92% (was 76)
qwen3.6-35B-A3B 60% offload (AR)98–106~92–99%

Calibration results (RTX 3090, Laguna-XS.2 Q4_K_M, held-out Claude Code sessions)

Configtok/s% all-GPUVRAM
All-GPU118100%18.8 GiB
Uniform 60%6656%10.6 GiB
Spark calibrated 60%8169%10.6 GiB
Spark + cache + single-graph97–101~85–92%14.6 GiB

Calibration: split by session (no leakage). Full tables in RESULTS.md.

Honest notes

  • The earlier "~0% cold-hit" figure was a counter bug (the fused branch never incremented the cold counter). Real cold-hit at true-60% is ~6–8%, capacity-bound: recency (LRU) is already at the Belady optimum, so eviction tuning can't beat it. The single-graph + async-pinned overlap hides that re-fetch under compute (that's the 76→~100 gain), it doesn't eliminate it.
  • Token-level expert prediction (transition / router-score / pre-gate) caps at ~53% recall@8 — the experts that newly fire are driven by the current token's hidden evolution, invisible to any prior-token signal. Draft-as-predictor (MoE-SpeQ style) is the open lever, documented as a follow-up.

Known follow-up (refactor debt)

laguna_step_hybrid / build_laguna_moe_block_hybrid currently duplicate ~150 lines of build_laguna_graph / build_laguna_layer / build_laguna_moe_block_full (path isolation while iterating). Unifying via a hybrid descriptor threaded through the existing builders is a clean follow-up to remove the drift risk.

🧙 Built with WOZCODE