[PR #121] [MERGED] GLM prompt: dual-link staging - the waiting GPU of a two-GPU split stages every second expert over its own PCIe link + NVLink (opt-in) #353

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/121
Author: @q8atnight
Created: 10/12/2026
Status: ✅ Merged
Merged: 10/14/2026
Merged by: @mw00

Base: main ← Head: pr/dual-prefill


📝 Commits (4)

  • 511e5d1 GLM prompt: dual-link staging - in a two-GPU split's serial prompt the waiting GPU stages every second expert through its own PCIe link + NVLink (STRATA_GLM_DUAL_PREFILL)
  • c309d0e hip_compat: cudaErrorPeerAccessAlreadyEnabled (dual-link prompt staging)
  • 2d922b0 docs/SETTINGS.md: STRATA_GLM_DUAL_PREFILL
  • 75dc842 bench/p2p_fetch_probe.cu: what two GPUs' PCIe links + NVLink deliver into one GPU (copy kernels, DMA, two-hop)

📊 Changes

5 files changed (+245 additions, -0 deletions)

View changed files

➕ bench/p2p_fetch_probe.cu (+140 -0)
📝 docs/SETTINGS.md (+1 -0)
📝 include/strata/core/glm_model.hpp (+2 -0)
📝 include/strata/hip_compat/cuda_runtime.h (+1 -0)
📝 src/core/glm_prefill.cu (+101 -0)

📄 Description

Why

A prompt of up to one chunk (--prefill, 32K here) runs the split's two halves one after the other. While one GPU
works through its layers, the other GPU and its PCIe link wait. On this box, staging the experts that aren't in VRAM
is about two thirds of the prompt time for short and mid-size prompts (STRATA_GLM_PREFILL_PROF, 1K + 4K prompts:
moe_staged 65.7 % / 64.6 % of the two GPUs' stream time). So the prompt is bound by one x8 link.

What

STRATA_GLM_DUAL_PREFILL=1 (off by default). It runs only on the serial path of prefill_run (one chunk, or
STRATA_GLM_PREFILL_SERIAL) with two parts that can reach each other's memory.

  • Every second expert of a staging group (the odd slots j) goes from the host into the waiting GPU's own gbuf
    slot (b, j) over its own PCIe link (that GPU's copy stream). From there it goes peer to peer into the working
    GPU's group buffer (cudaMemcpyPeerAsync, over NVLink). The working GPU waits for that copy (ev_hready[b], an
    event on the helper's device) and for its own copy before run_set.
  • Before a half starts, the helper's copy stream waits for all the work already queued on its compute stream
    (ev_hidle), so its gbuf is free.
  • dual_prefill_ready() runs once: it enables peer access both ways and creates the events. If anything fails, the
    prompt stages as before.
  • The pipelined path (several chunks) is unchanged. There, both links already carry their own chunks: 64K serial
    with this on is 1168 tokens/s, against 1468 pipelined.
  • I tried splitting the prestage copies the same way: no further gain, so they are not in this PR.

Why two hops: a direct H2D cudaMemcpyAsync into GPU 0 issued on a GPU 1 stream still rides GPU 0's link
(measured 13.3 GB/s, the same as one link). Staging in GPU 1 and then a peer copy gave 20.8 GB/s into GPU 0
(bench/p2p_fetch_probe.cu, below). Without NVLink the peer copy would cross GPU 0's link anyway, so expect no gain
on PCIe-only peer access.

Exactness

STRATA_GLM_SCORE=3000 + STRATA_GLM_SCORE_PREFILL=1 (a 3000-token context through the prompt path, then 400 scored
tokens), reference = unmodified v1.0.34: KL 0.000000, same top token 100 %. The same holds with
STRATA_GLM_PREFILL_CPU=0.

Caveat: the prompt's CPU-share plan learns from the measured copy times. Faster copies can move different experts to
the CPU, which changes the last bits, as any timing change does. One experimental variant here (prestage split too)
showed KL 0.0016 that way. With the CPU share off, that variant was exact as well.

Speed

Maya-M, 2x RTX 3090 (PCIe 4.0 x8 each, NVLink bridge), Ryzen 9 3950X, 128 GB DDR4-3600, RAM-resident. Fresh text,
no conversation reuse; each length runs twice and the second run counts. Tokens/s:

prompt before after
1K 283 / 284 362 +28 %
4K 622 / 625 772 +24 %
16K 1034 / 1036 1142 +10 %
64K (pipelined) 1469 / 1472 1468 ±0

Probe of the links (engine stopped, 16 x 8.6 MB experts into GPU 0):

path GB/s
GPU 0 copy kernel / DMA on its own link 13.4
DMA host -> GPU 0 issued on GPU 1's stream 13.3
half own link + half via GPU 1 staging + peer copy (DMA) 20.8
copy kernels on both GPUs, GPU 1 writing GPU 0 peer to peer 26.6

HIP: one error name mapped (cudaErrorPeerAccessAlreadyEnabled); tools/check_hip_compat.py passes. Not run on AMD
or Windows here. Docs: a row in docs/SETTINGS.md.


🔄 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/121 **Author:** [@q8atnight](https://github.com/q8atnight) **Created:** 10/12/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `pr/dual-prefill` --- ### 📝 Commits (4) - [`511e5d1`](https://github.com/mw00/project-maya/commit/511e5d18ee09741d32a7e317befd48a38b242dee) GLM prompt: dual-link staging - in a two-GPU split's serial prompt the waiting GPU stages every second expert through its own PCIe link + NVLink (STRATA_GLM_DUAL_PREFILL) - [`c309d0e`](https://github.com/mw00/project-maya/commit/c309d0eb7e6f6eb8f72e1353578b3c36d0467740) hip_compat: cudaErrorPeerAccessAlreadyEnabled (dual-link prompt staging) - [`2d922b0`](https://github.com/mw00/project-maya/commit/2d922b0a0bfc1f83d05087ff4c75f6ff57d12a0a) docs/SETTINGS.md: STRATA_GLM_DUAL_PREFILL - [`75dc842`](https://github.com/mw00/project-maya/commit/75dc8426ac4d8a517c65b09808ca6a632180ab00) bench/p2p_fetch_probe.cu: what two GPUs' PCIe links + NVLink deliver into one GPU (copy kernels, DMA, two-hop) ### 📊 Changes **5 files changed** (+245 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `bench/p2p_fetch_probe.cu` (+140 -0) 📝 `docs/SETTINGS.md` (+1 -0) 📝 `include/strata/core/glm_model.hpp` (+2 -0) 📝 `include/strata/hip_compat/cuda_runtime.h` (+1 -0) 📝 `src/core/glm_prefill.cu` (+101 -0) </details> ### 📄 Description ## Why A prompt of up to one chunk (`--prefill`, 32K here) runs the split's two halves one after the other. While one GPU works through its layers, the other GPU and its PCIe link wait. On this box, staging the experts that aren't in VRAM is about two thirds of the prompt time for short and mid-size prompts (`STRATA_GLM_PREFILL_PROF`, 1K + 4K prompts: `moe_staged` 65.7 % / 64.6 % of the two GPUs' stream time). So the prompt is bound by one x8 link. ## What `STRATA_GLM_DUAL_PREFILL=1` (off by default). It runs only on the serial path of `prefill_run` (one chunk, or `STRATA_GLM_PREFILL_SERIAL`) with two parts that can reach each other's memory. - Every second expert of a staging group (the odd slots `j`) goes from the host into the **waiting** GPU's own `gbuf` slot `(b, j)` over its own PCIe link (that GPU's `copy` stream). From there it goes peer to peer into the working GPU's group buffer (`cudaMemcpyPeerAsync`, over NVLink). The working GPU waits for that copy (`ev_hready[b]`, an event on the helper's device) and for its own copy before `run_set`. - Before a half starts, the helper's copy stream waits for all the work already queued on its compute stream (`ev_hidle`), so its `gbuf` is free. - `dual_prefill_ready()` runs once: it enables peer access both ways and creates the events. If anything fails, the prompt stages as before. - The pipelined path (several chunks) is unchanged. There, both links already carry their own chunks: 64K serial with this on is 1168 tokens/s, against 1468 pipelined. - I tried splitting the prestage copies the same way: no further gain, so they are not in this PR. Why two hops: a direct H2D `cudaMemcpyAsync` into GPU 0 issued on a GPU 1 stream still rides GPU 0's link (measured 13.3 GB/s, the same as one link). Staging in GPU 1 and then a peer copy gave 20.8 GB/s into GPU 0 (`bench/p2p_fetch_probe.cu`, below). Without NVLink the peer copy would cross GPU 0's link anyway, so expect no gain on PCIe-only peer access. ## Exactness `STRATA_GLM_SCORE=3000` + `STRATA_GLM_SCORE_PREFILL=1` (a 3000-token context through the prompt path, then 400 scored tokens), reference = unmodified v1.0.34: **KL 0.000000, same top token 100 %**. The same holds with `STRATA_GLM_PREFILL_CPU=0`. Caveat: the prompt's CPU-share plan learns from the measured copy times. Faster copies can move different experts to the CPU, which changes the last bits, as any timing change does. One experimental variant here (prestage split too) showed KL 0.0016 that way. With the CPU share off, that variant was exact as well. ## Speed Maya-M, 2x RTX 3090 (PCIe 4.0 x8 each, NVLink bridge), Ryzen 9 3950X, 128 GB DDR4-3600, RAM-resident. Fresh text, no conversation reuse; each length runs twice and the second run counts. Tokens/s: | prompt | before | after | | |---:|---:|---:|---:| | 1K | 283 / 284 | 362 | +28 % | | 4K | 622 / 625 | 772 | +24 % | | 16K | 1034 / 1036 | 1142 | +10 % | | 64K (pipelined) | 1469 / 1472 | 1468 | ±0 | Probe of the links (engine stopped, 16 x 8.6 MB experts into GPU 0): | path | GB/s | |---|---:| | GPU 0 copy kernel / DMA on its own link | 13.4 | | DMA host -> GPU 0 issued on GPU 1's stream | 13.3 | | half own link + half via GPU 1 staging + peer copy (DMA) | 20.8 | | copy kernels on both GPUs, GPU 1 writing GPU 0 peer to peer | 26.6 | HIP: one error name mapped (`cudaErrorPeerAccessAlreadyEnabled`); `tools/check_hip_compat.py` passes. Not run on AMD or Windows here. Docs: a row in `docs/SETTINGS.md`. --- <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:35 +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#353
No description provided.