[PR #569] feat(ds4): add opt-in expert prefetch sampling on Linux #602

Open
opened 2026-10-29 21:27:22 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/569
Author: @Whamp
Created: 10/27/2026
Status: 🔄 Open

Base: main ← Head: feat/ds4-expert-prefetch-policy


📝 Commits (2)

  • 4efbd3f feat(ds4): expose opt-in expert prefetch sampling on Linux
  • 1b4e3bc ref(ds4): simplify expert prefetch to one sample count

📊 Changes

9 files changed (+387 additions, -14 deletions)

View changed files

📝 CMakeLists.txt (+16 -0)
📝 README.md (+2 -1)
📝 docs/SETTINGS.md (+1 -0)
➕ docs/ds4-expert-prefetch.md (+39 -0)
➕ src/ds4/ds4_expert_prefetch.hpp (+48 -0)
📝 src/ds4/ds4_main.cpp (+7 -0)
📝 src/ds4/ds4_os.hpp (+7 -13)
➕ tests/ds4_prefetch_policy_test.cpp (+122 -0)
➕ tests/ds4_prefetch_test.cpp (+145 -0)

📄 Description

On Linux, Maya sends read-ahead hints for every expert-weight range passed to prefetch_cold, even when those file pages are already cached. This PR lets users sample pages and skip the hint when every sample is resident, avoiding repeated hints for cached weights.

Residency checks also cost time, so Linux sampling stays opt-in. Windows already uses eight samples per range; its default stays unchanged, but the count becomes configurable.

Configuration and behavior

Set DS4_PF_SAMPLES in the saved Maya config and restart:

{
  "env": { "DS4_PF_SAMPLES": "4" }
}
  • Unset preserves current defaults: always hint on Linux, sample eight pages per range on Windows. 0 always hints; 1 through 16 sets the sample count per range.
  • Sampling skips a hint only if every sample is resident. An uncached sampled page or failed query keeps the hint. The engine validates and logs the setting before loading weights, then keeps it until restart.
  • Nonzero DS4_PF_ALL still overrides the count and forces hints. DS4_PF_ALL=0 does not enable sampling. DS4_IQ_PF_ALL still bypasses filtering at its separate IQ call site.
  • This changes expert read-ahead only. Engram reads, RAM-copy allocation and input-path selection are unchanged. Full CPU-expert RAM copies can bypass this file-backed work.

Linux measurements

Mean time to process the added input and generate 256 tokens after an 8K cached code-chat prefix, comparing main e16dec85 with PR 1b4e3bc:

Added tokens Main, 1 start PR, always hint, 3 starts PR, four samples, 3 starts Four samples vs always hint: time change and 95% interval
128 10.620 s 10.981 s 9.463 s -13.8%, -16.5% to -8.5%
512 15.431 s 16.581 s 13.588 s -18.0%, -43.7% to -3.6%
2048 12.277 s 12.381 s 12.221 s -1.3%, -6.4% to +7.2%

Negative changes mean less time. Main is a single reference run; the repeated comparison is counts 0 versus 4 within the PR build.

  • Four samples raised decode throughput for 128-token additions from 30.55 to 34.32 tok/s, or 12.3%, with a 95% interval of +6.8% to +22.2%. Other decode estimates did not establish a clear change.
  • The largest prefill gain coincided with a different input-processing path. In two pairs, both settings used 16-token windows; four samples reduced 512-token prefill time by 6.6% and 7.5%. In the third, four samples used the streamed GPU flow path while the control used windows; the reduction was 70.9%. This does not establish whether sampling caused the path change or isolate read-ahead call cost. #612 addresses the selector separately. Do not add the two PRs' gains together.
  • Counts 1/2/8/16 had one start each. These runs do not establish a best count.
Benchmark setup
  • Threadripper PRO 3945WX, 123 GiB RAM, four RTX 3090s, DeepSeek V4.1 Flash GSQ RCO IQ2-XXS pack. File-backed experts, TP=1, 12 CPU threads, automatic path selection, speculative decoding enabled, 262144 configured context.
  • Eleven fresh starts and 99 cached turns. Counts 0/4 had three pairs, ordered 0/4, 4/0, 0/4. Main and counts 1/2/8/16 had one start each.
  • All generated outputs were included, even when they differed. Bootstrap intervals resample paired engine starts, not turns. Only three pairs underpin these estimates.

Tradeoffs and limits

  • Sampling can miss an uncached page and delay its demand read. Residency checks can also cost more than unconditional hints.
  • With experimental MAYA_DS4_DISK_SKIP_W enabled, changed residency can change which experts Maya omits and therefore change answers. The benchmark did not enable disk skipping and does not establish output equivalence.
  • These are direct-engine, single-request timings on synthetic chat that retained prior reasoning tokens. They exclude HTTP and queueing. OS cache, startup calibration and speculative acceptance can affect results. Native Windows, other hardware and broader workloads remain unverified.
  • Keep sampling opt-in. This PR adds no automatic tuning, startup sweep or UI changes.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/mw00/project-maya/pull/569 **Author:** [@Whamp](https://github.com/Whamp) **Created:** 10/27/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/ds4-expert-prefetch-policy` --- ### 📝 Commits (2) - [`4efbd3f`](https://github.com/mw00/project-maya/commit/4efbd3fffad5539f8df9c7fca98e18a37aa95034) feat(ds4): expose opt-in expert prefetch sampling on Linux - [`1b4e3bc`](https://github.com/mw00/project-maya/commit/1b4e3bc715dd868cbd8947fe0bc84b31ee5024a6) ref(ds4): simplify expert prefetch to one sample count ### 📊 Changes **9 files changed** (+387 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+16 -0) 📝 `README.md` (+2 -1) 📝 `docs/SETTINGS.md` (+1 -0) ➕ `docs/ds4-expert-prefetch.md` (+39 -0) ➕ `src/ds4/ds4_expert_prefetch.hpp` (+48 -0) 📝 `src/ds4/ds4_main.cpp` (+7 -0) 📝 `src/ds4/ds4_os.hpp` (+7 -13) ➕ `tests/ds4_prefetch_policy_test.cpp` (+122 -0) ➕ `tests/ds4_prefetch_test.cpp` (+145 -0) </details> ### 📄 Description On Linux, Maya sends read-ahead hints for every expert-weight range passed to `prefetch_cold`, even when those file pages are already cached. This PR lets users sample pages and skip the hint when every sample is resident, avoiding repeated hints for cached weights. Residency checks also cost time, so Linux sampling stays opt-in. Windows already uses eight samples per range; its default stays unchanged, but the count becomes configurable. ## Configuration and behavior Set `DS4_PF_SAMPLES` in the saved Maya config and restart: ```json { "env": { "DS4_PF_SAMPLES": "4" } } ``` - Unset preserves current defaults: always hint on Linux, sample eight pages per range on Windows. `0` always hints; `1` through `16` sets the sample count per range. - Sampling skips a hint only if every sample is resident. An uncached sampled page or failed query keeps the hint. The engine validates and logs the setting before loading weights, then keeps it until restart. - Nonzero `DS4_PF_ALL` still overrides the count and forces hints. `DS4_PF_ALL=0` does not enable sampling. `DS4_IQ_PF_ALL` still bypasses filtering at its separate IQ call site. - This changes expert read-ahead only. Engram reads, RAM-copy allocation and input-path selection are unchanged. Full CPU-expert RAM copies can bypass this file-backed work. ## Linux measurements Mean time to process the added input and generate 256 tokens after an 8K cached code-chat prefix, comparing main `e16dec85` with PR `1b4e3bc`: | Added tokens | Main, 1 start | PR, always hint, 3 starts | PR, four samples, 3 starts | Four samples vs always hint: time change and 95% interval | |---|---:|---:|---:|---:| | 128 | 10.620 s | 10.981 s | 9.463 s | -13.8%, -16.5% to -8.5% | | 512 | 15.431 s | 16.581 s | 13.588 s | -18.0%, -43.7% to -3.6% | | 2048 | 12.277 s | 12.381 s | 12.221 s | -1.3%, -6.4% to +7.2% | Negative changes mean less time. Main is a single reference run; the repeated comparison is counts 0 versus 4 within the PR build. - Four samples raised decode throughput for 128-token additions from 30.55 to 34.32 tok/s, or 12.3%, with a 95% interval of +6.8% to +22.2%. Other decode estimates did not establish a clear change. - The largest prefill gain coincided with a different input-processing path. In two pairs, both settings used 16-token windows; four samples reduced 512-token prefill time by 6.6% and 7.5%. In the third, four samples used the streamed GPU flow path while the control used windows; the reduction was 70.9%. This does not establish whether sampling caused the path change or isolate read-ahead call cost. #612 addresses the selector separately. Do not add the two PRs' gains together. - Counts 1/2/8/16 had one start each. These runs do not establish a best count. <details> <summary>Benchmark setup</summary> - Threadripper PRO 3945WX, 123 GiB RAM, four RTX 3090s, DeepSeek V4.1 Flash GSQ RCO IQ2-XXS pack. File-backed experts, TP=1, 12 CPU threads, automatic path selection, speculative decoding enabled, 262144 configured context. - Eleven fresh starts and 99 cached turns. Counts 0/4 had three pairs, ordered 0/4, 4/0, 0/4. Main and counts 1/2/8/16 had one start each. - All generated outputs were included, even when they differed. Bootstrap intervals resample paired engine starts, not turns. Only three pairs underpin these estimates. </details> ## Tradeoffs and limits - Sampling can miss an uncached page and delay its demand read. Residency checks can also cost more than unconditional hints. - With experimental `MAYA_DS4_DISK_SKIP_W` enabled, changed residency can change which experts Maya omits and therefore change answers. The benchmark did not enable disk skipping and does not establish output equivalence. - These are direct-engine, single-request timings on synthetic chat that retained prior reasoning tokens. They exclude HTTP and queueing. OS cache, startup calibration and speculative acceptance can affect results. Native Windows, other hardware and broader workloads remain unverified. - Keep sampling opt-in. This PR adds no automatic tuning, startup sweep or UI changes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#602
No description provided.