[PR #449] [CLOSED] DeepSeek copy mode: DS4_COPY_SWAP - the RAM copies follow the routes (DISK_SKIP_W leaves out 25-30% fewer experts, same speed) #530

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/449
Author: @cryptedy
Created: 10/24/2026
Status: ❌ Closed

Base: main ← Head: pr/ds4-copy-swap


📝 Commits (2)

  • e2b6ea6 DeepSeek copy mode: DS4_COPY_SWAP - the RAM copies follow the routes, as the RAM tier's do
  • 2432777 DS4_COPY_SWAP: the MAYA_DS4_COPY_SWAP name (read as STRATA_DS4_), docs/SETTINGS.md

📊 Changes

2 files changed (+156 additions, -3 deletions)

View changed files

📝 docs/SETTINGS.md (+21 -0)
📝 src/ds4/ds4_model.cu (+135 -3)

📄 Description

What

With --mmap-experts off the CPU lane's most-routed experts are copied into RAM at the start and stay there; the rest are read in place from the model's files. DISK_SKIP_W never computes an expert it leaves out, so that expert's pages never come off the SSD, and it is left out again wherever it is picked light - all through a conversation. Its heat does count those picks.

MAYA_DS4_COPY_SWAP=1 (opt-in) lets the copies follow the routes, as the RAM tier's do:

  • each layer gets one free copy slot more (the whole RAM cost: one expert a layer, ~0.44 GB on Maya-S);
  • between windows, a layer's hottest expert read from the files (heat, the expert cache's) takes the place of its coldest copy when it beats it by MAYA_DS4_COPY_SWAP_MARGIN x + 1 (default 1.25, as the RAM tier's moves);
  • a thread of its own reads it into the free slot, and the switch happens between windows (nothing reads the copies then); the coldest copy's slot becomes the free one, and that expert is read in place again;
  • one move at a time, at most one every MAYA_DS4_COPY_SWAP_EVERY tokens (default 8).

The copies keep their RAM, so nothing else leaves the page cache for them. With DISK_SKIP_W set, the log gets a line every 512 decoded tokens: the experts a token left out, and the copy swaps.

The idea is Abyss's RAM fill for its disk tail skip (zephel01/Abyss v1.3.46, issue #8 there), which in turn came from @sh-Tx2Lym's reading of that code - thanks to both. A first try here that read the skipped experts into the page cache instead (no fixed slots) cut the skips by 60-80% but cost 10-25% of the decode speed on a machine whose RAM was full: every read pushed other experts out. The fixed slots avoid that.

The settings are documented in docs/SETTINGS.md ("DeepSeek: skipping light experts the SSD would read"); they are read as STRATA_DS4_COPY_SWAP* (a config's MAYA_DS4_COPY_SWAP*), with DS4_COPY_SWAP* as a fallback.

Measured

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, DS4_COPY_GB=96 (about 2/3 of the CPU lane's experts copied), MAYA_DS4_DISK_SKIP_W=0.20, v1.1.26.

8,192-token answers (one request each, sampled, two runs each way, alternated):

tok/s experts a token left out, 2nd half
off 15.04 / 15.79 ~5.0-5.8
MAYA_DS4_COPY_SWAP=1 15.76 / 15.88 ~3.5-4.5
every 4 tokens 15.41 / 15.71 ~3-4
every 2 tokens 15.06 / 14.96 ~3.5-4.5

Quality after a 4,096-token answer (the conversation warm), 6 prompts x 256 greedy tokens, KL against the same build without skipping (the reference reads each token alone):

KL same top token
no skip 0.0171 +/- 0.0033 96.0%
DISK_SKIP_W=0.20 0.0184 +/- 0.0024 95.7%
DISK_SKIP_W=0.20, MAYA_DS4_COPY_SWAP=1 0.0149 +/- 0.0017 97.5%

(With the swaps the difference to no skip is within the noise; the swaps change only where experts sit, not the arithmetic.)

Chat decode (calibrate_ds4's workload) with it on: 18.6 tok/s, as before.

Not tested

Linux / AMD builds; NUMA with two parts (the read follows copy_experts' per-part layout, but only one part was run); a pack where the copies hold every expert (then there is nothing to swap in and nothing 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/449 **Author:** [@cryptedy](https://github.com/cryptedy) **Created:** 10/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/ds4-copy-swap` --- ### 📝 Commits (2) - [`e2b6ea6`](https://github.com/mw00/project-maya/commit/e2b6ea6c49f02d868039cf30221a65c5157479bc) DeepSeek copy mode: DS4_COPY_SWAP - the RAM copies follow the routes, as the RAM tier's do - [`2432777`](https://github.com/mw00/project-maya/commit/2432777270c77b01a1f7cda1ed6a5c0a1636409e) DS4_COPY_SWAP: the MAYA_DS4_COPY_SWAP name (read as STRATA_DS4_), docs/SETTINGS.md ### 📊 Changes **2 files changed** (+156 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+21 -0) 📝 `src/ds4/ds4_model.cu` (+135 -3) </details> ### 📄 Description ### What With `--mmap-experts off` the CPU lane's most-routed experts are copied into RAM at the start and stay there; the rest are read in place from the model's files. `DISK_SKIP_W` never computes an expert it leaves out, so that expert's pages never come off the SSD, and it is left out again wherever it is picked light - all through a conversation. Its heat does count those picks. `MAYA_DS4_COPY_SWAP=1` (opt-in) lets the copies follow the routes, as the RAM tier's do: - each layer gets one free copy slot more (the whole RAM cost: one expert a layer, ~0.44 GB on Maya-S); - between windows, a layer's hottest expert read from the files (heat, the expert cache's) takes the place of its coldest copy when it beats it by `MAYA_DS4_COPY_SWAP_MARGIN` x + 1 (default 1.25, as the RAM tier's moves); - a thread of its own reads it into the free slot, and the switch happens between windows (nothing reads the copies then); the coldest copy's slot becomes the free one, and that expert is read in place again; - one move at a time, at most one every `MAYA_DS4_COPY_SWAP_EVERY` tokens (default 8). The copies keep their RAM, so nothing else leaves the page cache for them. With `DISK_SKIP_W` set, the log gets a line every 512 decoded tokens: the experts a token left out, and the copy swaps. The idea is Abyss's RAM fill for its disk tail skip ([zephel01/Abyss](https://github.com/zephel01/Abyss) v1.3.46, issue #8 there), which in turn came from @sh-Tx2Lym's reading of that code - thanks to both. A first try here that read the skipped experts into the page cache instead (no fixed slots) cut the skips by 60-80% but cost 10-25% of the decode speed on a machine whose RAM was full: every read pushed other experts out. The fixed slots avoid that. The settings are documented in `docs/SETTINGS.md` ("DeepSeek: skipping light experts the SSD would read"); they are read as `STRATA_DS4_COPY_SWAP*` (a config's `MAYA_DS4_COPY_SWAP*`), with `DS4_COPY_SWAP*` as a fallback. ### Measured 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`, `DS4_COPY_GB=96` (about 2/3 of the CPU lane's experts copied), `MAYA_DS4_DISK_SKIP_W=0.20`, v1.1.26. 8,192-token answers (one request each, sampled, two runs each way, alternated): | | tok/s | experts a token left out, 2nd half | |---|---:|---:| | off | 15.04 / 15.79 | ~5.0-5.8 | | `MAYA_DS4_COPY_SWAP=1` | 15.76 / 15.88 | ~3.5-4.5 | | every 4 tokens | 15.41 / 15.71 | ~3-4 | | every 2 tokens | 15.06 / 14.96 | ~3.5-4.5 | Quality after a 4,096-token answer (the conversation warm), 6 prompts x 256 greedy tokens, KL against the same build without skipping (the reference reads each token alone): | | KL | same top token | |---|---:|---:| | no skip | 0.0171 +/- 0.0033 | 96.0% | | `DISK_SKIP_W=0.20` | 0.0184 +/- 0.0024 | 95.7% | | `DISK_SKIP_W=0.20`, `MAYA_DS4_COPY_SWAP=1` | 0.0149 +/- 0.0017 | 97.5% | (With the swaps the difference to no skip is within the noise; the swaps change only where experts sit, not the arithmetic.) Chat decode (calibrate_ds4's workload) with it on: 18.6 tok/s, as before. ### Not tested Linux / AMD builds; NUMA with two parts (the read follows `copy_experts`' per-part layout, but only one part was run); a pack where the copies hold every expert (then there is nothing to swap in and nothing changes). --- <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:28 +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#530
No description provided.