[PR #5002] [Engine] prompt path: opt-in dual data-parallel prompt read for two-GPU layer splits (STRATA_DP_PREFILL) #5284

Open
opened 2026-11-07 16:34:03 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5002
Author: @orochifj
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: pr/dp-prompt-path


📝 Commits (4)

  • 634dc2f [Engine] prompt path: opt-in dual data-parallel prompt read for two-GPU layer splits (STRATA_DP_PREFILL)
  • e64a076 [Engine] prompt path: the DP read stays off with --draft dflash2
  • 8b0c63e docs: the DP prompt path's limits - checkpoints, DFlash2, and what STRATA_KV_HOST_DMA does on CUDA
  • d4fbe2d [Engine] prompt path: the DP read stays off when the spill walk trims the stage weights

📊 Changes

8 files changed (+603 additions, -28 deletions)

View changed files

📝 docs/MULTI_GPU.md (+53 -0)
📝 include/strata/core/layer.hpp (+3 -1)
📝 include/strata/core/session.hpp (+3 -1)
📝 include/strata/prefill/prefill.hpp (+29 -0)
📝 src/core/layer.cpp (+2 -2)
📝 src/core/session.cpp (+2 -2)
📝 src/prefill/prefill.cpp (+337 -22)
📝 src/program/generate.cpp (+174 -0)

📄 Description

Problem and result

On a two-GPU layer split a long prompt is read by the layer pipeline, and on 24 GB cards the layer-major walk does not run (2x RTX 3090: no VRAM for a super-chunk, 587 MiB free). With STRATA_DP_PREFILL=1 both cards read the prompt at once: each runs every layer on every other chunk and hands each layer's state to the other card. Measured on 2x RTX 3090: prompts of 12K-123K tokens read 16-67 % faster (engine timing, medians of three alternating rounds). The cost: the extra sessions take 308 expert-cache slots a card, so prompts DP does not take (1.5K-4K) read up to 4 % slower. Unset, nothing changes.

Rebased onto v0.2.11 on 2026-11-06 (engine 0.1.57). One commit is new: 0.2.11's layer-split spill walk can trim a short card's dense weights by itself, and the DP read now stays off for that trim too. Since v0.2.10 it also stays off with --draft dflash2, and the limits below take in what the review found. The speed table was measured on the v0.2.9 base and has not been re-run. On 0.2.11 we ran a local build that carries this path plus our own changes. On the same 2x RTX 3090 it read 43K-123K prompts at the same speed as on 0.2.10 (5,118-5,312 against 5,158-5,347 tok/s).

Opened as a draft so the code can be read beside #4875: it waits for your scope decision there and is not asking to be merged before that.

#4875: the proposal, the scope of this first PR, and rafatxf's findings on a low-RAM 2x RTX 2080 Ti box. The design is nicejunjie's (nicejunjie/Strata-rdna3, MIT); he asked to be co-author, and the commit carries his Co-authored-by. rafatxf has the peer-slot residency for low-RAM boxes and DP with stage trim on rafatxf/Strata dp-followups (one commit each; rebased onto the v0.2.10 head of this PR, so it needs a rebase onto this one). lyesrock ran it on 2x Tesla P40 without peer access: DP linked and read 16K prompts about 19 % faster once warm.

Approach

  • Foreign sessions. Each card also carves a session for the layers it does not own in decode. A streamed QSA layer's K/V stay in the owner's host copy, which both cards append to, so the foreign session pins no copy of its own: session_init / qsa_state_init take kv_host (default true). #4875 measured 2.3 GiB of pinned RAM thrown away at 384K without this, and a 13-19 % decode loss on a 56 GB box. The stage's foreign session holds layer 1, so it gets its own PLE run.
  • The plan. Prefill::run_dp cuts a segment into an even number of balanced chunks (multiples of 256, at most the prompt chunk). The last one runs on the drafter's card and has at least 4224 tokens. run_impl walks the plan's boundaries in place of its per-run chunk (step_at / next_mine), skips the other card's chunks, and bypasses the layer-major walk.
  • The hand-off. After a layer's attention half, the card that ran chunk k copies that layer's state to the other card with cudaMemcpyPeerAsync on its stream and records a per-layer event: the GDN state, the chunk's indexer rows, the indexer tail, dead slot and block position, and the PLE history at layer 1. Chunk k+1 waits for it, on the host through a condition variable and on the device with cudaStreamWaitEvent. The foreign sessions start each prompt from the owners' state at its start position.
  • The server. A segment of at least STRATA_DP_MIN (8000) tokens whose plan qualifies is read by DP, after a head up to the next K/V block boundary. Anything else, and a continuation that starts inside a K/V block, goes to the layer pipeline as before.
  • When it stays off, said once at startup: not exactly two GPUs in a layer split, --batch, --peer-device, stage trim (asked for, or the spill walk's on a short card), --draft dflash2 (its prompt taps are kept per card, while a DP read runs every layer on one card), K/V not streamed or STRATA_KV_HOST_DMA not 1, or not every expert in RAM (--mmap-experts, --resident-experts, a file-backed arena that hands the GPU-held experts back). A DP read streams the experts the other card caches, which there would come from the model file (#4875: 82 GB read for a 16K prompt).
  • docs/MULTI_GPU.md: the switch, how it works, its limits and the measurements.

Validation

Passed

  • Builds at this commit (on v0.2.11):
    • CUDA 13.0 for 86-real;86-virtual with the Dockerfile's CMake options plus -DSTRATA_BUILD_TESTS=ON -DSTRATA_BUILD_CONVERSATION_TESTS=ON: engine and conversation_validation_test (972 host-only checks passed).
    • HIP: -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DCMAKE_HIP_ARCHITECTURES=gfx1201 in a ROCm 10.1 (HIP 7.16) container: the engine builds and links.
    • No compiler warnings on the changed lines in either build.
  • A/B on the CUDA build of the v0.2.9 base (before the rebase), in the v0.2.9 image with its own serve/server.py, 2026-11-02:
    • Rig: 2x RTX 3090 24 GB at 250 W, PCIe 4.0 x16, peer access on, EPYC 7452, 256 GB DDR4, Linux 6.8, NVIDIA 610.57.04.
    • Model and config: Swift-1.5 Qwen3.8-Flash-Next IQ4_XS, layer split auto (24 / 24), --max-context 524288 --rope-scaling yarn --rope-scale 2 --kv int8 --kv-resident 32768 --spec 4 --spec-min-p 0.5 --pipeline-windows 2 --pcie-frac 0, env STRATA_KV_HOST_DMA=1 STRATA_PREFILL_AUTO_MAX=16384 STRATA_HC_Q8=1 STRATA_ROUTE_TAIL_SKIP=0 STRATA_DECODE_TIMING=1 in both arms. The only change between arms is STRATA_DP_PREFILL=1.
    • Method: each arm is a fresh engine start, a 64-token warm-up, then fresh salted filler prompts, nothing reused, max_tokens 1. Two reads per size up to 12K, one per size from 19K, three rounds ordered A B / B A / A B.
    • Numbers are the engine's strata serve: prompt N tokens = 0 reused + N read in X ms line, tokens/s, median (min-max):
prompt tokens A: unset B: STRATA_DP_PREFILL=1 B vs A
1,471 863 (862-865) 831 (830-833) -3.7 % (not read by DP)
3,844 1,948 (1,943-1,952) 1,891 (1,888-1,897) -3.0 % (not read by DP)
7,901 2,244 (2,233-2,261) 2,240 (2,232-2,244) -0.2 % (not read by DP)
11,996 2,315 (2,244-2,386) 3,248 (3,133-3,361) +40 %
19,206 2,312 (2,311-2,337) 3,860 (3,854-3,882) +67 %
43,036 3,422 (3,421-3,434) 4,453 (4,445-4,456) +30 %
88,907 4,005 (3,990-4,044) 4,793 (4,791-4,797) +20 %
122,507 4,082 (4,079-4,112) 4,724 (4,711-4,734) +16 %
  • VRAM: the expert cache has 6,370 / 6,169 slots without DP and 6,062 / 5,861 with it, 308 a card or about 0.76 GiB; that is the short prompts' cost above. Pinned RAM: the DP startup line reports the K/V host copies at 6.19 GiB with the foreign sessions carved, the owners' two copies of 3.09 GiB; without kv_host false they would add their own.
  • Needles read through DP: 88,907 and 122,507 tokens, both PASS (18.2 s / 26.1 s).
  • Determinism: the 123K prompt read through DP in two fresh engine starts gave byte-identical STRATA_QSA_DUMP files (1,622,817,216 bytes, sha1 a4cb2cf7). Its bits differ from the layer pipeline's, because the chunk boundaries differ.
  • Fallback: STRATA_DP_PREFILL=1 with --mmap-experts logs STRATA_DP_PREFILL is off: a DP read streams the experts the other GPU caches, ... and serves through the layer pipeline.
  • No Xid or other NVRM messages in the kernel log during the runs.

Measured limit (not a failure): the drafter gap. Only the drafter card's chunks reach the draft layer, so after a DP read its cells for the other card's chunks are not filled. Test: a ~48K-token prompt of C++ source and an answer that copies 30 of its lines, greedy, six requests per cell:

copied lines from layer pipeline: decode / drafts accepted DP: decode / drafts accepted
the drafter card's last chunk 197 tok/s / 98.0 % 195 tok/s / 97.1 %
the other card's chunk 176 tok/s / 97.0 % 165 tok/s / 91.6 %

The tokens are the target's either way. Feeding the other card's final rows to the drafter would close this gap; it is left for a follow-up.

Failed: none observed.

Not run

  • gfx906 (STRATA_HIP_GFX906): every changed file compiles, but the link stops in src/core/dflash2.cpp, which this PR does not touch: hip_compat/strata_hip.h has no cudaDeviceGetStreamPriorityRange / cudaStreamCreateWithPriority. It fails the same way on main.
  • DP on AMD hardware: the design comes from 2x RX 7900 XTX in nicejunjie's fork, but this port was only run on the two RTX 3090s here (one AMD card on this box).
  • SYCL and Metal: not touched. Windows: not run.

Limits

  • Not with --batch slots yet, not with stage trim (rafatxf's follow-up), and off with --draft dflash2. Two cards only.
  • The drafter gap above.
  • A DP read keeps only the checkpoint at the end of the prompt: run_dp clears on_stage_chunk, which a layer split's mid-prompt checkpoints come from (rafatxf: 1 checkpoint against the pipeline's 4 on a 64K read). A turn that extends the conversation is unaffected; an edited earlier message, a regenerate or a compaction reads from the start again.
  • STRATA_KV_HOST_DMA=1 is one of DP's conditions. On CUDA it selects nothing else (its K/V append, one DMA a chunk to the host copy, is HIP-only), so it costs nothing where DP does not run.
  • One rig and one pack measured here.

Prepared with AI assistance (Claude); every measurement above comes from the runs described, and the logs are available.

🤖 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/Niko1221/Strata/pull/5002 **Author:** [@orochifj](https://github.com/orochifj) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/dp-prompt-path` --- ### 📝 Commits (4) - [`634dc2f`](https://github.com/Niko1221/Strata/commit/634dc2f9a8603a2763f4854223e237ec38c3813e) [Engine] prompt path: opt-in dual data-parallel prompt read for two-GPU layer splits (STRATA_DP_PREFILL) - [`e64a076`](https://github.com/Niko1221/Strata/commit/e64a07657d0d11703789a6513f50c16696d9dc4f) [Engine] prompt path: the DP read stays off with --draft dflash2 - [`8b0c63e`](https://github.com/Niko1221/Strata/commit/8b0c63e6ed2265fc313973d05b8806b908bee1f0) docs: the DP prompt path's limits - checkpoints, DFlash2, and what STRATA_KV_HOST_DMA does on CUDA - [`d4fbe2d`](https://github.com/Niko1221/Strata/commit/d4fbe2d34fbcf10436705577e25159efc442ffc1) [Engine] prompt path: the DP read stays off when the spill walk trims the stage weights ### 📊 Changes **8 files changed** (+603 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `docs/MULTI_GPU.md` (+53 -0) 📝 `include/strata/core/layer.hpp` (+3 -1) 📝 `include/strata/core/session.hpp` (+3 -1) 📝 `include/strata/prefill/prefill.hpp` (+29 -0) 📝 `src/core/layer.cpp` (+2 -2) 📝 `src/core/session.cpp` (+2 -2) 📝 `src/prefill/prefill.cpp` (+337 -22) 📝 `src/program/generate.cpp` (+174 -0) </details> ### 📄 Description ### Problem and result On a two-GPU layer split a long prompt is read by the layer pipeline, and on 24 GB cards the layer-major walk does not run (2x RTX 3090: `no VRAM for a super-chunk, 587 MiB free`). With `STRATA_DP_PREFILL=1` both cards read the prompt at once: each runs every layer on every other chunk and hands each layer's state to the other card. Measured on 2x RTX 3090: prompts of 12K-123K tokens read **16-67 % faster** (engine timing, medians of three alternating rounds). The cost: the extra sessions take 308 expert-cache slots a card, so prompts DP does not take (1.5K-4K) read up to 4 % slower. Unset, nothing changes. **Rebased onto v0.2.11 on 2026-11-06** (engine 0.1.57). One commit is new: 0.2.11's layer-split spill walk can trim a short card's dense weights by itself, and the DP read now stays off for that trim too. Since v0.2.10 it also stays off with `--draft dflash2`, and the limits below take in what the review found. The speed table was measured on the v0.2.9 base and has not been re-run. On 0.2.11 we ran a local build that carries this path plus our own changes. On the same 2x RTX 3090 it read 43K-123K prompts at the same speed as on 0.2.10 (5,118-5,312 against 5,158-5,347 tok/s). ### Related discussion **Opened as a draft so the code can be read beside #4875: it waits for your scope decision there and is not asking to be merged before that.** #4875: the proposal, the scope of this first PR, and rafatxf's findings on a low-RAM 2x RTX 2080 Ti box. The design is nicejunjie's ([nicejunjie/Strata-rdna3](https://github.com/nicejunjie/Strata-rdna3), MIT); he asked to be co-author, and the commit carries his `Co-authored-by`. rafatxf has the peer-slot residency for low-RAM boxes and DP with stage trim on [rafatxf/Strata `dp-followups`](https://github.com/rafatxf/Strata/tree/dp-followups) (one commit each; rebased onto the v0.2.10 head of this PR, so it needs a rebase onto this one). lyesrock ran it on 2x Tesla P40 without peer access: DP linked and read 16K prompts about 19 % faster once warm. ### Approach - **Foreign sessions.** Each card also carves a session for the layers it does not own in decode. A streamed QSA layer's K/V stay in the owner's host copy, which both cards append to, so the foreign session pins no copy of its own: `session_init` / `qsa_state_init` take `kv_host` (default true). #4875 measured 2.3 GiB of pinned RAM thrown away at 384K without this, and a 13-19 % decode loss on a 56 GB box. The stage's foreign session holds layer 1, so it gets its own PLE run. - **The plan.** `Prefill::run_dp` cuts a segment into an even number of balanced chunks (multiples of 256, at most the prompt chunk). The last one runs on the drafter's card and has at least 4224 tokens. `run_impl` walks the plan's boundaries in place of its per-run chunk (`step_at` / `next_mine`), skips the other card's chunks, and bypasses the layer-major walk. - **The hand-off.** After a layer's attention half, the card that ran chunk k copies that layer's state to the other card with `cudaMemcpyPeerAsync` on its stream and records a per-layer event: the GDN state, the chunk's indexer rows, the indexer tail, dead slot and block position, and the PLE history at layer 1. Chunk k+1 waits for it, on the host through a condition variable and on the device with `cudaStreamWaitEvent`. The foreign sessions start each prompt from the owners' state at its start position. - **The server.** A segment of at least `STRATA_DP_MIN` (8000) tokens whose plan qualifies is read by DP, after a head up to the next K/V block boundary. Anything else, and a continuation that starts inside a K/V block, goes to the layer pipeline as before. - **When it stays off**, said once at startup: not exactly two GPUs in a layer split, `--batch`, `--peer-device`, stage trim (asked for, or the spill walk's on a short card), `--draft dflash2` (its prompt taps are kept per card, while a DP read runs every layer on one card), K/V not streamed or `STRATA_KV_HOST_DMA` not 1, or not every expert in RAM (`--mmap-experts`, `--resident-experts`, a file-backed arena that hands the GPU-held experts back). A DP read streams the experts the other card caches, which there would come from the model file (#4875: 82 GB read for a 16K prompt). - `docs/MULTI_GPU.md`: the switch, how it works, its limits and the measurements. ### Validation **Passed** - Builds at this commit (on v0.2.11): - CUDA 13.0 for `86-real;86-virtual` with the Dockerfile's CMake options plus `-DSTRATA_BUILD_TESTS=ON -DSTRATA_BUILD_CONVERSATION_TESTS=ON`: engine and `conversation_validation_test` (972 host-only checks passed). - HIP: `-DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DCMAKE_HIP_ARCHITECTURES=gfx1201` in a ROCm 10.1 (HIP 7.16) container: the engine builds and links. - No compiler warnings on the changed lines in either build. - A/B on the CUDA build of the v0.2.9 base (before the rebase), in the v0.2.9 image with its own `serve/server.py`, 2026-11-02: - Rig: 2x RTX 3090 24 GB at 250 W, PCIe 4.0 x16, peer access on, EPYC 7452, 256 GB DDR4, Linux 6.8, NVIDIA 610.57.04. - Model and config: Swift-1.5 Qwen3.8-Flash-Next IQ4_XS, layer split auto (24 / 24), `--max-context 524288 --rope-scaling yarn --rope-scale 2 --kv int8 --kv-resident 32768 --spec 4 --spec-min-p 0.5 --pipeline-windows 2 --pcie-frac 0`, env `STRATA_KV_HOST_DMA=1 STRATA_PREFILL_AUTO_MAX=16384 STRATA_HC_Q8=1 STRATA_ROUTE_TAIL_SKIP=0 STRATA_DECODE_TIMING=1` in both arms. The only change between arms is `STRATA_DP_PREFILL=1`. - Method: each arm is a fresh engine start, a 64-token warm-up, then fresh salted filler prompts, nothing reused, `max_tokens` 1. Two reads per size up to 12K, one per size from 19K, three rounds ordered A B / B A / A B. - Numbers are the engine's `strata serve: prompt N tokens = 0 reused + N read in X ms` line, tokens/s, median (min-max): | prompt tokens | A: unset | B: `STRATA_DP_PREFILL=1` | B vs A | |---|---|---|---| | 1,471 | 863 (862-865) | 831 (830-833) | -3.7 % (not read by DP) | | 3,844 | 1,948 (1,943-1,952) | 1,891 (1,888-1,897) | -3.0 % (not read by DP) | | 7,901 | 2,244 (2,233-2,261) | 2,240 (2,232-2,244) | -0.2 % (not read by DP) | | 11,996 | 2,315 (2,244-2,386) | 3,248 (3,133-3,361) | +40 % | | 19,206 | 2,312 (2,311-2,337) | 3,860 (3,854-3,882) | +67 % | | 43,036 | 3,422 (3,421-3,434) | 4,453 (4,445-4,456) | +30 % | | 88,907 | 4,005 (3,990-4,044) | 4,793 (4,791-4,797) | +20 % | | 122,507 | 4,082 (4,079-4,112) | 4,724 (4,711-4,734) | +16 % | - VRAM: the expert cache has 6,370 / 6,169 slots without DP and 6,062 / 5,861 with it, 308 a card or about 0.76 GiB; that is the short prompts' cost above. Pinned RAM: the DP startup line reports the K/V host copies at 6.19 GiB with the foreign sessions carved, the owners' two copies of 3.09 GiB; without `kv_host` false they would add their own. - Needles read through DP: 88,907 and 122,507 tokens, both PASS (18.2 s / 26.1 s). - Determinism: the 123K prompt read through DP in two fresh engine starts gave byte-identical `STRATA_QSA_DUMP` files (1,622,817,216 bytes, sha1 a4cb2cf7). Its bits differ from the layer pipeline's, because the chunk boundaries differ. - Fallback: `STRATA_DP_PREFILL=1` with `--mmap-experts` logs `STRATA_DP_PREFILL is off: a DP read streams the experts the other GPU caches, ...` and serves through the layer pipeline. - No Xid or other NVRM messages in the kernel log during the runs. **Measured limit (not a failure):** the drafter gap. Only the drafter card's chunks reach the draft layer, so after a DP read its cells for the other card's chunks are not filled. Test: a ~48K-token prompt of C++ source and an answer that copies 30 of its lines, greedy, six requests per cell: | copied lines from | layer pipeline: decode / drafts accepted | DP: decode / drafts accepted | |---|---|---| | the drafter card's last chunk | 197 tok/s / 98.0 % | 195 tok/s / 97.1 % | | the other card's chunk | 176 tok/s / 97.0 % | 165 tok/s / 91.6 % | The tokens are the target's either way. Feeding the other card's final rows to the drafter would close this gap; it is left for a follow-up. **Failed:** none observed. **Not run** - gfx906 (`STRATA_HIP_GFX906`): every changed file compiles, but the link stops in `src/core/dflash2.cpp`, which this PR does not touch: `hip_compat/strata_hip.h` has no `cudaDeviceGetStreamPriorityRange` / `cudaStreamCreateWithPriority`. It fails the same way on main. - DP on AMD hardware: the design comes from 2x RX 7900 XTX in nicejunjie's fork, but this port was only run on the two RTX 3090s here (one AMD card on this box). - SYCL and Metal: not touched. Windows: not run. ### Limits - Not with `--batch` slots yet, not with stage trim (rafatxf's follow-up), and off with `--draft dflash2`. Two cards only. - The drafter gap above. - A DP read keeps only the checkpoint at the end of the prompt: `run_dp` clears `on_stage_chunk`, which a layer split's mid-prompt checkpoints come from (rafatxf: 1 checkpoint against the pipeline's 4 on a 64K read). A turn that extends the conversation is unaffected; an edited earlier message, a regenerate or a compaction reads from the start again. - `STRATA_KV_HOST_DMA=1` is one of DP's conditions. On CUDA it selects nothing else (its K/V append, one DMA a chunk to the host copy, is HIP-only), so it costs nothing where DP does not run. - One rig and one pack measured here. Prepared with AI assistance (Claude); every measurement above comes from the runs described, and the logs are available. 🤖 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>
Sign in to join this conversation.
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
Niko1221/Strata#5284
No description provided.