[PR #84] [MERGED] GLM prefetch that pays on a RAM-bound split: start the copy after this layer's fetch, on a few blocks, and copy only the prediction's top ranks (STRATA_GLM_PREFETCH_AT / _BLOCKS / _RANK) #324

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

📋 Pull Request Information

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

Base: main ← Head: pr-prefetch


📝 Commits (1)

  • b5a4491 GLM prefetch: when the copy starts (STRATA_GLM_PREFETCH_AT), how many blocks it takes (STRATA_GLM_PREFETCH_BLOCKS) and which prediction ranks it copies (STRATA_GLM_PREFETCH_RANK); README row for the prefetch

📊 Changes

4 files changed (+40 additions, -12 deletions)

View changed files

📝 README.md (+1 -0)
📝 include/strata/kernels/glm_fast.hpp (+1 -1)
📝 src/core/glm_fast_path.cu (+22 -5)
📝 src/kernels/cuda/glm_fast.cu (+16 -6)

📄 Description

What

STRATA_GLM_PREFETCH_N copies the next layer's predicted non-resident experts into its spares while a layer computes.
As it is, it cost us 13.6 % decode while it raised VRAM hits by 7.5 points. Three switches, each read once:

  • STRATA_GLM_PREFETCH_AT=route|fetch|cpu - when the copy starts: at once (the default, as before: beside this
    layer's own PCIe fetch and its CPU lane), after this layer's fetch (the link is free), or after its CPU-lane answer.
    The prefetch lists are double-buffered by layer parity and the next layer waits for the copy before its experts run,
    so any of the three is safe.
  • STRATA_GLM_PREFETCH_BLOCKS=<n> - the copy kernel's blocks (default half the SMs, as before). A PCIe pull needs
    few SMs; every SM it holds is one the main stream waits for.
  • STRATA_GLM_PREFETCH_RANK=<n> - copy only the prediction's first n ranks. The route kernel took the first predicted
    expert that is not resident; the top guesses usually are resident already, so that was often a rank-5..7 guess.

README: a row for the prefetch and these switches (PREFETCH_N had none).

Measured

Ryzen 9 5900X + 128 GB DDR4, RTX 3090 + 3060 (x8 each), warm 21K API test (fresh 21K prompt, then 2,500 tokens at
21K depth); Maya-M with RAM_RESIDENT=1, split 30, CPU_PLAN=012234567:

prefetch decode @21K VRAM hits
off (5 runs: 19.52-19.75) 19.64 64.4 %
N=1 (as it is) 17.02 71.9 %
N=1 AT=cpu BLOCKS=8 18.76 72.9 %
N=1 AT=fetch BLOCKS=8 19.33 72.6 %
N=1 AT=fetch BLOCKS=4 19.75 72.7 %
N=1 AT=fetch BLOCKS=2 18.07 72.5 %
N=2 AT=fetch BLOCKS=8 18.58 72.5 %
N=1 AT=fetch BLOCKS=4 RANK=2 (twice) 20.21 / 20.24 (+3 %) 69.4 %
N=1 AT=fetch BLOCKS=4 RANK=1 20.07 67.7 %
N=1 AT=fetch BLOCKS=4 RANK=3 / N=2 ... RANK=3 20.10 / 19.88 70.9 / 70.5 %

Why the rank: route logs with the predictions beside the next layer's real top 8 - the next layer used the prediction's
rank 0 / 1 / 2 / 3 96 / 88 / 75 / 62 % of the time and ranks 4..7 52 / 41 / 31 / 24 % (3090 half; the 3060 half 99 / 94
/ 89 / 80 .. 36 %). The prefetches as they were: 70 % used on the 3090 half. A wrong copy costs the link about what a
right one saves.

Maya-L there (12 MB experts, RAM_GB=96 + NVMe, calibrated plan, STRATA_GLM_VRAM_EVICT=lru from #78): RANK=2
11.46 (no gain over 11.75 without prefetch), RANK=1 12.02 (+2.3 % on top of #78, +5.0 % over 11.45 with neither).

On an agent-like workload (one conversation, 40 turns of short answers on a reused, growing context 22K -> 89K, a
20K-token prompt read every 8th turn; tools-style driver over /v1/chat/completions), Maya-M, same box: answer
decode weighted by tokens 19.31 -> 20.21 tok/s (+4.7 %) with N=1 AT=fetch BLOCKS=4 RANK=2, 19.42 -> 20.41 at
contexts over 60K (+5.1 %)
; 0 failures in either run, and 0 in a third run with Maya-L (RANK=1, 11.4 tok/s) -
the prompt -> answer handoffs on reused prefixes are where the #39 races showed, so it was worth the check.

Checks run on this branch: builds (sm_75, sm_86); glm_dsa_parity, glm_ffn_parity, glm_hc_parity,
glm_kda_parity, glm_layer_parity --selftest: all PASS; python -m unittest serve.test_server serve.test_tools serve.test_mcp serve.test_detok: OK; the 21K API test on the real model with this exact build and
N=1 AT=fetch BLOCKS=4 RANK=2: 20.11 tok/s at 21K (VRAM hits 69.3 %), clean. It merges cleanly with #76, #78, #80 and #81.


The code, the measurements and this description were produced with the help of Claude, an AI assistant by Anthropic.


🔄 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/84 **Author:** [@sociolog](https://github.com/sociolog) **Created:** 10/10/2026 **Status:** ✅ Merged **Merged:** 10/10/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `pr-prefetch` --- ### 📝 Commits (1) - [`b5a4491`](https://github.com/mw00/project-maya/commit/b5a449149a8f322923719444748c0be17558dbab) GLM prefetch: when the copy starts (STRATA_GLM_PREFETCH_AT), how many blocks it takes (STRATA_GLM_PREFETCH_BLOCKS) and which prediction ranks it copies (STRATA_GLM_PREFETCH_RANK); README row for the prefetch ### 📊 Changes **4 files changed** (+40 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+1 -0) 📝 `include/strata/kernels/glm_fast.hpp` (+1 -1) 📝 `src/core/glm_fast_path.cu` (+22 -5) 📝 `src/kernels/cuda/glm_fast.cu` (+16 -6) </details> ### 📄 Description ## What `STRATA_GLM_PREFETCH_N` copies the next layer's predicted non-resident experts into its spares while a layer computes. As it is, it cost us 13.6 % decode while it raised VRAM hits by 7.5 points. Three switches, each read once: - `STRATA_GLM_PREFETCH_AT=route|fetch|cpu` - when the copy starts: at once (the default, as before: beside this layer's own PCIe fetch and its CPU lane), after this layer's fetch (the link is free), or after its CPU-lane answer. The prefetch lists are double-buffered by layer parity and the next layer waits for the copy before its experts run, so any of the three is safe. - `STRATA_GLM_PREFETCH_BLOCKS=<n>` - the copy kernel's blocks (default half the SMs, as before). A PCIe pull needs few SMs; every SM it holds is one the main stream waits for. - `STRATA_GLM_PREFETCH_RANK=<n>` - copy only the prediction's first n ranks. The route kernel took the first predicted expert that is not resident; the top guesses usually are resident already, so that was often a rank-5..7 guess. README: a row for the prefetch and these switches (`PREFETCH_N` had none). ## Measured Ryzen 9 5900X + 128 GB DDR4, RTX 3090 + 3060 (x8 each), warm 21K API test (fresh 21K prompt, then 2,500 tokens at 21K depth); Maya-M with `RAM_RESIDENT=1`, split 30, `CPU_PLAN=012234567`: | prefetch | decode @21K | VRAM hits | |---|---:|---:| | off (5 runs: 19.52-19.75) | 19.64 | 64.4 % | | `N=1` (as it is) | 17.02 | 71.9 % | | `N=1 AT=cpu BLOCKS=8` | 18.76 | 72.9 % | | `N=1 AT=fetch BLOCKS=8` | 19.33 | 72.6 % | | `N=1 AT=fetch BLOCKS=4` | 19.75 | 72.7 % | | `N=1 AT=fetch BLOCKS=2` | 18.07 | 72.5 % | | `N=2 AT=fetch BLOCKS=8` | 18.58 | 72.5 % | | **`N=1 AT=fetch BLOCKS=4 RANK=2`** (twice) | **20.21 / 20.24 (+3 %)** | 69.4 % | | `N=1 AT=fetch BLOCKS=4 RANK=1` | 20.07 | 67.7 % | | `N=1 AT=fetch BLOCKS=4 RANK=3` / `N=2 ... RANK=3` | 20.10 / 19.88 | 70.9 / 70.5 % | Why the rank: route logs with the predictions beside the next layer's real top 8 - the next layer used the prediction's rank 0 / 1 / 2 / 3 96 / 88 / 75 / 62 % of the time and ranks 4..7 52 / 41 / 31 / 24 % (3090 half; the 3060 half 99 / 94 / 89 / 80 .. 36 %). The prefetches as they were: 70 % used on the 3090 half. A wrong copy costs the link about what a right one saves. Maya-L there (12 MB experts, `RAM_GB=96` + NVMe, calibrated plan, `STRATA_GLM_VRAM_EVICT=lru` from #78): `RANK=2` 11.46 (no gain over 11.75 without prefetch), **`RANK=1` 12.02** (+2.3 % on top of #78, +5.0 % over 11.45 with neither). **On an agent-like workload** (one conversation, 40 turns of short answers on a reused, growing context 22K -> 89K, a 20K-token prompt read every 8th turn; `tools`-style driver over `/v1/chat/completions`), Maya-M, same box: answer decode weighted by tokens **19.31 -> 20.21 tok/s (+4.7 %)** with `N=1 AT=fetch BLOCKS=4 RANK=2`, **19.42 -> 20.41 at contexts over 60K (+5.1 %)**; 0 failures in either run, and 0 in a third run with Maya-L (`RANK=1`, 11.4 tok/s) - the prompt -> answer handoffs on reused prefixes are where the #39 races showed, so it was worth the check. **Checks run on this branch:** builds (sm_75, sm_86); `glm_dsa_parity`, `glm_ffn_parity`, `glm_hc_parity`, `glm_kda_parity`, `glm_layer_parity` `--selftest`: all PASS; `python -m unittest serve.test_server serve.test_tools serve.test_mcp serve.test_detok`: OK; the 21K API test on the real model with this exact build and `N=1 AT=fetch BLOCKS=4 RANK=2`: 20.11 tok/s at 21K (VRAM hits 69.3 %), clean. It merges cleanly with #76, #78, #80 and #81. --- *The code, the measurements and this description were produced with the help of Claude, an AI assistant by Anthropic.* --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:24:13 +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#324
No description provided.