mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #1348] Foresight: fetching MoE experts before they're needed — measured on 2× 3090 (update: prefetch path built and correct, no decode gain yet; data, tools, help wanted) #545
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#545
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @q8atnight on GitHub (Oct 7, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1348
Hi Niko and everyone, this is a data report and an invitation, not a PR. We spent a day measuring whether experts
could be brought into VRAM before a window asks for them, instead of the CPU computing the misses.
Short version:
(bus-limited there).
smaller cards.
verify/pool/residency core.
Code and tools to reproduce everything are on a public branch (see "Try it / help" at the end).
Setup. 2× RTX 3090 (x8 Gen4 each, ~13.5 GB/s), Ryzen 3950X, 121 GB DDR4. unsloth UD-Q4_K_XL, v0.1.40.1,
--layer-split 24 --pipeline-windows 2, locked-RAM arena, 12,779 slots (~52 % of experts),--spec 4.After tuning
--pcie-frac 0.2 --spec-min-p 0.7(+16 % decode vs 0.5/0.5 here; more PCIe share was monotonicallyslower, −17…−32 % at 1.0), real agentic-coding chats run at ~95-110 t/s with a 94-96 % hit rate.
1. The price of a miss is linear and sizeable. Shrinking the cache via
--vram-reserve-mibwithSTRATA_DECODE_TIMING=1:That's +2.78 ms per window per extra miss per layer-window, i.e. ~0.058 ms per distinct missed expert, with a
zero-miss intercept of ~13.0 ms. On real coding windows (wider, T≈2.5) we see
1.57 misses per layer-window, so+75 %** headroom (22.8 → ~13 ms). There, though,"every miss arrives in time" would be worth up to +34 % decode on this box. At the 6,363-slot point (≈ the share
of experts a single 24 GB card holds) the same arithmetic gives **
the x8 bus can't carry every miss in time, so a real gain would be well below that ceiling.
2. Misses are predictable, two ways. Both were measured offline on real sessions:
--dump-routing, plus a smallenv-gated dump of each pool call's
x_frows (BF16) and ids. Recomputing W_L·x_f reproduces the engine's own top-10at 99.92 %. The simulator below replays the routing through a mimic of the static profile plus your adapt rules; it
matches the engine's hit rate (~94 %) and also reproduces that changing
--adapt-every/--adapt-swapsdoesn'tmove it.
Recency ring (cross-window): reserve 16 slots per layer (taken from the coldest residents) that hold experts
that just missed, refreshed every window. This gives −24 % distinct misses if a copy lands by the next window. It is
very lag-sensitive: −27 / −18 / −12 / −3.5 % at a landing delay of 1 / 2 / 3 / 5 windows. Making adapt itself more
aggressive (usage ≥ 1, gain 0-1, every window) only reaches −3…−8 %. It has to be a separate recency tier.
Router-ahead, zero-shot (within a window, Fate-style): apply layer L+k's
ffn_gate_inpto layer L'sx_f.Token recall of the 10 routed experts:
Fetching only the best-ranked non-resident candidates within what an x8 link moves in 1-3 layers covers
~25-35 % of misses, mostly different ones from the ring's.
A small trained residual predictor (~200K params per layer) did not transfer across sessions (it helped layer 3,
hurt layers 10-42), so we'd stay with the router-ahead zero-shot predictor.
Combined estimate: ~−45 % misses ≈ +12-13 % decode on this box.
3. We built the ring on the adapt path, and it didn't work. We built the ring inside the serve
adapt()(an envswitch, off by default, 6/6 answers identical with it off). Live result: misses −2…−10 %, speed within noise. Our
reading: under
--pipeline-windows 2,pl_adapt→adapt_fence→ copy →pl_applycommit →exch_evreleasemeans one ring update per ~4 windows that lands 2-3 windows late. In the serial loop the ring does cut misses −21 %,
as simulated, but per-window adapting costs ~2.5 ms per window there, so decode drops 13 %.
What we think a working version needs:
pre[l]graph that applies the next 1-3 routers tomixed_rows and publishestop-k with the doorbell (the host is far too slow: ~430 M MAC per window);
known;
host_res) and the GPU plan (d_res) see identically within a window.This is the part we're least sure how to do safely in your pipeline.
Questions:
plans you already have for the expert tier?
would you rather double-buffer
d_resper window?x_fdump switch (~25 lines indrive_pool_multi),the trace-replay simulator and the gate scripts, and can open a small PR for the dump switch or share the branch.
Try it / help. Branch
q8atnight/Strata:foresight, based onv0.1.40.1 plus our layer-split ports. It has:
STRATA_FORESIGHT_DUMP);STRATA_FORESIGHT_RING, measured no gain on the adapt path, kept for comparison);tools/foresight/: router extraction, the trace-replay cache simulator, router-ahead scoring and the Scout trial,with a README.
Both switches are off by default and the build is gate-identical. The most useful contributions:
--vram-reserve-mib+STRATA_DECODE_TIMING=1, hitrate, router-ahead coverage. Single 24 GB / 32 GB cards and AMD would tell us where this pays most;
All numbers here come from one box and one user's real agentic-coding sessions. We're happy to rerun anything on our
2× 3090.
@q8atnight commented on GitHub (Oct 7, 2026):
Follow-up: we built the prefetch path ourselves. It's correct and it removes 21-39 % of the CPU misses, as our trace simulation predicted, but decode does not get faster on our box. Posting it so nobody repeats the same steps, and to correct the "+34 % headroom" in the title, which overstates the prize at our operating point.
What we built (branch
q8atnight/Strata:foresight, all off by default,tools/foresight/README.mdhas the details):STRATA_FS_SLOTS,_BUDGET,_ADMIT,_DEPTH);P.ptrpoints at the slot. No kernel changes, and the host plan stays the single source of truth;depthmore finished windows since a plan last pointed at it.Correctness. With the switches off, the deterministic gate gave 6/6 identical answers. With it on,
STRATA_FS_VERIFY=1(reads every landed slot back and compares it byte for byte) gave 19,633 ok, 0 mismatches.Speed (2× 3090, UD-Q4_K_XL, layer split,
--pipeline-windows 2, four prompts × 3 reps, a restart per setting):Why it doesn't pay, per
STRATA_DECODE_TIMING:What we think a winning version needs: clear all of a layer's misses so its CPU round trip disappears, and schedule copies into bus-idle time. With a layer split, for example, use the other card's link while one card computes its half. Boxes with more misses per layer (single 24 GB cards) sit where the per-miss price did hold in our test, so it may look better there. That's untested, and measurements from such setups would be welcome.
@Niko1221 commented on GitHub (Oct 8, 2026):
Thanks @q8atnight for the swap space, the verify mode and the honest follow-up. The three swap-space commits are in 0.1.41 with your authorship kept, off by default (
STRATA_FS_SLOTS).Two things on top. The router look-ahead we already had (
RouterLookahead, which only warmed file pages) now also feeds the slots: its next-layer predictions are copied into them (STRATA_FS_AHEAD, on whenever the swap space is on), so there is one prefetch design, not two. And the slot state sits behind a mutex now, since the pool thread and the look-ahead thread both use it.Correctness:
STRATA_FS_VERIFY=1on an RTX 5070 (Q2_0, Windows) read back 2,324 landed slots, 0 bad.Speed, 4 slots per layer, the cache giving up the VRAM they take, 6 interleaved pairs of whole engine runs, 200-token greedy answers, median decode tok/s of on / off (pairs faster): RTX 3060 + IQ3_XXS 0.95 with misses only (0/6), 0.91 with the look-ahead (0/6); Tesla P100 + IQ3_XXS 0.97 (2/6) and 1.00 (4/6), 16 slots 0.96 (0/6); RTX 5070 + Q2_0 0.98 (1/6). That is what you found: below about one miss per layer-window the CPU round trip stays and the smaller cache costs more than the slots return. So it stays opt-in. A single 24 GB card with several misses per layer-window is where it could pay, and we have none: if someone runs it there, the engine prints the counters (
foresight swap: ... served from the swap space, ... copies) at the end of each request.@q8atnight commented on GitHub (Oct 8, 2026):
Thanks for keeping the authorship, and for the
RouterLookaheadfeed on top — one prefetch design is the right shape, and the mutexwas a real hole: we hit the same "two threads, one slot table" corner ourselves when the pool thread and our dump
recorder overlapped.
Your rows match ours exactly. Every rig you measured sits below one miss per layer-window, and that is precisely where our live box also
sits: the swap space is correct and the misses drop 21–39 %, but decode stays flat because the cost is per
layer-with-any-CPU-expert, not per miss. Your "single 24 GB card with several misses per layer-window" is a class we DO have: our
elastic pair (https://github.com/Niko1221/Strata/pull/1461) runs a whole IQ3_S engine on one 24 GB card with the experts from RAM,
which is a many-misses box by construction. We will run stock 0.1.41 there —
STRATA_FS_SLOTS=4,STRATA_FS_VERIFY=1once, yourend-of-request counters, interleaved on/off pairs at greedy 200 tokens — and post the rows here in our next maintenance window.
One question about
STRATA_DBG_FEAT(the routing + hidden-state prefill hooks from6c51a295): is that meant as the on-ramp for acontent-aware predictor — predicting from the hidden state what the next layer will route to, rather than the previous layer's output?
Our Part-2 study (the dump + Scout replay described in this issue's follow-up) found the recency-style
predictors cap around +5–7 % decode and a content-aware predictor is where the open +25 % sits; the trained Scout we
tried didn't transfer across sessions, but a hidden-state predictor trained per model rather than per session is a
different animal. If the hooks are headed there, we have the dump format, ~60 GB of recorded real sessions, and the
replay tooling on the
foresightbranch to share.@q8atnight commented on GitHub (Oct 8, 2026):
Rows for the single-24 GB case, as promised. Stock v0.1.41 (
fb58e0db, no patches), one RTX 3090 (24 GB, PCIe 4.0 x8), IQ3_S (GSQ-RCO), experts from pinned RAM,--expert-cache auto --spec 4 --mtp --kv int8 --pcie-frac 0, no vision. Greedy, 200 tokens, three prompts (short code, short prose, ~8K-token code context), 2 reps per prompt per engine start, whole-engine restarts for every arm, on/off interleaved.STRATA_DECODE_TIMING=1for the miss counts.This card is in the class you asked for: decode hit rate 84–87 %, 3.0–3.8 CPU experts per layer-window (3.8–4.9 entries), vs ~0.85 on our 2-card box.
4 slots per layer (look-ahead on, the default), 4 interleaved pairs,
--vram-reserve-mib 1500:Median 0.947, 0/4. Hit rate 86.6 → 88.2 %, CPU experts per layer-window 3.04 → 2.85, but per-layer host time 7.16 → 8.64 ms and ms/window 24.2 → 25.9.
Counters at the end of one on-arm (cumulative over its 9 requests):
11065 experts served from the swap space, 24645 copies (19298 from the router look-ahead), 8082 not landed yet, 150709 no free slot, 99361 over budget.STRATA_FS_AHEAD=0is a real kill switch (0 from the router look-ahead,0 not landed yet) and it is the better setting here: 4 slots → 93.2 (≈ 0.99 of off, one start), more experts served from the slots (13,102 vs ~11,000) with fewer copies (22,298), "no free slot" 151K → 64K. So on this card the look-ahead's ~19K copies mostly crowd the 4 slots — 4 per layer is far too few for ~4 misses per window plus predictions.More slots, look-ahead off (
--vram-reserve-mib 3000for all arms, so the main cache is 7,508 slots and misses are higher):16 slots serve ~21K experts with ~10K "no free slot" (the slots are finally big enough), misses drop ~13 %, but decode still 0.97–0.98. Same picture as on our live box, just with more misses: the slots remove some of a layer's CPU experts, rarely all of them, so the per-layer CPU round trip stays and the copies cost a little on the GPU side.
STRATA_FS_VERIFY=1(4 slots, look-ahead on):verified 8566 ok / 0 BAD. Decode drops to 80 t/s with verify on, as expected for the read-back.One snag you may want to know: with
--expert-cache autoand the default reserve, turning the slots on made the FIRST request fail withverify: instantiate: out of memory(the cache had filled the card to ~50 MiB free; the slots' VRAM is apparently not counted when the cache is sized).--vram-reserve-mib 1500fixed it for 4 slots, 3000 for 16. A user flippingSTRATA_FS_SLOTSon a full card hits that before any speed question.Free RAM unchanged between arms (65.3–65.7 GB available). Prompt reads were from the conversation cache in these runs, so this says nothing about prefill.
So, short version: even at 3–4 misses per layer-window on a single 24 GB card, the swap space doesn't win in its current form (best 0.98–0.99 with the look-ahead off). If it is ever to pay, I think it has to clear whole layers of misses, not some of each — happy to run another variant on this card if you want to try one.
@MarsLuay commented on GitHub (Oct 13, 2026):
I measured the opt-in foresight swap path on my mixed RTX 3080 Ti 12 GB + Tesla V100 32 GB PCIe pair using Strata v0.1.43.1 CUDA 12. Model: Qwen3.8-Flash-Next GSQ-RCO IQ3_S; manual
--layer-split 28 --trim-stage-weights; no conversation cache or pipeline windows; 10,065-token prompts; 128 greedy output tokens; two measured requests after warm-up.Environment:
The two foresight-on requests reported:
The corresponding two-run K=28/no-foresight sample on the same release was 68.4 / 72.0 tok/s decode (mean 70.2), so this small sample was about +8%, but it is not a six-pair interleaved result.
Swap counters for the two long requests were:
Decode timing showed, respectively, 1.72 / 1.17 CPU experts per layer-window, 11.17 / 12.90 VRAM hits, and 0.33 / 0.29 PCIe reads. The V100 stage had about 27 GiB free for its cache, so this is not the same as the proposed single 24 GB card case; the result does show that the swap/verification path was correct on this mixed pair. No bad landed slots or request errors occurred.
@Niko1221 commented on GitHub (Oct 13, 2026):
Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.
If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.