mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #5391] [Engine] experts: a managed cold tier below the RAM budget (scope proposal) #3217
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#3217
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 @yeyeyeason on GitHub (Nov 6, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5391
Area
[Engine] (speed, kernels, models, the server and API)
What do you want to do?
A scope proposal before any code (per CONTRIBUTING.md): a managed cold tier for experts — today the experts the GPU does not hold are either copied into RAM (
--resident-budget-gib, the ranked "warm" tier) or left to the OS file cache (--mmap-experts/ GGUF-in-place), with nothing in between. When RAM cannot hold the rest of the experts, every cold expert read is un-prioritized, un-measured and un-managed. This proposal: make that remainder a first-class tier, ranked by the same expert profile the warm tier uses, with its own accounting and (later) prefetch.We follow the release notes' own vocabulary — the VRAM cache, the RAM copy and the file reads are the hot, warm and cold tiers. The first two exist; this is about the third.
Who needs it. Anyone whose model is bigger than RAM-plus-VRAM: a 32 GB PC running UD-Q4_K_XL (59 GiB of experts), a 96 GB PC running Q8_0 (128 GiB) or DeepSeek-V4.1 (2xx GB), and — the vivid case — #5365's 81 GB IQ3_S on 32 GB of RAM plus a 500 GB pagefile across three SATA SSDs. That user is running the cold tier through the Windows pagefile with no priority, no ranking and no visibility. The engine already knows which experts are hot (the profile), and already does ranked SSD reads elsewhere (
--ple-io direct); the cold tier is the missing third application of the same idea.The measured problem. On this machine (2x RTX 4060 Ti 16 GB, i5-10600KF, 96 GB RAM, Windows 11; SC117 Qwen3.8-Flash-Next IQ3_S and Unsloth UD-Q4_K_XL, temperature 0, frozen profile, engine-measured decode; RAM-constrained arms simulated by allocating and touching memory down to the target free RAM), pure mmap and a ranked warm tier differ by:
(1M-context rows on engine 0.1.56; re-checked on 0.1.57 / v0.2.11: +16% and +26% — the tier still wins, see "Relation to the 0.2.11 CPU-share change" below.)
The mechanism is visible in the engine's own per-arm logs: over the same request set, the pure-mmap UD-Q4_K_XL arm read 797 GB from the SSD while the 46 GiB warm-tier arm read 64 GB — the OS file cache re-reads the same cold experts over and over (12x the bytes for the same work), while the ranked tier reads each cold expert about once. That re-read factor is the waste a managed cold tier removes.
The reversal that makes this a placement-policy problem, not just a bigger-budget problem. The warm tier is not always right, and the engine has no way to say so today. At 1M context the KV cache's pinned RAM (~6.2 GiB, engine-logged) squeezes the page cache, and the tier wins; at 512K the same machine frees ~3.1 GiB back, the page cache covers the hot subset of a 28.5 GiB complement, and the tier loses (measured: 16 GB RAM + IQ3_S, 512K: mmap 24.5 vs tier 23.1 tok/s, −6%; the same scenario at 1M: tier +26%). The opposite failure exists too: UD-Q4_K_XL at 1M with a 13 GiB budget that covers only ~22% of the complement went −9% versus mmap — a pinned tier too small to matter steals RAM from the page cache serving the rest. So the value of a managed tier is a function of (complement size, free RAM, context length, budget) — four things the engine can see and the person cannot. A user who copies a 1M-tuned config to a 512K session, or vice versa, silently lands in the wrong regime in either direction.
Proposed shape (opt-in, engine-side, small first step).
--statsand Monitor already report VRAM-cache / RAM-resident / file reads; align them under hot / warm / cold so the placement story is one model. No behavior change.--resident-budget-gib's ranking applied below the RAM line, not a new policy.--stats//metrics, so a person can see which regime they are in — including "your budget is too small; mmap would serve you better."--resident-budget-gibfrom--max-context, free RAM and the complement size.Prefetch (profile-predicted reads ahead of the verify window) is deliberately out of the first step; the ranked read path and the accounting come first, with prefetch as a follow-up once the read pattern is measured.
Existing foundations this builds on.
--resident-budget-gibalready ranks and admits by the profile;--ple-io directalready does ranked SSD reads of the 28.8 GB PLE table (the I/O pattern exists); the GGUF-in-place file tier already reads experts from the files (the transport exists); the profile (--expert-profile,--expert-profile-save) already knows the hot set. The change is to extend ranking and accounting below the RAM line — not a new subsystem.Validation plan. Same-machine A/B, mmap vs budget, at 128K/512K/1M across the two RAM simulations and both models (the tables above are that data, per-request JSON retained); a second model family (DeepSeek-V4.1 2.00 bpw) as the extreme case is planned and named up front; quality unchanged (placement does not touch math); every arm's engine logs kept, failures included. The reversal scenarios are part of the validation matrix on purpose: a placement policy that cannot say "mmap is better here" is not done.
Relation to the 0.2.11 CPU-share change (measured, so it belongs here): 0.2.11's CPU/upload share for missed experts (measured speed, ceiling 0.95) speeds up the GPU-side miss path — on the same machine it moved DFlash2 decode +34% on code — but it does not help the disk-side miss path these arms live in: both cold-tier arms' recall decode dropped ~20% on 0.1.57 (16 GB arm: mmap 11.0→8.7, tier 13.9→10.1), and the tier's advantage held (+26%→+16%, +31%→+26%). The two mechanisms sit on different bottlenecks (PCIe/CPU vs SSD bandwidth) and are complementary, not competing. The 0.1.57 low-RAM recall regression is separately worth its own report once reproduced cleanly.
Not proposing: no default change, no Linux page-cache tricks, no multi-disk sharding in v1, no change to the warm tier's admission policy.
What do you do today instead?
Three bad options, all silent: (a)
--mmap-expertsand accept the re-read waste (the 797 GB arm); (b) a--resident-budget-gibguess that may be too small (the −9% arm) or sized for a context you are not running (the 512K reversal); (c) #5365's route — a giant pagefile and hope. None of them can see which regime they are in; the engine can.@yeyeyeason commented on GitHub (Nov 6, 2026):
Follow-up data (engine 0.1.56 → 0.1.57, five more experiment sets since the proposal)
The proposal's tables came from one machine (2x RTX 4060 Ti 16 GB, i5-10600KF, 96 GB RAM, Windows 11). Since then we ran five more sets on the same box, including the second engine line, and one correction to our own table.
1. Correction to the table above. The "full warm (60 GiB) +142%" row is a ceiling reference, not a cold-tier gain: budget 60 GiB ≥ the 59.1 GiB complement means every expert sits in RAM/VRAM with zero cold reads — it measures what memory capacity is worth, not what the tier earns. The cold-tier gains in the not-fitting regime are +22% (35 GiB budget) to +76% (46 GiB budget). We have annotated the local report accordingly.
2. The tier survives v0.2.11 (engine 0.1.57). Re-ran the 1M-context sponge arms on 0.1.57: the tier's recall advantage holds (+16% and +26%, vs +26% and +31% on 0.1.56). Both arms' recall decode dropped ~20% on the new engine (mmap 11.0→8.7, tier 13.9→10.1) — an engine-level change worth its own report once reproduced cleanly. The tier advantage itself is intact.
3. A bidirectional reversal the proposal predicted, measured. Halving the context (1M → 512K) frees ~3.1 GiB of pinned KV RAM back to the page cache, and the tier's advantage flips sign for IQ3_S at 16 GB (mmap 24.5 vs tier 23.1 tok/s, −6%) while growing for UD-Q4_K_XL at 32 GB (+26%). The tier's value is a function of (complement, free RAM, context, budget) — the four things the engine can see. A fixed budget cannot follow that; this is the case for context-aware budgeting.
4. The DeepSeek engine line replicates the tier's value and the under-sized-budget law. strata-dsv41 0.1.57, DeepSeek-V4.1-Flash 2.00 bpw (113.9 GiB routed experts + 110.6 GiB Engram), 128K, full 96 GB RAM, no simulation:
--ssd-cache 0(managed store off; pure file path)--ssd-cache 48(forced, undersized)Two laws from our Qwen data replicate on this line: the managed tier wins big when the complement far exceeds RAM (+29%), and an under-sized pinned tier is a negative asset (48 GiB forced < auto's sizing → −6% vs auto; the same shape as Qwen's −9% at 13 GiB for a 59 GiB complement). We also swept
--vram-experts0.30/0.50/0.70: every manual share landed below the engine's own auto placement (6.0/6.3/7.0 vs 8.1) — the engine's layer-level placement beats hand-picked ratios, one more argument for engine-side scheduling over person-side guessing.5. The read-path question, measured on the Qwen engine (phase 1). The engine already ships the unbuffered path (
open_direct,FILE_FLAG_NO_BUFFERING/O_DIRECT) with a heuristic (file_tier_unbuffered) choosing between buffered and direct. In the squeezed regime (16 GB free, 1 GiB budget, 1M context), the heuristic moved both arms to unbuffered, so we compared against the buffered arm from set (1) at 68.9 GiB free:STRATA_UNBUFFERED_LOAD=1)Byte saving ≈ speed gain. But this comes with the boundary condition the repo's own history records (#773: forced unbuffered in the no-budget mmap mode re-read 163-629 GB and halved speed — there the page cache IS the tier). Both paths have failure modes; the structural fix is a managed arena that reads each cold expert once (what dsv41's
ExpertStoredoes and what the Qwen engine's budget mode lacks below its pinned tier).What we propose to do with this (unchanged scope, sharpened)
--stats//metrics(no behavior change);src/dsv41/ds4_store.hpp'sExpertStore(arena + LRU/LFU + profile prefill) to the Qwen engine's budget mode, opt-in;Hardware reference for anyone re-verifying (from our box and the community): expert-share-in-VRAM ↔ speed tier is steep — all-experts-in-VRAM boxes land ~59-100 tok/s on DeepSeek 2.00 bpw while CPU-lane-bound boxes land 6-26. On this consumer box (dual-channel DDR4, one NVMe), 40+ tok/s on this model is a memory-bandwidth wall, not a software gap; the tier work raises the software floor (+29% measured) and the punch-hole/dedup path (next step) shrinks the SSD footprint.
All arms' per-request JSON and engine logs retained; failures included; quality unchanged everywhere (placement does not touch math).
@yeyeyeason commented on GitHub (Nov 7, 2026):
Follow-up: the punch experiment's fix — a persistent cold store (design + request for scope agreement)
Test A (the comment above) showed the missing piece precisely: the ExpertStore's arena is rebuilt from the GGUF at every start, so punched regions enter the arena as zeros and the model silently degrades (396 → 42). This comment proposes the missing piece and asks for scope agreement before any code.
The design in one line: let the arena's source of truth be a dedicated cold-store file (
cold-store.bin) instead of the GGUF, so the GGUF's expert bytes become removable duplicates.Mechanism (mapping the pieces that already exist in the repo):
Write side (one-time, offline). A small tool reads the model's GGUF expert extents (the ds4
tensors.txtmap already carries every expert tensor's file/offset/size) and writes them contiguously intocold-store.binbeside the pack, with a manifest (per-layer offsets, sha256 of every region, the source shards' sizes and mtimes). This ispunch_gguf.py's map reader with a writer instead of a puncher — the format is ours to define, ~200 lines.Read side (engine change, dsv41 first).
ExpertStore's startup fill gets one new source branch: ifcold-store.binexists and its manifest matches (shard sizes/mtimes unchanged, region hashes spot-checked), fill the arena from it; otherwise fill from the GGUF as today and log which source was used. Everything else — LRU/LFU, prefetch, stats — is untouched. The change is one read-source switch plus one validation pass, opt-in via the presence of the file (no new flag needed: a pack with a cold store uses it).Consistency guard (the protection chain, learned the hard way). Test A's silent degradation is exactly what the validation must prevent: the manifest records the punched state (which GGUF regions are holes) and the store's region hashes; at startup, a mismatch (file replaced, store truncated) refuses to load with a loud error — never zeros into the arena.
Punch side (then, and only then). With the cold store validated at startup,
punch_gguf.py's guard lifts for packs that carry a matchingcold-store.bin: the GGUF's expert regions are released (47.6 GiB measured in test A), the model restarts cleanly from the store.Why dsv41 first: the ExpertStore already exists there (measured +29% over the pure file path); the cold store completes its story (restart-safe + dedup) with one read-source branch. Porting to the Qwen engine then ships the whole pattern (arena + cold store + punch) as one coherent feature — the #5391 proposal's "managed cold tier" with its dedup payoff included.
Validation plan: round-trip on this box (DeepSeek 2.00 bpw): baseline → cold-store write → punch 47.6 GiB → restart → byte-identical answers to baseline (temperature 0) → decode within noise → restart again → same. Failures included; the marker/hash chain exercised at every step.
Not in scope: no default change for packs without a cold store; no Qwen engine change in the first PR; no multi-disk spread yet (the cold store is one file; spreading it is a follow-up).
Sequencing question for the maintainer: does this fit the #5391 direction as the first concrete PR (dsv41 read-source branch + the two tools), with the Qwen port as the second?
@yeyeyeason commented on GitHub (Nov 7, 2026):
The cold store is now validated end-to-end on real hardware
Following up on the design comment above: the whole scheme (tools + engine patch) is implemented and verified on this box (DeepSeek-V4.1-Flash 2.00 bpw, 2x RTX 4060 Ti, engine built from current main + the patch below).
The round-trip, measured:
The engine's own log line:
ds4: cold store active: reads served from cold-store.bin (46077 entries; misses read the GGUF)— the arena fills from the cold store while the GGUF's expert regions are holes. Answers are identical to the baseline.The three states we measured — each proves one part of the design:
record-punch(dual fingerprints)What exists now (all opt-in, default path unchanged):
cold_store.py(~300 lines, standalone):write(129.7 GiB store, 47,229 regions, per-region sha256, ~10 min),verify(hash + source fingerprint check),usage(what a start would decide),record-punch(record the post-punch shard fingerprints as accepted).cold-store.mapv2: the engine's binary map — 46,077(layer, expert, role)offsets plus per-shard dual fingerprints (original + punched), magic-checked, dims-checked against the model.src/dsv41/ds4_model.cu+ a small addition tods4_store.hpp):DS4_COLD_STORE=1opens the pack's cold-store.bin, validates the map, copies the per-role offset tables into the store's geometry, andstart_fillserves reads from the cold-store fd; misses fall back to the GGUF; fingerprint mismatch refuses loudly. No flag: nothing changes.Why we validated before proposing code: the first implementation had six real bugs, every one of which produced a plausible-looking but wrong system — an offset-gap sizing bug that swallowed 5.7 GiB of non-expert tail data into a fake region; a manifest without tensor identity (the engine could not map
(layer, expert, role)); the pack-vs-model directory confusion; mtime granularity (float seconds in the tool vstime_tintegers in the engine — a fingerprint that never matched); a null dereference afterstd::move; and a role-order mismatch (the engine'sparts = {w1, w3, w2}= gate/up/down vs the tool's w1/w2/w3, which produced NaN weights that looked like an engine bug). Three of the six only manifest as silent wrongness or a crash deep in startup — a paper design review would not have caught them.Ready for the PR if the direction fits: the engine patch +
cold_store.py+ the punch integration as one PR (dsv41 only, no default change), with this round-trip as the validation data. The Qwen-engine port of the whole pattern (arena + cold store + punch) follows the #5391 shape as the second step. We can also share the per-request JSON and engine logs for every stage above.@bahooo22 commented on GitHub (Nov 7, 2026):
Data point from a single-GPU hybrid build (Windows 11, 32 GiB RAM, RTX 3060 Ti 8 GiB, qwen35moe
KAT IQ4_XS, KV q4_0):
come from the OS file cache.
that the engine is not started at all.
--prefill 2048failsat
cudaHostAlloc(E.cpu_out)(out of memory), while--prefill 512runs; on IQ4_XS at 128k theengine holds 2.17 GiB VRAM free plus a 256 MiB super-chunk buffer.
warm (pinned) tier and the largest prompt chunk: 18 GiB gate - 16.34 GiB experts ~= 1.7 GiB for
KV, staging and the OS.
Per-tier accounting would already be useful here: today the only signals are the RAM gate and the
expert H2D counter.
@yeyeyeason commented on GitHub (Nov 7, 2026):
Thanks — this is a useful shape of machine for the tier work, and your framing ("the gap between the warm tier and the largest prompt chunk", not total RAM) matches what our measurements see.
A few numbers from our box that map onto yours (2x RTX 4060 Ti 16 GB, 96 GiB RAM, IQ3_S with the complement at 28.5 GiB; RAM-constrained arms simulated by holding RAM):
If you get a chance to measure the re-read factor on your build (bytes actually read from the SSD per session vs the 16.34 GiB the tier holds), that is the one number that would tell whether the file tier is thrashing on your workload — our Qwen-line measurements saw 12-22x re-reads in exactly that regime when the pinned tier under-covers.
@bahooo22 commented on GitHub (Nov 7, 2026):
Thanks — we measured it on our box, and the number is at the opposite end from your 12-22x.
Setup: RTX 3060 Ti 8 GiB, 32 GiB RAM, Qwen3.5-MoE 35B-A3B IQ4_XS, q4_0 KV, the 16.34 GiB arena, the q36 engine with super-chunk N=4 and FA. Three phases with
psutil(process tree plus per-disk counters): right after/health(the model is not loaded yet,lazy_load), after a warm request (model loaded), after a long run.Prefill took 66.1 s at 96k and 111.9 s at 128k.
So the file tier is not thrashing on our workload: the model is 18.5-19 GiB and fits the 32 GiB page cache, and after the load the experts come from RAM. Two consequences:
A note on the counters:
psutil.Process.io_counters().read_bytesdoes not see mmap reads (soft page faults do not increaseReadTransferCount) — it reported 0.35-0.53 MiB per run. For an mmap engine the per-disk counters are the ones to trust. Our numbers are warm (the page cache holds the model after the load); a cold run needs the standby list dropped with admin rights, which we have not done yet.The question stands: on a 32 GiB machine, is hole-punching the model file safe when the arena comes from a separate cold-store file that outlives restarts?