[GH-ISSUE #4936] [Engine] dsv41: route prompt tokens to resident experts only (no disk reads while a prompt is read), opt-in #2269

Closed
opened 2026-11-04 01:58:03 +07:00 by bsakaguchi · 4 comments
Owner

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=64 here) shape the streaming; the floor stays at the drive's bandwidth times the expert bytes a prompt touches.

Proposed behavior

  • While a prompt is read (feed and feed_mark), each layer's router gets a selection bias: the expert's gate_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_kernel uses the bias only to choose the top k; the weights come from the unbiased scores, renormalised over the chosen experts.
  • The chunked path (layer_chunk) and the window path (layer, including its lookahead) both use it during a prompt read. flow_spec queues early reads only for resident experts.
  • A reply's tokens route as trained.
  • When a layer has fewer than 2k resident experts, it routes as usual.
  • Opt-in: STRATA_DS4_PROMPT_RESIDENT=1, default off.

Tradeoffs

  • It changes answers: prompt tokens are processed with substitute experts where their top choice is on disk. Here about 4,900 of 15,360 experts are resident (474 in VRAM, the rest in the RAM store), the most-routed ones, so the substitutes are the next-best resident choices.
  • The effect depends on how much of the model is resident: more RAM or VRAM, fewer substitutions.
  • The host builds the bias per layer and chunk (a residency check for each of 384 experts and a 1.5 KB upload); not measured separately, inside the read times below.

Evidence so far

Strata 0.1.55 (c62d5e3a), HIP build of strata-dsv41 from 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):

Prompt Stock Resident routing
1,239 to 1,305 tokens 22.8 s, 58 GB read from the NVMe 8.2 s, 1.3 GB read, GPU 73% busy
81 tokens (window path) not measured 4.5 s, 0.4 GB read
109 tokens with DS4_CHUNK_MIN=16 not measured 3.6 s

Real 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:

  • My 13-problem hard coding suite (pass@1, thinking on, temperature 0.6, top_p 0.95, top_k 20, seed 1234, 16,384 max tokens), one run each: stock 12/13 (sudoku failed at the token limit), resident routing 12/13 (cron_next failed, an off-by-one-minute case for * * * * *). One problem flipped each way. That run had #4921's reuse on as well.
  • Recall: three facts buried in 11,441 to 11,777-token prompts of shuffled code, each prompt read fresh with resident routing: 3/3, exact strings (for example 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.

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=64` here) shape the streaming; the floor stays at the drive's bandwidth times the expert bytes a prompt touches. ### Proposed behavior - While a prompt is read (`feed` and `feed_mark`), each layer's router gets a selection bias: the expert's `gate_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_kernel` uses the bias only to choose the top k; the weights come from the unbiased scores, renormalised over the chosen experts. - The chunked path (`layer_chunk`) and the window path (`layer`, including its lookahead) both use it during a prompt read. `flow_spec` queues early reads only for resident experts. - A reply's tokens route as trained. - When a layer has fewer than 2k resident experts, it routes as usual. - Opt-in: `STRATA_DS4_PROMPT_RESIDENT=1`, default off. ### Tradeoffs - It changes answers: prompt tokens are processed with substitute experts where their top choice is on disk. Here about 4,900 of 15,360 experts are resident (474 in VRAM, the rest in the RAM store), the most-routed ones, so the substitutes are the next-best resident choices. - The effect depends on how much of the model is resident: more RAM or VRAM, fewer substitutions. - The host builds the bias per layer and chunk (a residency check for each of 384 experts and a 1.5 KB upload); not measured separately, inside the read times below. ### Evidence so far Strata 0.1.55 (c62d5e3a), HIP build of `strata-dsv41` from 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): | Prompt | Stock | Resident routing | |---|---|---| | 1,239 to 1,305 tokens | 22.8 s, 58 GB read from the NVMe | 8.2 s, 1.3 GB read, GPU 73% busy | | 81 tokens (window path) | not measured | 4.5 s, 0.4 GB read | | 109 tokens with `DS4_CHUNK_MIN=16` | not measured | 3.6 s | Real 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: - My 13-problem hard coding suite (pass@1, thinking on, temperature 0.6, top_p 0.95, top_k 20, seed 1234, 16,384 max tokens), one run each: stock 12/13 (`sudoku` failed at the token limit), resident routing 12/13 (`cron_next` failed, an off-by-one-minute case for `* * * * *`). One problem flipped each way. That run had #4921's reuse on as well. - Recall: three facts buried in 11,441 to 11,777-token prompts of shuffled code, each prompt read fresh with resident routing: 3/3, exact strings (for example `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.
Author
Owner

@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=0 turns it off); a PR would flip it to opt-in as proposed above. The window-path numbers in the table used DS4_CHUNK_MIN=16 for the 109-token row. Built and tested with HIP on gfx1201 only; build steps are in the #4921 comment.

<!-- gh-comment-id:6565894449 --> @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=0` turns it off); a PR would flip it to opt-in as proposed above. The window-path numbers in the table used `DS4_CHUNK_MIN=16` for the 109-token row. Built and tested with HIP on gfx1201 only; build steps are in the #4921 comment.
Author
Owner

@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 --score against full routing on 5,000 tokens (code, docs, English, multilingual, agent transcript), 6 experts:

Prompt routing Top-1 vs full KL Perplexity 1,303-token fresh read
full routing 100% 0 6.874 15.3 s, 31.4 GB from NVMe
resident only (this proposal) 67.3% 0.679 16.91 (+146%) 9.9 s, 1.1 GB
selection penalty 0.3 92.9% 0.040 7.083 (+3.0%) 10.8 s, 14.5 GB

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)

<!-- gh-comment-id:6591682684 --> @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 `--score` against full routing on 5,000 tokens (code, docs, English, multilingual, agent transcript), 6 experts: | Prompt routing | Top-1 vs full | KL | Perplexity | 1,303-token fresh read | |---|---|---|---|---| | full routing | 100% | 0 | 6.874 | 15.3 s, 31.4 GB from NVMe | | resident only (this proposal) | 67.3% | 0.679 | 16.91 (+146%) | 9.9 s, 1.1 GB | | selection penalty 0.3 | 92.9% | 0.040 | 7.083 (+3.0%) | 10.8 s, 14.5 GB | 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)
Author
Owner

@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-dsv41 built 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 --score rows 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 --score on data/quant_quality/v1 tokenized with the pack's tokenizer, against the same engine with the bonus off:

    bonus top-1 KL PPL (off: 3.173)
    0.05 95.8% 0.0125 3.177
    0.1 95.4% 0.0161 3.178
    0.2 94.4% 0.0232 3.177
    0.4 92.1% 0.0397 3.259

    For reference, Faster (5 experts) against Full (6) on the same set: KL 0.0172.

  • Decode, CLI, 4K prompt + 256 tokens, 3 runs each:

    • off: 6.88 tok/s (6.47 to 7.14), 29.2 store misses a token
    • 0.1: 9.25 tok/s (9.14 to 9.45), 18.4 misses
    • 0.2: 9.76 tok/s (8.39 to 10.44), 14.1 misses
  • 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); --score at 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's STRATA_ROUTE_PRIOR.

<!-- gh-comment-id:6712499392 --> @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-dsv41` built 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 `--score` rows 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 `--score` on data/quant_quality/v1 tokenized with the pack's tokenizer, against the same engine with the bonus off: | bonus | top-1 | KL | PPL (off: 3.173) | |---|---:|---:|---:| | 0.05 | 95.8% | 0.0125 | 3.177 | | 0.1 | 95.4% | 0.0161 | 3.178 | | 0.2 | 94.4% | 0.0232 | 3.177 | | 0.4 | 92.1% | 0.0397 | 3.259 | For reference, Faster (5 experts) against Full (6) on the same set: KL 0.0172. - Decode, CLI, 4K prompt + 256 tokens, 3 runs each: - off: 6.88 tok/s (6.47 to 7.14), 29.2 store misses a token - 0.1: 9.25 tok/s (9.14 to 9.45), 18.4 misses - 0.2: 9.76 tok/s (8.39 to 10.44), 14.1 misses - 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); `--score` at 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's `STRATA_ROUTE_PRIOR`.
Author
Owner

@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.

<!-- gh-comment-id:6714468448 --> @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 <ram>,<vram> form looks like it already expresses this. It may be worth keeping the two values separate in the PR.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2269
No description provided.