[PR #270] [MERGED] GLM prompt on a split without NVLink: the waiting GPU computes a share of the working half's staged experts over its own PCIe link (MAYA_GLM_PREFILL_CALC, opt-in) #438

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

📋 Pull Request Information

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

Base: main ← Head: prompt-help


📝 Commits (1)

  • e5a25a7 GLM prompt on a split without NVLink: the waiting GPU computes a share of the working half's staged experts over its own PCIe link (MAYA_GLM_PREFILL_CALC, off by default)

📊 Changes

3 files changed (+754 additions, -144 deletions)

View changed files

📝 docs/SETTINGS.md (+1 -0)
📝 include/strata/core/glm_model.hpp (+5 -0)
📝 src/core/glm_prefill.cu (+748 -144)

📄 Description

What

On a two-GPU layer split, a prompt of one chunk runs the halves one after the other: while the first GPU runs its
layers, the second GPU and its PCIe link wait, and the other way round. When most routed experts live in the RAM tier,
most of each half is the staging of those experts over the working GPU's own link (MAYA_GLM_PREFILL_PROF=1, a
2K prompt on an RTX 3090 + RTX 3060: moe_staged 67 % of each half; the two halves' stream times add up to the wall
time). MAYA_GLM_DUAL_PREFILL (#121) puts the waiting GPU's link to work through NVLink; without peer access
(GeForce cards, no NVLink) its peer copy would cross the working GPU's link anyway. #138 (a short prompt cut into one
chunk per GPU, pipelined) goes after the same idle GPU, but where most experts come from RAM each extra chunk stages
them again: on the machine below it is 3-23 % slower from 1K to 7K tokens (MAYA_GLM_PREFILL_SHORT=1, one run).

MAYA_GLM_PREFILL_CALC=1 (off by default): the waiting GPU computes a share of each MoE layer's RAM-tier experts
itself - their weights over its own PCIe link from the working GPU's pinned RAM tier, the chunk's inputs and routes
over the host to it, and the weighted sum of its rows back over the host, added into the layer's output after the
combine. Both links stream at once.

  • One code path for the expert products: the EXL3 products (tensor-core kernels for the lightly routed experts,
    reconstruct + cuBLAS for the rest) move out of prefill_half's lambdas into file-level functions on an explicit
    lane (stream, cuBLAS handle, weight scratch, x, row tokens, output window) - unchanged, operation for operation - so
    the waiting GPU computes exactly what the working GPU would.
  • The plan splits the staged RAM-tier experts three ways: the CPU lane's share as before (its PCIe estimate scaled by
    the share the other GPU takes), then a learned share for the waiting GPU (the lightest experts when it has fewer
    multiprocessors, else the most routed), the rest on the working GPU. The waiting GPU's rows go last in the sorted
    order; the working GPU never computes them.
  • x early: the FFN input goes down right after the hyper-connection read (the CPU lane's own early copy, made
    portable) and up the waiting GPU's link while the working GPU runs the shared expert and the router; the routes go
    into mapped memory with the counts (no copy engine).
  • The waiting GPU's work goes onto its streams from a host thread of its own: its plan up, the share's weights
    into a ring of 3 groups of 4 slots, the same products, its window added into a zeroed sum (moe_combine_add, route
    order), the sum down in 4 pieces; the working GPU uploads each piece as it lands (after the CPU rows' upload) into
    the tail of OUTPc (the CPU rows are capped to leave the chunk's rows there).
  • No new VRAM: the waiting GPU's buffers are carved from its own prompt carve, which is idle until its half
    (calc_carve; the ring drops to 2 groups if it must, else the mode stays off for that prompt and says so). Pinned:
    a chunk's sum (T x n_embd floats) a GPU, the routes, x made portable.
  • The order guards: at every half's start each part's copy / KV / x streams wait for its compute stream, so the
    waiting GPU's copies never land in a carve still in use and a part's own half never starts its copies while its
    share of the other half still reads that carve; a part whose carve held a share sets its MMQ row ids again.
  • The balance: each helped layer's two lanes (this link's last staged copy; the other GPU's sum on the host plus its
    way up) are read at the next one, and the share is nudged until they end together (MAYA_GLM_PREFILL_CALC_SHARE
    fixes it). MAYA_GLM_PREFILL_TRACE=1 prints both lane ends per layer, MAYA_GLM_PREFILL_VERBOSE=1 the experts and
    rows the waiting GPU computed and the shares.
  • Not with MAYA_GLM_DUAL_PREFILL (where peer access works that one wins), not in the pipeline (prompts of several
    chunks keep both GPUs busy already), EXL3 experts only (an MMQ pack keeps the path as before).
  • MAYA_GLM_PREFILL_CALC_CHECK=1 (debug, synchronous): the working GPU computes the share again and prints how far
    the two sums differ, layer by layer.

Checked

turboderp's GLM-5.3-Flash sc_3.10bpw on RTX 3090 + RTX 3060 (PCIe 4.0 x8 each, no NVLink), Ryzen 9 5900X, 128 GB,
layers [0, 28) / [28, 45), most routed experts in the RAM tier (MAYA_GLM_RAM_RESIDENT=1), the CPU lane on.

Prompt time (fresh prompts, two each, one engine start a run, a quiet machine; off / on / off / on interleaved):

Prompt off MAYA_GLM_PREFILL_CALC=1 time
512 tokens 5,249 ms = 98 tok/s 3,544 ms = 144 tok/s -32.5 %
1,024 6,595 ms = 155 tok/s 4,471 ms = 229 tok/s -32.2 %
2,048 8,396 ms = 244 tok/s 5,869 ms = 349 tok/s -30.1 %
4,096 11,636 ms = 352 tok/s 8,744 ms = 468 tok/s -24.9 %
7,168 16,108 ms = 445 tok/s 12,868 ms = 557 tok/s -20.1 %

(The mean of 4 prompts an arm; each arm's runs within 1 % of each other, the arms' ranges apart at every size.
v1.1.15 itself in the same series: the same as off, within 1 %.) The learned shares settle at 0.51-0.55; with
MAYA_GLM_PREFILL_TRACE=1 a layer's two lanes end within a few ms of each other. Longer prompts gain less: their
experts' compute and the attention grow with the tokens while the staged bytes stay about the same.

Answers: the scorer with its context through the prompt path (MAYA_GLM_SCORE_PREFILL=1: 2,048 tokens of
held-out prose as one chunk through both halves, the next 650 scored token by token), CPU lane off, against v1.1.15:

Build / setting KL max same top token
v1.1.15 again 0.000000 0.0000 100.00 %
this branch, off 0.000000 0.0000 100.00 %
this branch, MAYA_GLM_PREFILL_CALC=1 0.012616 0.1846 95.69 %
v1.1.15, MAYA_GLM_PREFILL_SUB=512 (only the mixers' blocking changes) 0.013763 0.4297 95.23 %

Not bit-exact by design: the share's rows are summed apart and added after the working GPU's, and cuBLAS may pick other
kernels on the other GPU. The KL is that of any last-bit change in a 2K prefill on this model (the sub-batch control
above: routing near-ties flip). MAYA_GLM_PREFILL_CALC_CHECK=1 over four prompts (168 helped layers): where the
RTX 3060 computes for the RTX 3090 (the lightest experts, the tensor-core kernels) its sums are bit-identical to the
3090's own (100 layers, every value equal); where the 3090 computes for the 3060 (the most routed, cuBLAS) rel. L2
3.5e-5 on average, 8.1e-5 at most. Off, the token path and the prompt path are unchanged: the scorer through the
one-token path KL 0.000000 against v1.1.15 with the CPU lane off and on, through the prompt path 0.000000 (lane off).

Memory: nvidia-smi every 2 s through all four runs - the same peaks off and on (RTX 3090 23,601 MiB, RTX 3060
11,467 MiB of 12,288). Pinned RAM: +128 MB a GPU at 8K chunks (the sum), the routes, x made portable.

With the CPU lane on, the prompt's CPU share plan learns from the copy times, so even v1.1.15 is not repeatable from
start to start through the prompt path (against its own dump: KL 0.0163); this branch off 0.0154, on 0.0158.

Not compiled for HIP here (every CUDA call it adds has its mapping in hip_compat/cuda_runtime.h).

🤖 Generated with Claude Code


🔄 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/270 **Author:** [@sociolog](https://github.com/sociolog) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/20/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `prompt-help` --- ### 📝 Commits (1) - [`e5a25a7`](https://github.com/mw00/project-maya/commit/e5a25a7165865dbfa7f586224f478d1dbf2a4885) GLM prompt on a split without NVLink: the waiting GPU computes a share of the working half's staged experts over its own PCIe link (MAYA_GLM_PREFILL_CALC, off by default) ### 📊 Changes **3 files changed** (+754 additions, -144 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+1 -0) 📝 `include/strata/core/glm_model.hpp` (+5 -0) 📝 `src/core/glm_prefill.cu` (+748 -144) </details> ### 📄 Description ## What On a two-GPU layer split, a prompt of one chunk runs the halves one after the other: while the first GPU runs its layers, the second GPU and its PCIe link wait, and the other way round. When most routed experts live in the RAM tier, most of each half is the staging of those experts over the working GPU's own link (`MAYA_GLM_PREFILL_PROF=1`, a 2K prompt on an RTX 3090 + RTX 3060: `moe_staged` 67 % of each half; the two halves' stream times add up to the wall time). `MAYA_GLM_DUAL_PREFILL` (#121) puts the waiting GPU's link to work through NVLink; without peer access (GeForce cards, no NVLink) its peer copy would cross the working GPU's link anyway. #138 (a short prompt cut into one chunk per GPU, pipelined) goes after the same idle GPU, but where most experts come from RAM each extra chunk stages them again: on the machine below it is 3-23 % slower from 1K to 7K tokens (`MAYA_GLM_PREFILL_SHORT=1`, one run). `MAYA_GLM_PREFILL_CALC=1` (off by default): the waiting GPU **computes** a share of each MoE layer's RAM-tier experts itself - their weights over **its own** PCIe link from the working GPU's pinned RAM tier, the chunk's inputs and routes over the host to it, and the weighted sum of its rows back over the host, added into the layer's output after the combine. Both links stream at once. - **One code path for the expert products**: the EXL3 products (tensor-core kernels for the lightly routed experts, reconstruct + cuBLAS for the rest) move out of `prefill_half`'s lambdas into file-level functions on an explicit lane (stream, cuBLAS handle, weight scratch, x, row tokens, output window) - unchanged, operation for operation - so the waiting GPU computes exactly what the working GPU would. - **The plan** splits the staged RAM-tier experts three ways: the CPU lane's share as before (its PCIe estimate scaled by the share the other GPU takes), then a learned share for the waiting GPU (the lightest experts when it has fewer multiprocessors, else the most routed), the rest on the working GPU. The waiting GPU's rows go last in the sorted order; the working GPU never computes them. - **x early**: the FFN input goes down right after the hyper-connection read (the CPU lane's own early copy, made portable) and up the waiting GPU's link while the working GPU runs the shared expert and the router; the routes go into mapped memory with the counts (no copy engine). - **The waiting GPU's work** goes onto its streams from a host thread of its own: its plan up, the share's weights into a ring of 3 groups of 4 slots, the same products, its window added into a zeroed sum (`moe_combine_add`, route order), the sum down in 4 pieces; the working GPU uploads each piece as it lands (after the CPU rows' upload) into the tail of `OUTPc` (the CPU rows are capped to leave the chunk's rows there). - **No new VRAM**: the waiting GPU's buffers are carved from its own prompt carve, which is idle until its half (`calc_carve`; the ring drops to 2 groups if it must, else the mode stays off for that prompt and says so). Pinned: a chunk's sum (T x n_embd floats) a GPU, the routes, x made portable. - **The order guards**: at every half's start each part's copy / KV / x streams wait for its compute stream, so the waiting GPU's copies never land in a carve still in use and a part's own half never starts its copies while its share of the other half still reads that carve; a part whose carve held a share sets its MMQ row ids again. - **The balance**: each helped layer's two lanes (this link's last staged copy; the other GPU's sum on the host plus its way up) are read at the next one, and the share is nudged until they end together (`MAYA_GLM_PREFILL_CALC_SHARE` fixes it). `MAYA_GLM_PREFILL_TRACE=1` prints both lane ends per layer, `MAYA_GLM_PREFILL_VERBOSE=1` the experts and rows the waiting GPU computed and the shares. - Not with `MAYA_GLM_DUAL_PREFILL` (where peer access works that one wins), not in the pipeline (prompts of several chunks keep both GPUs busy already), EXL3 experts only (an MMQ pack keeps the path as before). - `MAYA_GLM_PREFILL_CALC_CHECK=1` (debug, synchronous): the working GPU computes the share again and prints how far the two sums differ, layer by layer. ## Checked turboderp's GLM-5.3-Flash `sc_3.10bpw` on RTX 3090 + RTX 3060 (PCIe 4.0 x8 each, no NVLink), Ryzen 9 5900X, 128 GB, layers [0, 28) / [28, 45), most routed experts in the RAM tier (`MAYA_GLM_RAM_RESIDENT=1`), the CPU lane on. **Prompt time** (fresh prompts, two each, one engine start a run, a quiet machine; off / on / off / on interleaved): | Prompt | off | `MAYA_GLM_PREFILL_CALC=1` | time | | --- | ---: | ---: | ---: | | 512 tokens | 5,249 ms = 98 tok/s | 3,544 ms = 144 tok/s | -32.5 % | | 1,024 | 6,595 ms = 155 tok/s | 4,471 ms = 229 tok/s | -32.2 % | | 2,048 | 8,396 ms = 244 tok/s | 5,869 ms = 349 tok/s | -30.1 % | | 4,096 | 11,636 ms = 352 tok/s | 8,744 ms = 468 tok/s | -24.9 % | | 7,168 | 16,108 ms = 445 tok/s | 12,868 ms = 557 tok/s | -20.1 % | (The mean of 4 prompts an arm; each arm's runs within 1 % of each other, the arms' ranges apart at every size. v1.1.15 itself in the same series: the same as off, within 1 %.) The learned shares settle at 0.51-0.55; with `MAYA_GLM_PREFILL_TRACE=1` a layer's two lanes end within a few ms of each other. Longer prompts gain less: their experts' compute and the attention grow with the tokens while the staged bytes stay about the same. **Answers**: the scorer with its context through the prompt path (`MAYA_GLM_SCORE_PREFILL=1`: 2,048 tokens of held-out prose as one chunk through both halves, the next 650 scored token by token), CPU lane off, against v1.1.15: | Build / setting | KL | max | same top token | | --- | ---: | ---: | ---: | | v1.1.15 again | 0.000000 | 0.0000 | 100.00 % | | this branch, off | 0.000000 | 0.0000 | 100.00 % | | this branch, `MAYA_GLM_PREFILL_CALC=1` | 0.012616 | 0.1846 | 95.69 % | | v1.1.15, `MAYA_GLM_PREFILL_SUB=512` (only the mixers' blocking changes) | 0.013763 | 0.4297 | 95.23 % | Not bit-exact by design: the share's rows are summed apart and added after the working GPU's, and cuBLAS may pick other kernels on the other GPU. The KL is that of any last-bit change in a 2K prefill on this model (the sub-batch control above: routing near-ties flip). `MAYA_GLM_PREFILL_CALC_CHECK=1` over four prompts (168 helped layers): where the RTX 3060 computes for the RTX 3090 (the lightest experts, the tensor-core kernels) its sums are bit-identical to the 3090's own (100 layers, every value equal); where the 3090 computes for the 3060 (the most routed, cuBLAS) rel. L2 3.5e-5 on average, 8.1e-5 at most. Off, the token path and the prompt path are unchanged: the scorer through the one-token path KL 0.000000 against v1.1.15 with the CPU lane off and on, through the prompt path 0.000000 (lane off). **Memory**: nvidia-smi every 2 s through all four runs - the same peaks off and on (RTX 3090 23,601 MiB, RTX 3060 11,467 MiB of 12,288). Pinned RAM: +128 MB a GPU at 8K chunks (the sum), the routes, x made portable. With the CPU lane on, the prompt's CPU share plan learns from the copy times, so even v1.1.15 is not repeatable from start to start through the prompt path (against its own dump: KL 0.0163); this branch off 0.0154, on 0.0158. Not compiled for HIP here (every CUDA call it adds has its mapping in `hip_compat/cuda_runtime.h`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:25:26 +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#438
No description provided.