[PR #2761] [CLOSED] serve: STRATA_MTP_ROOM_MIN — a long prompt takes the MTP drafter's 512 experts (decode-only) as ring #4252

Closed
opened 2026-11-07 15:34:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2761
Author: @gopinath87607
Created: 10/16/2026
Status: ❌ Closed

Base: main ← Head: prefill-decode-room


📝 Commits (3)

  • 6e48553 prefill: what only the decode needs leaves VRAM while a prompt runs, and the prestage ring takes the loan (WIP - porting mw00/project-maya#223)
  • b4642dd serve: STRATA_MTP_ROOM_MIN - a long prompt takes the MTP drafter's 512 experts (decode-only) as ring
  • 0958a68 docs: the room measured on the Q8_0 4-way - it works, and at 3k/15k it bought nothing

📊 Changes

7 files changed (+492 additions, -42 deletions)

View changed files

📝 docs/DETAILS.md (+7 -0)
➕ docs/MTP_PROMPT_ROOM.md (+146 -0)
📝 include/strata/core/mtp.hpp (+28 -0)
📝 include/strata/prefill/prefill.hpp (+11 -0)
📝 src/core/mtp.cpp (+89 -0)
📝 src/prefill/prefill.cpp (+30 -1)
📝 src/program/generate.cpp (+181 -41)

📄 Description

The MTP draft layer's 512 routed experts are read by the decode alone: record_rest is their only reader, and
every prompt pass — the capture's K/V (record_front, both prefill captures) and the prompt path's
Prefill::draft_kv — runs the layer's dense tensors and its K/V state instead. This is that block, lent to the prompt
path for as long as a prompt is read.

STRATA_MTP_ROOM_MIN=4096 strata serve --mtp rt …     # prompts of 4096 tokens or more take the room
STRATA_MTP_ROOM_MIN=0    strata serve --mtp rt …     # every prompt does
strata serve --mtp rt …                              # unset: off, and not one line of this runs

Port of the MTP half of mw00/project-maya#223
(STRATA_GLM_ROOM_MIN). The reference's other half is its DFlash drafter, which Strata does not have; what this keeps
is the mechanism, in Strata's own shape.

What it does

  1. Per request, before the prompt: the drafter's stream is synchronized, its streamed chain waited for, and the
    512 blobs are copied into pinned host memory (taken once and kept — the room opens around every long prompt, and a
    second read of the 675 MiB experts.bin per prompt is what that avoids). The device block is freed.
  2. The prompt path is laid out again, the path on the drafter's card with Prefill::set_ring_room(room): the
    room is experts_bytes / max_blob ring slots — 135 on a Q8_0 pack, 672 MiB. Those slots spill past the
    borrowed region
    , in one cudaMalloc taken after the region's own buffers: a slot at a time, 135 mallocs of
    4.98 MiB would each round up to a 2 MiB page and want 130 MiB more than the block that was freed. The loan itself
    does not move — bytes_needed cannot count the room without resizing the whole expert cache, and a spilled
    layout cannot be relaid out (relayout refuses), so the roomed request keeps its layout, exactly as
    --prefill-head-alias does.
  3. **After the prompt, before the first windowaid out as they were, the blobs are
    allocated again (cudaMalloc of the same size, then one DMA back), and the lending state is re-anchored
    (pf_parts[].first_now at the start-up regs out at, so lend marks only the slots
    the layout really covers as lent). If the block comes back at a different address, the round/step graphs are
    dropped and captured again — they are per-rad-alias` stops in that case instead
    because its verify graphs are all-or-nothinhen it happens.
  4. Guards: while the experts are out, draunch and record_rest refuse with an
    error rather than launch a graph that readso decode runs between 1 and 3 anyway: the
    room opens and closes inside one request's eaches the close — a room left open by a
    request that ended another way is closed at the start of the next one).

Files

  • **include/strata/core/mtp.hpp / src/core/, experts_resident(), experts_out(),
    experts_back(), drop_expert_graphs(), an
  • **include/strata/prefill/prefill.hpp / sret_ring_room(slots) and the ring's extra
    slots in carve (one block, past the region
  • src/program/generate.cpp — the start-uclose, and two drive-by fixes in the same
    code path (below).
  • docs/MTP_PROMPT_ROOM.md — the mechanismeasure it; docs/DETAILS.md points at it
    from the opt-in switches.

What it leaves alone

  • **Unset, the default path is byte-identical*he gate, the open, the close and the
    lend/init_prompt_paths changes are all ie; set_ring_room(0) is the default).
  • Every prompt below the threshold, every decode, and every other opt-in switch are untouched.
  • --prefill-head-alias keeps its own behaviowo are combined deliberately rather than
    serially: when both apply, the head is unloaded and the path is laid out once, with the head's bytes and the
    drafter's together, and both come back before the first window. Without that, the second rebuild would undo the
    first (and could take VRAM the head's reload needs).

Two fixes in the code this touches

  • **set_peer / set_stage_helper survive a tate inside the path's layout
    (Impl), so any sp.reset() + re-init silel-head-alias's rebuild did this every request on a rig using STRATA_PEER_PREFILL_ROWSor a layer split's helpers, and the room's rebuild would have too. Both rebuilds now call onearm_prompt_
  • STRATA_MTP_ROOM_MIN is refused, not readr (0 means "every prompt", so a typo
    would silently turn the room on for every re

Limits

  • --serve only, --mtp needed, --batch ree the solo drafter's weights, so freeing
    them under the slots would be a use-after-freason at start and exits with 2.
  • A layer split is fine (the room goes to the --mtp-first`: the first).
  • Costs: 708 MB of pinned host memory (once), 708 MB over PCIe each way per roomed request, one prompt-path rebuild
    each way, and the roomed request's layout isshort prompt.

Measured

Q8_0 4-way, 2026-10-16: 2× RTX 3060 + 2× RTX 5060, layer split auto, Qwen3.8-Flash-Next Q8_0, MTP rt, --spec 4;
this branch's build, two fresh engines, the vae request per size. The chunk auto-picked
3,328 tokens with a 101-slot ring; the room's e a roomed prompt runs.

prompt arm read (the engine's prompt … read in line) of which the room decode
3,080 tokens room 20,647 ms (149.2 tok/s 1,572.5 ms 25.1 tok/s
3,080 tokens room (repeat) 20,685 ms (14ms + back 1,580.9 ms 25.9 tok/s
3,080 tokens standing 16,171 ms (190.5 t
14,859 tokens room 39,807 ms (373.3 tok/k 1,566.1 ms 31.2 tok/s
14,859 tokens standing 35,794 ms (415.1 tok/s) — 32.7 tok/s

That line covers the room open and close, so the read itself is it minus the two room lines: ~16.6 s against 16.2 s,
and 36.4 s against 35.8 s. **The ring bought ns not what the prompt was waiting on — and
the room's own 3.4–4.0 s is what the request ptly what the doc says otherwise: CUDA3's
free VRAM while a roomed prompt ran was 66 MiBe freed 675 MiB was the ring; on the first
roomed prompt of an engine the block came back44866000000, not 0x746dbc000000`) and the
round/step graphs were dropped and re-capturedok/s — and every later prompt returned it
to the same address with nothing dropped. No guard refused a draft, no request errored, decode moved only within
noise. The reference measured the same shape ost 89.5 s): the room moves the ring, and
where the ring is not the limit, that is all i


🤖 Generated with [Claude Code](https://claude


🔄 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/2761 **Author:** [@gopinath87607](https://github.com/gopinath87607) **Created:** 10/16/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `prefill-decode-room` --- ### 📝 Commits (3) - [`6e48553`](https://github.com/Niko1221/Strata/commit/6e4855381987245b9e7fae93fd4770939ca3c6a9) prefill: what only the decode needs leaves VRAM while a prompt runs, and the prestage ring takes the loan (WIP - porting mw00/project-maya#223) - [`b4642dd`](https://github.com/Niko1221/Strata/commit/b4642ddcd1bd2892d420ee95c09890c042e8d5f8) serve: STRATA_MTP_ROOM_MIN - a long prompt takes the MTP drafter's 512 experts (decode-only) as ring - [`0958a68`](https://github.com/Niko1221/Strata/commit/0958a6864fe7588c74f13bbf2ac2991ef1b49323) docs: the room measured on the Q8_0 4-way - it works, and at 3k/15k it bought nothing ### 📊 Changes **7 files changed** (+492 additions, -42 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+7 -0) ➕ `docs/MTP_PROMPT_ROOM.md` (+146 -0) 📝 `include/strata/core/mtp.hpp` (+28 -0) 📝 `include/strata/prefill/prefill.hpp` (+11 -0) 📝 `src/core/mtp.cpp` (+89 -0) 📝 `src/prefill/prefill.cpp` (+30 -1) 📝 `src/program/generate.cpp` (+181 -41) </details> ### 📄 Description The MTP draft layer's 512 routed experts are read by the **decode alone**: `record_rest` is their only reader, and every prompt pass — the capture's K/V (`record_front`, both prefill captures) and the prompt path's `Prefill::draft_kv` — runs the layer's dense tensors and its K/V state instead. This is that block, lent to the prompt path for as long as a prompt is read. ```sh STRATA_MTP_ROOM_MIN=4096 strata serve --mtp rt … # prompts of 4096 tokens or more take the room STRATA_MTP_ROOM_MIN=0 strata serve --mtp rt … # every prompt does strata serve --mtp rt … # unset: off, and not one line of this runs ``` Port of the MTP half of [mw00/project-maya#223](https://github.com/mw00/project-maya/pull/223) (`STRATA_GLM_ROOM_MIN`). The reference's other half is its DFlash drafter, which Strata does not have; what this keeps is the mechanism, in Strata's own shape. ## What it does 1. **Per request, before the prompt**: the drafter's stream is synchronized, its streamed chain waited for, and the 512 blobs are copied into pinned host memory (taken once and kept — the room opens around every long prompt, and a second read of the 675 MiB `experts.bin` per prompt is what that avoids). The device block is freed. 2. **The prompt path is laid out again**, the path on the drafter's card with `Prefill::set_ring_room(room)`: the room is `experts_bytes / max_blob` ring slots — **135 on a Q8_0 pack, 672 MiB**. Those slots **spill past the borrowed region**, in one `cudaMalloc` taken after the region's own buffers: a slot at a time, 135 mallocs of 4.98 MiB would each round up to a 2 MiB page and want 130 MiB more than the block that was freed. The loan itself does not move — `bytes_needed` cannot count the room without resizing the whole expert cache, and a spilled layout cannot be relaid out (`relayout` refuses), so the roomed request keeps its layout, exactly as `--prefill-head-alias` does. 3. **After the prompt, before the first windowaid out as they were, the blobs are allocated again (cudaMalloc of the same size, then one DMA back), and the lending state is re-anchored (`pf_parts[].first_now` at the start-up regs out at, so `lend` marks only the slots the layout really covers as lent). If the block comes back at a **different address**, the round/step graphs are dropped and captured again — they are per-rad-alias` stops in that case instead because its verify graphs are all-or-nothinhen it happens. 4. **Guards**: while the experts are out, `draunch` and `record_rest` refuse with an error rather than launch a graph that readso decode runs between 1 and 3 anyway: the room opens and closes inside one request's eaches the close — a room left open by a request that ended another way is closed at the start of the next one). ## Files - **`include/strata/core/mtp.hpp` / `src/core/`, `experts_resident()`, `experts_out()`, `experts_back()`, `drop_expert_graphs()`, an - **`include/strata/prefill/prefill.hpp` / `sret_ring_room(slots)` and the ring's extra slots in `carve` (one block, past the region - **`src/program/generate.cpp`** — the start-uclose, and two drive-by fixes in the same code path (below). - **`docs/MTP_PROMPT_ROOM.md`** — the mechanismeasure it; `docs/DETAILS.md` points at it from the opt-in switches. ## What it leaves alone - **Unset, the default path is byte-identical*he gate, the open, the close and the `lend`/`init_prompt_paths` changes are all ie; `set_ring_room(0)` is the default). - Every prompt below the threshold, every decode, and every other opt-in switch are untouched. - `--prefill-head-alias` keeps its own behaviowo are combined deliberately rather than serially: when both apply, the head is unloaded and the path is laid out **once**, with the head's bytes and the drafter's together, and both come back before the first window. Without that, the second rebuild would undo the first (and could take VRAM the head's reload needs). ## Two fixes in the code this touches - **`set_peer` / `set_stage_helper` survive a tate *inside* the path's layout (`Impl`), so any `sp.reset()` + re-init silel-head-alias`'s rebuild did this every request on a rig using `STRATA_PEER_PREFILL_ROWS` or a layer split's helpers, and the room's rebuild would have too. Both rebuilds now call one `arm_prompt_ - **`STRATA_MTP_ROOM_MIN` is refused, not readr** (0 means "every prompt", so a typo would silently turn the room on for every re ## Limits - `--serve` only, `--mtp` needed, `--batch` ree the solo drafter's weights, so freeing them under the slots would be a use-after-freason at start and exits with 2. - A layer split is fine (the room goes to the --mtp-first`: the first). - Costs: 708 MB of pinned host memory (once), 708 MB over PCIe each way per roomed request, one prompt-path rebuild each way, and the roomed request's layout isshort prompt. ## Measured Q8_0 4-way, 2026-10-16: 2× RTX 3060 + 2× RTX 5060, layer split `auto`, Qwen3.8-Flash-Next Q8_0, MTP `rt`, `--spec 4`; this branch's build, two fresh engines, the vae request per size. The chunk auto-picked 3,328 tokens with a 101-slot ring; the room's e a roomed prompt runs. | prompt | arm | read (the engine's `prompt … read in` line) | of which the room | decode | |---|---|---|---|---| | 3,080 tokens | room | 20,647 ms (149.2 tok/s 1,572.5 ms | 25.1 tok/s | | 3,080 tokens | room (repeat) | 20,685 ms (14ms + back 1,580.9 ms | 25.9 tok/s | | 3,080 tokens | standing | 16,171 ms (190.5 t | 14,859 tokens | room | 39,807 ms (373.3 tok/k 1,566.1 ms | 31.2 tok/s | | 14,859 tokens | standing | 35,794 ms (415.1 tok/s) | — | 32.7 tok/s | That line covers the room open and close, so the read itself is it minus the two room lines: ~16.6 s against 16.2 s, and 36.4 s against 35.8 s. **The ring bought ns not what the prompt was waiting on — and the room's own 3.4–4.0 s is what the request ptly what the doc says otherwise: CUDA3's free VRAM while a roomed prompt ran was 66 MiBe freed 675 MiB was the ring; on the first roomed prompt of an engine the block came back44866000000, not 0x746dbc000000`) and the round/step graphs were dropped and re-capturedok/s — and every later prompt returned it to the same address with nothing dropped. No guard refused a draft, no request errored, decode moved only within noise. The reference measured the same shape ost 89.5 s): the room moves the ring, and where the ring is not the limit, that is all i --- 🤖 Generated with [Claude Code](https://claude --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:34:21 +07:00
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#4252
No description provided.