[PR #4121] [Engine] batch-groups: MTP drafts in the pipelined slot groups (STRATA_PIPED_MTP=N, opt-in) #4909

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4121
Author: @wannagoxuf
Created: 10/25/2026
Status: 🔄 Open

Base: main ← Head: feature/piped-mtp-upstream


📝 Commits (5)

  • 0ee2c21 batch-groups: MTP drafts in the pipelined slot groups (STRATA_PIPED_MTP=N, opt-in, #2973)
  • c89bcb1 batch_groups: STRATA_PIPED_MTP 也要在显式给了 --batch-groups 时生效
  • 2fc99e4 流水线组多槽: 每组可带多个槽(配对草稿行) + verifier 窗口上限修正
  • a570fd4 server: 多槽组的请求优先摊到各组(准入的槽选择)
  • 9241a24 撤出 PR: 服务端的"准入摊到各组"改动

📊 Changes

6 files changed (+653 additions, -41 deletions)

View changed files

📝 docs/BATCHING.md (+44 -2)
📝 include/strata/core/verify.hpp (+27 -0)
📝 include/strata/program/batch_groups.hpp (+21 -10)
📝 src/core/verify.cpp (+236 -1)
📝 src/program/batch_groups_test.cpp (+47 -0)
📝 src/program/generate.cpp (+278 -28)

📄 Description

Problem and result

Problem. With a layer split, --batch pipelines the slots in groups (one group per stage), but the pipelined path runs no MTP drafts, and --batch-mtp with serial windows leaves all but one card waiting (on four stages it lost 30-40% of the four streams' total against the pipelined default — we measured that layout ourselves: 212 tok/s against the pipelined default's 364 at four concurrent, -42%; at two concurrent it starves the second client, the prompt read being walked serially between the stages). The drafts that the solo path gets are exactly the ones a multi-stream deployment wants.

Result. STRATA_PIPED_MTP=N (with --batch-mtp) keeps the pipeline and drafts in it: each group's window carries its slots' rows — every slot of the group brings its token and up to N MTP proposals (at most --spec - 1; the first always, each further one while the draft layer was at least --spec-min-p sure of the one before, the solo path's rule), and each slot's proposals are judged, committed and drafted on their own. It is left off, with a line at start, otherwise. Default off: nothing changes without the variable.

On 4x RTX 4090 (layer split 13,27,38, --batch 4, four concurrent streams, fixed 30 s windows): 365.9 -> 510 tok/s (+39%) with N=2, every slot still decoding exactly the tokens it decodes alone. A group's window may now hold more than one slot, which lifts the "one slot per group" ceiling that kept the four streams on four stages.

Closes #3794 (the feature request). Refs #2973 and #2985 — this replaces #2985 (closed unmerged): the same feature, ported onto current main, plus two fixes the original PR had, plus the extension to more than one slot per group. The measurements in #3794 from @llollaalloll (V100/2080Ti) and @noahark (3x sm_70) are on the same feature and are quoted back below where they bear on the shape.

Approach

What the port touched

The port itself was small: 2 conflict hunks in include/strata/program/batch_groups.hpp and 6 in src/program/generate.cpp, all of them "both features keep theirs" (the nv_serial_faster proposal and the PSTAT telemetry on this side, mtp_piped / batch_launch_rows on the other). src/core/verify.cpp (+237) and include/strata/core/verify.hpp (+27) merged without a conflict.

Fix 1: the feature silently did nothing when --batch-groups was given explicitly

In batch_groups::resolve the two new lines sat inside if (!in.set && r.would_be > 1), and in.set is true whenever --batch-groups was given (a number or auto):

strata generate: WARNING: --batch-mtp is off: it does not combine with --batch-groups (pipelined slot groups) yet

i.e. the drafts are off and the message does not say why. --batch-groups auto is the documented way to configure a layer split, and the PR's own unit test never set in.set, so it did not catch this. The two assignments now sit outside that block: when the operator has already asked for the groups, one slot per group still drafts. Three unit tests cover it (auto given, a number given, two slots per group).

Fix 2 (not ours to decide): --remote-expert-opt blocks the feature even where it does nothing

The gate checks the flag:

        if (why == nullptr && !stages.empty() && (remote_caches || o.remote_expert_opt))
            why = "it is not run with helper expert caches on a layer split";

but the object it guards is only created with a helper expert cache:

    if (o.remote_expert_opt && o.expert_cache_remote[0] > 0) remote_opt = std::make_unique<strata::core::RemoteExpertOpt>();

On a rig without --expert-cache-device1..3 the flag is inert (every remote_opt-guarded branch takes the else path) and the gate still refuses --batch-mtp. Checking the object instead of the flag would unblock the feature for everyone who has the flag on for no reason. (We did not change this here — it is a one-line decision for the maintainer.)

Fix 3: the verifier's window has to hold a group's rows

The verifiers' max_t was sized from --spec alone (the solo path's draft window), which is enough for a group of one slot (its token plus its proposals) but not for a group of several slots: the window then failed with verify: batch rows out of range and took the whole pipeline down. It is now max(the old value, a group's rows), still bounded by kVerifyMaxT.

More than one slot per group

The original PR needed one slot per group. A group's window can now carry several slots: the rows of the group are split per slot, and the verdict judges each slot's proposals on its own (its own accepted prefix), the commit replays each slot's accepted prefix (the verifier's batch commit already groups a window's rows per slot), and each slot's chain catches up on its own rows only — the last stage's final residuals are copied per slot's block, and the chain is launched with that slot's own rows, picks and positions.

With one slot per group this is exactly the original behaviour. With more, a group's window holds more rows, which amortises the weights over more of them.

Validation

Passed:

  • Exactness. tools/batch_test.py (4 slots on a 4-GPU split, 300 tokens, STRATA_IQ_MT_MIN=1 --adapt-swaps 0 --pcie-frac 0): every slot decodes exactly the tokens it decodes alone, with the feature on and with it off — for one slot per group and for two, and for N=1, 2 and 3.
  • Unit tests. The three batch_groups cases (groups given as auto, as a number, and two slots per group) pass.
  • The measurements below, four concurrent streams on 4x RTX 4090, layer split 13,27,38, --trim-stage-weights, --batch 4, --spec 4 --spec-min-p 0.25, experts 100% resident, --kv k8v4 --kv-resident 524288, STRATA_BATCH_MTP=1. Metric: a fixed 30 s window, the tokens that arrived in it (a fixed window removes the batch-window-shape variance — with "generate N tokens" the requests stop at different times and the same configuration measures 270 or 343 rows/s).
arm rows per step (engine) aggregate (30 s window)
pipelined groups (default, no drafts) 1.00 365.9 tok/s
STRATA_PIPED_MTP=1 1.72 477.8 tok/s (+30.5%)
STRATA_PIPED_MTP=2 2.29 510 tok/s (+39%)
STRATA_PIPED_MTP=3 2.70 464 tok/s (+27%)

The engine's own numbers agree: 381 rows/s without the drafts, 533 rows/s at N=2 (proposals kept 72%, 64%, 58% at N=1, 2, 3 — the acceptance falls as the window grows, which is why N=2 is the sweet spot and N=3 is not).

  • VRAM. 50 MiB of private K/V state and buffers per slot (the solo drafter's weights are shared), so four slot drafters cost 200 MiB on the last stage's card and the expert cache stayed 100% resident. The warning text's "about 0.9 GB per slot" is far off on our split.

  • Two slots per group, eight slots (4x RTX 4090, fixed 30 s windows, two interleaved rounds):

shape 4 concurrent 8 concurrent
one slot per group (--batch 4), no drafts 366 tok/s 4 served, 4 starved
one slot per group (--batch 4) 489 tok/s 4 served, 4 starved
two slots per group (--batch 8, --kv-resident 262144) 390 tok/s 421 tok/s, all 8 served
two slots per group (--batch 8, --kv-resident 131072) 501 tok/s 522 tok/s, all 8 served

The requests do spread over the four groups (busy slots 0, 2, 4, 6; the engine reports 2.16 rows per step, one live slot per group). The four-concurrent gap is VRAM, not the spreading: eight slot sessions take 10.18 GiB on CUDA0, so the expert cache shrinks from 9.41 GiB to 8.01 GiB and the decode fetches more experts over PCIe. --batch 4 with --kv-resident 262144 (cache unchanged) measures 496 tok/s, and --batch 8 with --kv-resident 131072 (cache back to 9.41 GiB) measures 514.

  • The serial layout, for the record (STRATA_BATCH_MTP_SERIAL=1, one group of four slots with the slot drafters, against the pipelined default on the same rig and the same clients):
layout 2 concurrent (window / steady) 4 concurrent (window / steady) per request at 4
one group + --batch-mtp 0.3 / 1.0 tok/s 212 / 246 tok/s 53
pipelined groups, no drafts 211 / 227 tok/s 364 / 430 tok/s 91
pipelined groups + STRATA_PIPED_MTP=2 307 / 357 tok/s 481 / 584 tok/s 120

At four concurrent the serial layout loses 42% against the pipelined default (the 30-40% that #2985's summary reports for four stages). At two concurrent it does not merely lose: the second client never got a token in 30 s, because the prompt read is walked serially between the stages and the decode has nothing to hide it behind — the engine logged the prompt read gives way at 102838 of 186841 tokens; slot 0 holds it and eight windows (1.75 rows each) in the whole window. The pipeline is what makes a long read hideable, and the drafts exploit the same property.

Failed:

  • none observed.

Not run:

  • Non-CUDA builds (HIP / SYCL / Metal) and the GUI/TUI — the change is in the engine's batch path only, but we could not compile them.
  • The two-slots-per-group shape on a three-stage rig, where the per-request speed (not the aggregate) decides the trade; our four-stage rig has enough stages to keep every card busy.
  • Any long-context legs: the measurements above use ~120-token prompts; the KV and the conversation cache were not stressed.

Limits

  • The server's slot choice is deliberately not in this PR. With groups of several slots, pick_slot prefers "fill a hole below a busy slot of the same group" (#793: a group left as [_ B] costs a whole row) and only then the cross-group order, so a request that ends while another of its group runs leaves the next request back in that group while another stage sits idle. Preferring the group with the fewest busy slots would spread them, but that changes a decision the repository encodes in serve/test_slot_alloc.py (test_fills_a_leading_hole_first), so it is a change for the maintainer to take rather than for this PR to take silently. We run the variant on our own box and can submit it separately if you want it.

  • The per-request speed halves when a group carries two slots. The aggregate is machine-bound, so two slots per group split it: 501 tok/s over eight requests is 63 tok/s each, against 489 tok/s over four requests at 122 tok/s each. The two-slot shape pays off when there are more concurrent requests than stages (four streams over four stages leave half the requests waiting); it does not pay off for a rig that already has a free slot per stage.

  • The expert cache is the price of the extra slots (9.41 GiB -> 8.01 GiB at --batch 8, worth about 19% of the aggregate at four concurrent). The mitigation is --kv-resident 131072, which brings the cache back.

  • A measurement caveat for whoever repeats this. A fixed 30 s window counts the first-token ramp as part of the window: with four streams admitted together the first token arrives at 1.3-5.2 s each (the prompt reads are serial, and a read costs 1.2 s on an idle engine but 4.5 s when the expert cache is occupied), so the window number is 9-27% below the steady rate. We now report the steady rate (the last 10 s of the window) next to it: the same run reads 512 tok/s in the window and 634 tok/s steady. The arm-to-arm comparisons above are unaffected (every arm has the same shape), but the absolute numbers are low.

  • The --remote-expert-opt gate is untouched (see fix 2).


🔄 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/4121 **Author:** [@wannagoxuf](https://github.com/wannagoxuf) **Created:** 10/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feature/piped-mtp-upstream` --- ### 📝 Commits (5) - [`0ee2c21`](https://github.com/Niko1221/Strata/commit/0ee2c21026fff46a24f1c87e44d0a4e15c06660c) batch-groups: MTP drafts in the pipelined slot groups (STRATA_PIPED_MTP=N, opt-in, #2973) - [`c89bcb1`](https://github.com/Niko1221/Strata/commit/c89bcb15a4827b346b4e69d3659a43283c1b9fcf) batch_groups: STRATA_PIPED_MTP 也要在显式给了 --batch-groups 时生效 - [`2fc99e4`](https://github.com/Niko1221/Strata/commit/2fc99e4efa741b3759b104b0604a24b28bb1e05a) 流水线组多槽: 每组可带多个槽(配对草稿行) + verifier 窗口上限修正 - [`a570fd4`](https://github.com/Niko1221/Strata/commit/a570fd4453415e626f18a05e5c0c97c4ea10f39b) server: 多槽组的请求优先摊到各组(准入的槽选择) - [`9241a24`](https://github.com/Niko1221/Strata/commit/9241a24ed421dbe24c05877ccef213dc89524221) 撤出 PR: 服务端的"准入摊到各组"改动 ### 📊 Changes **6 files changed** (+653 additions, -41 deletions) <details> <summary>View changed files</summary> 📝 `docs/BATCHING.md` (+44 -2) 📝 `include/strata/core/verify.hpp` (+27 -0) 📝 `include/strata/program/batch_groups.hpp` (+21 -10) 📝 `src/core/verify.cpp` (+236 -1) 📝 `src/program/batch_groups_test.cpp` (+47 -0) 📝 `src/program/generate.cpp` (+278 -28) </details> ### 📄 Description ## Problem and result **Problem.** With a layer split, `--batch` pipelines the slots in groups (one group per stage), but the pipelined path runs no MTP drafts, and `--batch-mtp` with serial windows leaves all but one card waiting (on four stages it lost 30-40% of the four streams' total against the pipelined default — we measured that layout ourselves: 212 tok/s against the pipelined default's 364 at four concurrent, -42%; at two concurrent it starves the second client, the prompt read being walked serially between the stages). The drafts that the solo path gets are exactly the ones a multi-stream deployment wants. **Result.** `STRATA_PIPED_MTP=N` (with `--batch-mtp`) keeps the pipeline and drafts in it: each group's window carries its slots' rows — every slot of the group brings its token and up to N MTP proposals (at most `--spec` - 1; the first always, each further one while the draft layer was at least `--spec-min-p` sure of the one before, the solo path's rule), and each slot's proposals are judged, committed and drafted on their own. It is left off, with a line at start, otherwise. Default off: nothing changes without the variable. On 4x RTX 4090 (layer split `13,27,38`, `--batch 4`, four concurrent streams, fixed 30 s windows): **365.9 -> 510 tok/s (+39%)** with `N=2`, every slot still decoding exactly the tokens it decodes alone. A group's window may now hold **more than one slot**, which lifts the "one slot per group" ceiling that kept the four streams on four stages. ## Related discussion Closes #3794 (the feature request). Refs #2973 and #2985 — this replaces #2985 (closed unmerged): the same feature, ported onto current `main`, plus two fixes the original PR had, plus the extension to more than one slot per group. The measurements in #3794 from @llollaalloll (V100/2080Ti) and @noahark (3x sm_70) are on the same feature and are quoted back below where they bear on the shape. ## Approach ### What the port touched The port itself was small: 2 conflict hunks in `include/strata/program/batch_groups.hpp` and 6 in `src/program/generate.cpp`, all of them "both features keep theirs" (the `nv_serial_faster` proposal and the PSTAT telemetry on this side, `mtp_piped` / `batch_launch_rows` on the other). `src/core/verify.cpp` (+237) and `include/strata/core/verify.hpp` (+27) merged without a conflict. ### Fix 1: the feature silently did nothing when `--batch-groups` was given explicitly In `batch_groups::resolve` the two new lines sat *inside* `if (!in.set && r.would_be > 1)`, and `in.set` is true whenever `--batch-groups` was given (a number *or* `auto`): ``` strata generate: WARNING: --batch-mtp is off: it does not combine with --batch-groups (pipelined slot groups) yet ``` i.e. the drafts are off and the message does not say why. `--batch-groups auto` is the documented way to configure a layer split, and the PR's own unit test never set `in.set`, so it did not catch this. The two assignments now sit outside that block: when the operator has already asked for the groups, one slot per group still drafts. Three unit tests cover it (`auto` given, a number given, two slots per group). ### Fix 2 (not ours to decide): `--remote-expert-opt` blocks the feature even where it does nothing The gate checks the *flag*: ```cpp if (why == nullptr && !stages.empty() && (remote_caches || o.remote_expert_opt)) why = "it is not run with helper expert caches on a layer split"; ``` but the object it guards is only created with a helper expert cache: ```cpp if (o.remote_expert_opt && o.expert_cache_remote[0] > 0) remote_opt = std::make_unique<strata::core::RemoteExpertOpt>(); ``` On a rig without `--expert-cache-device1..3` the flag is inert (every `remote_opt`-guarded branch takes the `else` path) and the gate still refuses `--batch-mtp`. Checking the object instead of the flag would unblock the feature for everyone who has the flag on for no reason. (We did not change this here — it is a one-line decision for the maintainer.) ### Fix 3: the verifier's window has to hold a group's rows The verifiers' `max_t` was sized from `--spec` alone (the solo path's draft window), which is enough for a group of one slot (its token plus its proposals) but not for a group of several slots: the window then failed with `verify: batch rows out of range` and took the whole pipeline down. It is now `max(the old value, a group's rows)`, still bounded by `kVerifyMaxT`. ### More than one slot per group The original PR needed one slot per group. A group's window can now carry several slots: the rows of the group are split per slot, and the verdict judges each slot's proposals on its own (its own accepted prefix), the commit replays each slot's accepted prefix (the verifier's batch commit already groups a window's rows per slot), and each slot's chain catches up on its own rows only — the last stage's final residuals are copied per slot's block, and the chain is launched with that slot's own rows, picks and positions. With one slot per group this is exactly the original behaviour. With more, a group's window holds more rows, which amortises the weights over more of them. ## Validation **Passed:** - **Exactness.** `tools/batch_test.py` (4 slots on a 4-GPU split, 300 tokens, `STRATA_IQ_MT_MIN=1 --adapt-swaps 0 --pcie-frac 0`): every slot decodes exactly the tokens it decodes alone, with the feature on and with it off — for one slot per group and for two, and for N=1, 2 and 3. - **Unit tests.** The three `batch_groups` cases (groups given as `auto`, as a number, and two slots per group) pass. - **The measurements below**, four concurrent streams on 4x RTX 4090, layer split `13,27,38`, `--trim-stage-weights`, `--batch 4`, `--spec 4 --spec-min-p 0.25`, experts 100% resident, `--kv k8v4 --kv-resident 524288`, `STRATA_BATCH_MTP=1`. Metric: a fixed 30 s window, the tokens that arrived in it (a fixed window removes the batch-window-shape variance — with "generate N tokens" the requests stop at different times and the same configuration measures 270 or 343 rows/s). | arm | rows per step (engine) | aggregate (30 s window) | |---|---:|---:| | pipelined groups (default, no drafts) | 1.00 | 365.9 tok/s | | `STRATA_PIPED_MTP=1` | 1.72 | 477.8 tok/s (+30.5%) | | `STRATA_PIPED_MTP=2` | 2.29 | **510 tok/s (+39%)** | | `STRATA_PIPED_MTP=3` | 2.70 | 464 tok/s (+27%) | The engine's own numbers agree: 381 rows/s without the drafts, 533 rows/s at N=2 (proposals kept 72%, 64%, 58% at N=1, 2, 3 — the acceptance falls as the window grows, which is why N=2 is the sweet spot and N=3 is not). - **VRAM.** 50 MiB of private K/V state and buffers per slot (the solo drafter's weights are shared), so four slot drafters cost 200 MiB on the last stage's card and the expert cache stayed 100% resident. The warning text's "about 0.9 GB per slot" is far off on our split. - **Two slots per group, eight slots** (4x RTX 4090, fixed 30 s windows, two interleaved rounds): | shape | 4 concurrent | 8 concurrent | |---|---:|---:| | one slot per group (`--batch 4`), no drafts | 366 tok/s | 4 served, 4 starved | | one slot per group (`--batch 4`) | 489 tok/s | 4 served, 4 starved | | two slots per group (`--batch 8`, `--kv-resident 262144`) | 390 tok/s | 421 tok/s, all 8 served | | two slots per group (`--batch 8`, `--kv-resident 131072`) | 501 tok/s | **522 tok/s, all 8 served** | The requests do spread over the four groups (busy slots 0, 2, 4, 6; the engine reports 2.16 rows per step, one live slot per group). The four-concurrent gap is VRAM, not the spreading: eight slot sessions take 10.18 GiB on CUDA0, so the expert cache shrinks from 9.41 GiB to 8.01 GiB and the decode fetches more experts over PCIe. `--batch 4` with `--kv-resident 262144` (cache unchanged) measures 496 tok/s, and `--batch 8` with `--kv-resident 131072` (cache back to 9.41 GiB) measures 514. - **The serial layout, for the record** (`STRATA_BATCH_MTP_SERIAL=1`, one group of four slots with the slot drafters, against the pipelined default on the same rig and the same clients): | layout | 2 concurrent (window / steady) | 4 concurrent (window / steady) | per request at 4 | |---|---:|---:|---:| | one group + `--batch-mtp` | 0.3 / 1.0 tok/s | 212 / 246 tok/s | 53 | | pipelined groups, no drafts | 211 / 227 tok/s | 364 / 430 tok/s | 91 | | pipelined groups + `STRATA_PIPED_MTP=2` | 307 / 357 tok/s | 481 / 584 tok/s | 120 | At four concurrent the serial layout loses 42% against the pipelined default (the 30-40% that #2985's summary reports for four stages). At two concurrent it does not merely lose: the second client never got a token in 30 s, because the prompt read is walked serially between the stages and the decode has nothing to hide it behind — the engine logged `the prompt read gives way at 102838 of 186841 tokens; slot 0 holds it` and eight windows (1.75 rows each) in the whole window. The pipeline is what makes a long read hideable, and the drafts exploit the same property. **Failed:** - none observed. **Not run:** - Non-CUDA builds (HIP / SYCL / Metal) and the GUI/TUI — the change is in the engine's batch path only, but we could not compile them. - The two-slots-per-group shape on a three-stage rig, where the per-request speed (not the aggregate) decides the trade; our four-stage rig has enough stages to keep every card busy. - Any long-context legs: the measurements above use ~120-token prompts; the KV and the conversation cache were not stressed. ## Limits - **The server's slot choice is deliberately not in this PR.** With groups of several slots, `pick_slot` prefers "fill a hole below a busy slot of the same group" (#793: a group left as `[_ B]` costs a whole row) and only then the cross-group order, so a request that ends while another of its group runs leaves the next request back in that group while another stage sits idle. Preferring the group with the fewest busy slots would spread them, but that changes a decision the repository encodes in `serve/test_slot_alloc.py` (`test_fills_a_leading_hole_first`), so it is a change for the maintainer to take rather than for this PR to take silently. We run the variant on our own box and can submit it separately if you want it. - **The per-request speed halves when a group carries two slots.** The aggregate is machine-bound, so two slots per group split it: 501 tok/s over eight requests is 63 tok/s each, against 489 tok/s over four requests at 122 tok/s each. The two-slot shape pays off when there are more concurrent requests than stages (four streams over four stages leave half the requests waiting); it does not pay off for a rig that already has a free slot per stage. - **The expert cache is the price of the extra slots** (9.41 GiB -> 8.01 GiB at `--batch 8`, worth about 19% of the aggregate at four concurrent). The mitigation is `--kv-resident 131072`, which brings the cache back. - **A measurement caveat for whoever repeats this.** A fixed 30 s window counts the first-token ramp as part of the window: with four streams admitted together the first token arrives at 1.3-5.2 s each (the prompt reads are serial, and a read costs 1.2 s on an idle engine but 4.5 s when the expert cache is occupied), so the window number is 9-27% below the steady rate. We now report the steady rate (the last 10 s of the window) next to it: the same run reads 512 tok/s in the window and 634 tok/s steady. The arm-to-arm comparisons above are unaffected (every arm has the same shape), but the absolute numbers are low. - The `--remote-expert-opt` gate is untouched (see fix 2). --- <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#4909
No description provided.