mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #4936] [Engine] dsv41: route prompt tokens to resident experts only (no disk reads while a prompt is read), opt-in #2269
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#2269
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 @PhialsBasement on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4936
Area
[Engine] (speed, kernels, models, the server and API)
What do you want to do?
On a machine where most of the routed experts live on an NVMe drive, reading even a short prompt is limited by the drive, not the GPU. A few hundred tokens are enough to touch nearly every expert of every layer (6 of 384 per token, 40 layers), so the prompt read streams most of the model from disk. Measured on my machine (environment below), a fresh 1,239-token prompt took 22.8 s and read 58 GB from the NVMe at 2.1 to 3.0 GB/s, with the GPU 37 to 49% busy. The same happens for the new part of every agent turn.
I want an opt-in mode where prompt tokens pick their experts only among those already in VRAM, the RAM store or the page cache, so a prompt read needs no disk reads. The reply's tokens keep the model's own routing.
What do you do today instead?
Nothing that avoids the reads. Prompt Skip, the readers and readahead settings (
DS4_READERS=4,DS4_READAHEAD_MB=64here) shape the streaming; the floor stays at the drive's bandwidth times the expert bytes a prompt touches.Proposed behavior
feedandfeed_mark), each layer's router gets a selection bias: the expert'sgate_bias, minus 1e4 for an expert that is in none of VRAM (l.slot), the RAM store (store->find) or the page cache (in_ram).route_kerneluses the bias only to choose the top k; the weights come from the unbiased scores, renormalised over the chosen experts.layer_chunk) and the window path (layer, including its lookahead) both use it during a prompt read.flow_specqueues early reads only for resident experts.STRATA_DS4_PROMPT_RESIDENT=1, default off.Tradeoffs
Evidence so far
Strata 0.1.55 (
c62d5e3a), HIP build ofstrata-dsv41from source (system ROCm 7.2.4, gfx1201), RX 9070 XT 16 GB, Ryzen 7 5800X3D, 64 GB DDR4, PCIe 3.0 NVMe, CachyOS kernel 7.3.0-4, deepseek-v4.1-flash-ist-das-1.75bpw, 1M context.Speed, fresh prompts (unique text, nothing reused):
DS4_CHUNK_MIN=16Real OpenCode sessions, together with the conversation reuse in #4921: a new session in another project read its new part (513 tokens, 36,949 reused) in 5.1 s, where it took 26.0 s with the reuse alone; later turns of the kind read 145 tokens (37,308 reused) in 3.8 s.
Quality:
sudokufailed at the token limit), resident routing 12/13 (cron_nextfailed, an off-by-one-minute case for* * * * *). One problem flipped each way. That run had #4921's reuse on as well.TANGERINE-4471).Not run: CUDA, SYCL and Metal builds; Strata's C++ test suite; a KL or perplexity comparison against stock routing on the same prompts; repeated benchmark runs; long-context quality beyond the recall check.
The branch is ready to split into a PR once the scope is agreed.
@PhialsBasement commented on GitHub (Nov 2, 2026):
The implementation is on the same branch as #4921: https://github.com/PhialsBasement/Strata/tree/dsv41-kv-splice
Note: on that branch resident routing is on by default (
STRATA_DS4_PROMPT_RESIDENT=0turns it off); a PR would flip it to opt-in as proposed above. The window-path numbers in the table usedDS4_CHUNK_MIN=16for the 109-token row. Built and tested with HIP on gfx1201 only; build steps are in the #4921 comment.@PhialsBasement commented on GitHub (Nov 3, 2026):
Closing this: measured properly, the proposal damages quality far more than the tests here showed.
I scored it with
--scoreagainst full routing on 5,000 tokens (code, docs, English, multilingual, agent transcript), 6 experts:Banning non-resident experts changes the hidden state of every prompt token, and the KV cache built from it carries the error into everything after. The 12/13 coding suite and 3/3 recall test in the original post were far too coarse to catch it.
A small selection penalty does better: a non-resident expert's selection score is lowered by a constant, so it only loses near-ties, and the mixing weights stay the router's own. At 0.3 it reads within about 1 s of the ban, keeps code perplexity level with full routing (4.441 against 4.469), and also speeds up decode (6.98 to 10.80 tok/s here). It is on the branch as
DS4_TIE_PEN, with resident-only routing now off by default: https://github.com/PhialsBasement/Strata/tree/dsv41-kv-splice (commit 55b8ddd)@AlexGabbia commented on GitHub (Nov 7, 2026):
Independent measurements of the tie-penalty routing above (
DS4_TIE_PEN) on CUDA and Windows, on a 12 GB laptop, and a question for @PhialsBasement.I wrote the same change before I found this thread: a selection-only bonus for the experts held in VRAM or the RAM store, added to
gate.bias. The weights stay the router's own. The biased rows are rebuilt at each prompt and every 16 decode steps (STRATA_DS4_CACHE_ROUTE=<ram>[,<vram>], 64 lines, a local branch, not pushed). A bonus for the held experts and a penalty of the same size for the others pick the same top k, so this is the same proposal.Environment: Strata main
146df3c4(engine 0.1.58),strata-dsv41built with CUDA 13.0 for sm_120, Windows 11, RTX 5070 Ti Laptop 12 GB (PCIe 5.0 x8, 28 GB/s pinned), Core Ultra 9 275HX, 64 GB DDR5-5600, NVMe at 4.7 GB/s (1 MiB random reads), ISTA-DAS 2.00 bpw, 5 experts (Faster), 128K context. 282 to 322 experts are in VRAM and about 3,400 in the RAM store.Without the bonus, decode spends 83 of its 198 ms a token waiting for the SSD: 30 store misses a token (CLI, 4K prompt + 256 tokens, release engine).
Passed
Off: the
--scorerows are byte-identical to the release engine 0.1.58's (the same SHA-256 over 4,995 positions; the release engine run twice gives the same bytes).Quality, measured with
--scoreon data/quant_quality/v1 tokenized with the pack's tokenizer, against the same engine with the bonus off:For reference, Faster (5 experts) against Full (6) on the same set: KL 0.0172.
Decode, CLI, 4K prompt + 256 tokens, 3 runs each:
Agent turns,
--serve, 2 runs each. The test is a 4K-token start followed by 7 turns of 16 to 2,048 new tokens. Prompt reads of the 7 turns: 111 s off, 81 s at 0.1, 59 s at 0.2. A 256-token answer after them: 8.2, 11.8 and 14.6 tok/s.Not run: HIP, SYCL and Metal builds; task-level quality (coding suites, long answers);
--scoreat contexts above 8K.Question: do you plan a PR for
DS4_TIE_PEN? If you do, I will add these numbers there and drop mine. If not, I can open a small opt-in PR, crediting you for the idea and for the KL table above. If the maintainers prefer one name for this in both engines, it could be named like the Qwen engine'sSTRATA_ROUTE_PRIOR.@PhialsBasement commented on GitHub (Nov 7, 2026):
Thanks for the independent numbers. Matching KL at 0.3–0.4 on CUDA/Windows is more convincing than my single-machine run. Go ahead with the opt-in PR. On my branch it's tangled with #4921, and yours is already standalone.
One thing to consider, I run a two-tier version, DS4_TIE_PEN=0.3 for experts not resident anywhere plus DS4_TIE_PEN_RAM=0.1 for experts only in the RAM store, so VRAM-resident experts win ties over RAM ones too. Your , form looks like it already expresses this. It may be worth keeping the two values separate in the PR.