[PR #425] [MERGED] DeepSeek CPU lane: prefetch only the IQ experts' pages that are not in RAM (Windows: +6-7% decode, more on long answers) #522

Closed
opened 2026-10-29 21:26:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/425
Author: @cryptedy
Created: 10/23/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @mw00

Base: main ← Head: pr/ds4-iq-prefetch-cold


📝 Commits (1)

  • 0f44646 DeepSeek CPU lane: prefetch only the IQ experts' pages not in RAM

📊 Changes

1 file changed (+6 additions, -2 deletions)

View changed files

📝 src/ds4/ds4_model.cu (+6 -2)

📄 Description

What

cpu_experts_iq (the GGUF low-bit experts - Maya-S's IQ2_XXS / IQ2_S / IQ3) called os::prefetch for every expert it reads from the files, resident or not. On Windows PrefetchVirtualMemory walks every page of each range - about 0.13 ms for a 10.6 MB IQ2_XXS expert - on the lane thread, before the first entry computes.

cpu_experts_mx already avoids this with os::prefetch_cold (only the ranges that do not look resident, resident_sampled). This PR does the same in the IQ path.

  • Linux: unchanged (prefetch_cold is prefetch there - madvise on cached pages is cheap).
  • DS4_IQ_PF_ALL=1: every range, as before.
  • Only a hint to the OS changes: the same numbers. No new requirements on RAM, VRAM, context or GPU.

Speed

Ryzen 7 9700X (8 cores, 4x DDR5-3600), 128 GB RAM, RTX 3090 24 GB, Windows 11, NVMe; DeepSeek-V4.1-Flash-1017 Maya-S, --mmap-experts off with DS4_COPY_GB=96 (about 2/3 of the CPU lane's experts copied to RAM, the rest read in place), 1,187 of 15,360 experts in VRAM.

Decode = calibrate_ds4's workload (a 512-token document, fresh questions, >= 1.5K tokens written, temp 1.0, thinking off), each run from the same copy of the expert profile; the same binary with DS4_IQ_PF_ALL=1 / unset, alternated, two runs each:

this branch (v1.1.25 + this) tok/s
DS4_IQ_PF_ALL=1 (as before) 16.9 / 16.7
default 18.1 / 17.7 (+6.5%)

On v1.1.21 the same change measured 17.0 / 17.1 -> 18.4 / 18.3 tok/s for chat, and on 4K-token answers (where more experts come from the files) the slowest 256-token stretches went from ~7.4 to ~11.5 tok/s.

The gain grows with the share of experts a token reads from the files (copies capped, or more experts than RAM holds); with every CPU-lane expert copied to RAM there is nothing to prefetch and nothing changes.

Not tested

Linux and AMD (HIP) builds - the Linux path is the same call as before.


🔄 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/425 **Author:** [@cryptedy](https://github.com/cryptedy) **Created:** 10/23/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `pr/ds4-iq-prefetch-cold` --- ### 📝 Commits (1) - [`0f44646`](https://github.com/mw00/project-maya/commit/0f44646832a6afae4d428b28afad4c0373443eea) DeepSeek CPU lane: prefetch only the IQ experts' pages not in RAM ### 📊 Changes **1 file changed** (+6 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/ds4/ds4_model.cu` (+6 -2) </details> ### 📄 Description ### What `cpu_experts_iq` (the GGUF low-bit experts - Maya-S's IQ2_XXS / IQ2_S / IQ3) called `os::prefetch` for every expert it reads from the files, resident or not. On Windows `PrefetchVirtualMemory` walks every page of each range - about 0.13 ms for a 10.6 MB IQ2_XXS expert - on the lane thread, before the first entry computes. `cpu_experts_mx` already avoids this with `os::prefetch_cold` (only the ranges that do not look resident, `resident_sampled`). This PR does the same in the IQ path. - Linux: unchanged (`prefetch_cold` is `prefetch` there - madvise on cached pages is cheap). - `DS4_IQ_PF_ALL=1`: every range, as before. - Only a hint to the OS changes: the same numbers. No new requirements on RAM, VRAM, context or GPU. ### Speed Ryzen 7 9700X (8 cores, 4x DDR5-3600), 128 GB RAM, RTX 3090 24 GB, Windows 11, NVMe; DeepSeek-V4.1-Flash-1017 Maya-S, `--mmap-experts off` with `DS4_COPY_GB=96` (about 2/3 of the CPU lane's experts copied to RAM, the rest read in place), 1,187 of 15,360 experts in VRAM. Decode = calibrate_ds4's workload (a 512-token document, fresh questions, >= 1.5K tokens written, temp 1.0, thinking off), each run from the same copy of the expert profile; the same binary with `DS4_IQ_PF_ALL=1` / unset, alternated, two runs each: | this branch (v1.1.25 + this) | tok/s | |---|---:| | `DS4_IQ_PF_ALL=1` (as before) | 16.9 / 16.7 | | default | **18.1 / 17.7** (+6.5%) | On v1.1.21 the same change measured 17.0 / 17.1 -> 18.4 / 18.3 tok/s for chat, and on 4K-token answers (where more experts come from the files) the slowest 256-token stretches went from ~7.4 to ~11.5 tok/s. The gain grows with the share of experts a token reads from the files (copies capped, or more experts than RAM holds); with every CPU-lane expert copied to RAM there is nothing to prefetch and nothing changes. ### Not tested Linux and AMD (HIP) builds - the Linux path is the same call as before. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:26:21 +07:00
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#522
No description provided.