mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4121] [Engine] batch-groups: MTP drafts in the pipelined slot groups (STRATA_PIPED_MTP=N, opt-in) #4909
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4909
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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)
0ee2c21batch-groups: MTP drafts in the pipelined slot groups (STRATA_PIPED_MTP=N, opt-in, #2973)c89bcb1batch_groups: STRATA_PIPED_MTP 也要在显式给了 --batch-groups 时生效2fc99e4流水线组多槽: 每组可带多个槽(配对草稿行) + verifier 窗口上限修正a570fd4server: 多槽组的请求优先摊到各组(准入的槽选择)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,
--batchpipelines the slots in groups (one group per stage), but the pipelined path runs no MTP drafts, and--batch-mtpwith 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-psure 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%) withN=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.hppand 6 insrc/program/generate.cpp, all of them "both features keep theirs" (thenv_serial_fasterproposal and the PSTAT telemetry on this side,mtp_piped/batch_launch_rowson the other).src/core/verify.cpp(+237) andinclude/strata/core/verify.hpp(+27) merged without a conflict.Fix 1: the feature silently did nothing when
--batch-groupswas given explicitlyIn
batch_groups::resolvethe two new lines sat insideif (!in.set && r.would_be > 1), andin.setis true whenever--batch-groupswas given (a number orauto):i.e. the drafts are off and the message does not say why.
--batch-groups autois the documented way to configure a layer split, and the PR's own unit test never setin.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 (autogiven, a number given, two slots per group).Fix 2 (not ours to decide):
--remote-expert-optblocks the feature even where it does nothingThe gate checks the flag:
but the object it guards is only created with a helper expert cache:
On a rig without
--expert-cache-device1..3the flag is inert (everyremote_opt-guarded branch takes theelsepath) 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_twas sized from--specalone (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 withverify: batch rows out of rangeand took the whole pipeline down. It is nowmax(the old value, a group's rows), still bounded bykVerifyMaxT.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:
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.batch_groupscases (groups given asauto, as a number, and two slots per group) pass.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).STRATA_PIPED_MTP=1STRATA_PIPED_MTP=2STRATA_PIPED_MTP=3The 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):
--batch 4), no drafts--batch 4)--batch 8,--kv-resident 262144)--batch 8,--kv-resident 131072)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 4with--kv-resident 262144(cache unchanged) measures 496 tok/s, and--batch 8with--kv-resident 131072(cache back to 9.41 GiB) measures 514.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):--batch-mtpSTRATA_PIPED_MTP=2At 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 itand 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:
Not run:
Limits
The server's slot choice is deliberately not in this PR. With groups of several slots,
pick_slotprefers "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 inserve/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-optgate is untouched (see fix 2).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.