batch slots: MTP drafts in the pipelined groups, STRATA_PIPED_MTP=N opt-in with --batch-mtp (#4121, #3794)

Problem: a layer split with --batch pipelines the slots in groups, and the pipelined groups run no MTP drafts.
--batch-mtp with serial windows leaves all but one card waiting. A multi-stream deployment wants both.

What changed: STRATA_PIPED_MTP=N (with --batch-mtp) keeps the pipeline and drafts in it. A group's window carries
each of its slots' rows: the slot's 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 last stage judges each
slot's proposals on their own. The number of rows to keep is known only then, and by then the earlier stages run
other groups' windows, which reuse the scratch the commit replays from. So a small save graph copies those rows
right behind each window (Verifier::batch_launch_rows), and every stage queues the commit of the kept rows after
the verdict (Verifier::batch_commit_rows). The slot drafter catches up on its own rows and drafts the next
proposals as an asynchronous chain (MtpDrafter::chain_launch). Unset, nothing changes.

Changes on top of the PR as sent (review):
- The verifier window size is worked out where the verifiers are built, from the slots that fit and the final
  groups, not earlier from --batch as asked. Unset it is the old expression.
- STRATA_PIPED_MTP is decided again once the slots that fit are known. It says it is off, and why, when fewer than
  2 groups are left, when STRATA_BATCH_SELF_COMMIT is on, or when a group's window would hold more than
  kVerifyMaxT rows. The start line names groups and slots correctly.
- batch_groups::resolve keeps its old mtp_dropped rule; only mtp_piped is new, and it also applies with
  --batch-groups given (the PR's fix 1). The "--batch-groups 1" test case now expects "not dropped".
- --remote-expert-opt alone no longer blocks --batch-mtp on a layer split: the object it guards is only made with
  a helper expert cache (the PR's fix 2).
- docs/BATCHING.md rewritten with the numbers measured here.

Tests: batch_groups_test (the PR's cases, four "unset is as before" cases); builds on CUDA sm_86 (Linux), SYCL
(the sycl tree has its own verify.cpp and generate.cpp and does not include this code) and MSVC. Model runs:
see docs/BATCHING.md and the gate scripts 4121-*.sh.

Not covered: AMD (HIP) was not built or run; the draft layer on the first stage; helper expert caches.
This commit is contained in:
wannagoxuf authored and Niko1221 committed 2026-10-27 00:21:07 +01:00
1 parent a8c1d4b7f8
commit 17878ac579
6 files changed
+717 -43

No files matched your search

+66
View File
@@ -3,6 +3,7 @@
// 1. `auto` picks the most groups, at most one per stage, that divide the slots;
// 2. a layer split with --batch >= 2 and no --batch-groups means `auto` (0.1.41);
// 3. --batch-mtp (or --adapt-async 1) turns that default into one group, and says which feature did it;
// with STRATA_PIPED_MTP and one slot per group, --batch-mtp keeps the pipeline and drafts in it;
// 4. a number or `auto` given explicitly is honoured, with or without those features;
// 5. no layer split: the number given (1) stays.
#include "strata/program/batch_groups.hpp"
@@ -58,6 +59,71 @@ int main() {
"STRATA_BATCH_MTP_SERIAL: one group, because of --batch-mtp");
check(bg::serial_what(r.serial)[0] == '-', "the reason names the feature");
}
{ // STRATA_PIPED_MTP: the pipelined groups draft too, with any number of slots per group
bg::Input i = in(4, 3);
i.batch_mtp = true;
i.mtp_piped = true;
auto r = bg::resolve(i);
check(r.groups == 4 && r.mtp_piped && !r.mtp_dropped && r.serial == bg::Serial::None,
"STRATA_PIPED_MTP, 4 slots on 4 GPUs: 4 groups of 1 slot, and the drafts stay");
i.batch = 8; // two slots per group: the group's window carries both slots' rows, each with its own drafts
r = bg::resolve(i);
check(r.groups == 4 && r.mtp_piped && !r.mtp_dropped && r.serial == bg::Serial::None,
"STRATA_PIPED_MTP, 8 slots on 4 GPUs: 4 groups of 2 slots, and the drafts stay");
i.batch = 4;
i.mtp_serial = true; // asked for the serial windows: those win
r = bg::resolve(i);
check(r.groups == 1 && !r.mtp_piped && r.serial == bg::Serial::BatchMtp,
"STRATA_PIPED_MTP with STRATA_BATCH_MTP_SERIAL: one serial group");
i.mtp_serial = false;
i.batch_mtp = false;
r = bg::resolve(i);
check(r.groups == 4 && !r.mtp_piped && !r.mtp_dropped, "STRATA_PIPED_MTP without --batch-mtp: nothing to draft");
i.batch_mtp = true;
i.set = true;
i.given = 1; // one group: the serial windows, where --batch-mtp's own drafts run
r = bg::resolve(i);
check(r.groups == 1 && !r.mtp_piped && !r.mtp_dropped, "STRATA_PIPED_MTP, --batch-groups 1: the serial path, --batch-mtp runs there");
}
{ // 0.1.49.2 port: --batch-groups given EXPLICITLY (a number or `auto`) must not silently
// drop the drafts: the operator asked for those groups, and one slot per group still drafts.
bg::Input i = in(4, 3);
i.batch_mtp = true;
i.mtp_piped = true;
i.set = true;
i.auto_given = true; // --batch-groups auto
i.given = 4;
auto r = bg::resolve(i);
check(r.groups == 4 && r.mtp_piped && !r.mtp_dropped && r.serial == bg::Serial::None,
"STRATA_PIPED_MTP, --batch-groups auto given: 4 groups of 1 slot, and the drafts stay");
i.auto_given = false; // --batch-groups 4
r = bg::resolve(i);
check(r.groups == 4 && r.mtp_piped && !r.mtp_dropped && r.serial == bg::Serial::None,
"STRATA_PIPED_MTP, --batch-groups 4 given: 4 groups of 1 slot, and the drafts stay");
i.given = 2; // two slots per group: the group's window carries both slots' rows
r = bg::resolve(i);
check(r.groups == 2 && r.mtp_piped && !r.mtp_dropped,
"STRATA_PIPED_MTP, --batch-groups 2 given: 2 groups of 2 slots, and the drafts stay");
}
{ // STRATA_PIPED_MTP unset: nothing changes, whatever --batch-mtp and the groups say
bg::Input i = in(4, 1);
i.batch_mtp = true;
auto r = bg::resolve(i);
check(r.groups == 2 && !r.mtp_piped && r.mtp_dropped && r.serial == bg::Serial::None,
"unset, --batch-mtp, nothing given: the pipeline wins, the drafts are dropped (as before)");
i.set = true;
i.given = 2;
r = bg::resolve(i);
check(r.groups == 2 && !r.mtp_piped && !r.mtp_dropped, "unset, --batch-mtp, --batch-groups 2: not 'dropped' here (as before)");
i.given = 1;
r = bg::resolve(i);
check(r.groups == 1 && !r.mtp_piped && !r.mtp_dropped, "unset, --batch-mtp, --batch-groups 1: serial windows keep the drafts");
i.set = false;
i.mtp_serial = true;
r = bg::resolve(i);
check(r.groups == 1 && !r.mtp_piped && !r.mtp_dropped && r.serial == bg::Serial::BatchMtp,
"unset, STRATA_BATCH_MTP_SERIAL: one serial group (as before)");
}
{
bg::Input i = in(2, 1);
i.adapt_async = true;