batch-groups: the 0.1.41 auto default gives way to --batch-mtp (one group, said once)

--batch-groups auto became the default for a layer split with --batch >= 2, but the --batch-mtp gate ran before
the groups were resolved: it saw 1 group, kept batch-MTP on, and the groups were then raised to 2 - pipelined groups
do not run the slots' MTP drafts (#1413). The resolution is now a pure helper (include/strata/program/batch_groups.hpp,
CPU test src/program/batch_groups_test.cpp): with --batch-mtp and no --batch-groups the default is one group and
the log says why; --batch-groups N (N > 1) or --batch-groups auto given on the command line pipelines the groups and
turns --batch-mtp off, as before.
This commit is contained in:
noon-at-cgn authored and Niko1221 committed 2026-10-09 15:16:16 +02:00
1 parent 70fc0ba46d
commit cb6c549c8a
5 files changed
+194 -13

No files matched your search

+93
View File
@@ -0,0 +1,93 @@
// src/program/batch_groups_test.cpp - how many pipelined slot groups --batch runs with (header-only, CPU).
//
// 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 turns that default into one group, and says which feature did it;
// 4. a number or `auto` given explicitly is honoured, with or without --batch-mtp;
// 5. no layer split: the number given (1) stays.
#include "strata/program/batch_groups.hpp"
#include <cstdio>
namespace bg = strata::program::batch_groups;
namespace {
int g_fail = 0;
void check(bool ok, const char* what) {
std::printf(" %-78s %s\n", what, ok ? "ok" : "FAIL");
if (!ok) ++g_fail;
}
bg::Input in(int batch, int stages) {
bg::Input i;
i.batch = batch;
i.later_stages = stages;
return i;
}
} // namespace
int main() {
std::printf("batch_groups_test\n");
check(bg::auto_groups(0, 4) == 1, "auto: no layer split, one group");
check(bg::auto_groups(1, 2) == 2 && bg::auto_groups(1, 4) == 2 && bg::auto_groups(1, 3) == 1,
"auto: two GPUs, 2 groups when the slots divide by 2");
check(bg::auto_groups(3, 8) == 4 && bg::auto_groups(3, 6) == 3 && bg::auto_groups(3, 2) == 2,
"auto: at most one group per GPU, and a divisor of the slots");
{ // the 0.1.41 default
const auto r = bg::resolve(in(2, 1));
check(r.groups == 2 && r.from_auto && r.serial == bg::Serial::None, "layer split, --batch 2, nothing given: 2 groups");
}
{
const auto r = bg::resolve(in(1, 1));
check(r.groups == 1 && !r.from_auto, "--batch 1: no default");
}
{
const auto r = bg::resolve(in(2, 0));
check(r.groups == 1 && !r.from_auto, "no layer split: one group");
}
{ // the shape this is for: parallel 2 on a 2-GPU split with --batch-mtp
bg::Input i = in(2, 1);
i.batch_mtp = true;
const auto r = bg::resolve(i);
check(r.groups == 1 && r.from_auto && r.serial == bg::Serial::BatchMtp && r.would_be == 2,
"--batch-mtp, nothing given: one group, because of --batch-mtp");
check(bg::serial_what(r.serial)[0] == '-', "the reason names the feature");
}
{ // nothing to give way: the slots do not divide, so auto is one group anyway and there is nothing to say
bg::Input i = in(3, 1);
i.batch_mtp = true;
const auto r = bg::resolve(i);
check(r.groups == 1 && r.serial == bg::Serial::None && r.would_be == 1, "auto would be 1 group anyway: no reason");
}
{ // explicit values are honoured
bg::Input i = in(4, 1);
i.set = true;
i.given = 2;
i.batch_mtp = true;
const auto r = bg::resolve(i);
check(r.groups == 2 && !r.from_auto && r.serial == bg::Serial::None, "--batch-groups 2 with --batch-mtp: 2");
i.given = 1;
check(bg::resolve(i).groups == 1, "--batch-groups 1: 1 (the opt-out)");
i.given = 4; // not checked here: generate.cpp refuses what does not divide
check(bg::resolve(i).groups == 4, "--batch-groups 4 is returned as given");
}
{
bg::Input i = in(2, 1);
i.set = true;
i.auto_given = true;
i.batch_mtp = true;
const auto r = bg::resolve(i);
check(r.groups == 2 && r.from_auto && r.serial == bg::Serial::None,
"--batch-groups auto with --batch-mtp: auto asked for the pipeline, 2 groups");
}
{
bg::Input i = in(2, 0);
i.set = true;
i.given = 2;
check(bg::resolve(i).groups == 2, "an explicit number without a split is returned (the engine warns)");
}
std::printf("%s\n", g_fail == 0 ? "batch_groups_test: all passed" : "batch_groups_test: FAILED");
return g_fail == 0 ? 0 : 1;
}
+34 -12
View File
@@ -72,6 +72,7 @@
#include "strata/spec/draft_policy.hpp"
#include "strata/spec/draft_source.hpp"
#include "strata/spec/suffix_drafter.hpp"
#include "strata/program/batch_groups.hpp"
#include "strata/kernels/cvec.hpp"
#include "strata/core/progress.hpp"
#include "strata/core/device.hpp"
@@ -4117,15 +4118,31 @@ int main(int argc, char** argv) {
// force: when it cannot run it is said and left off (plain batching still starts); default off = exactly 0.1.39.
// With a layer split the slots' drafters live on the LAST stage's GPU (where the solo drafter, the head and the final
// residual rows are); the windows are the ones --batch runs, two rows per slot, through every stage.
// --batch-groups: given as a number or auto, or (0.1.41) auto by default for a layer split with --batch >= 2. The
// pipelined slot groups do not run --batch-mtp's drafts, so when it is asked for and the groups were not given, the
// default is one group (batch_groups.hpp). Evaluated again once the slots that fit are known, and BEFORE the
// --batch-mtp gate below, which must see the resolved number.
auto batch_groups_for = [&](bool mtp_on) {
strata::program::batch_groups::Input bin;
bin.set = o.batch_groups_set;
bin.auto_given = o.batch_groups_auto;
bin.given = o.batch_groups;
bin.batch = o.batch;
bin.later_stages = (int) stages.size();
bin.batch_mtp = mtp_on;
return strata::program::batch_groups::resolve(bin);
};
const char* batch_mtp_env = std::getenv("STRATA_BATCH_MTP");
bool batch_mtp = o.batch_mtp || (batch_mtp_env != nullptr && batch_mtp_env[0] != '\0' && batch_mtp_env[0] != '0');
if (batch_mtp) {
// (--pipeline-windows is already off with --batch slots)
const char* why = o.batch < 2 ? "it needs --batch 2 or more" : o.mtp.empty() ? "it needs --mtp"
: o.spec < 2 ? "it needs --spec T (T >= 2)" : split_same
? "it needs each stage of a layer split on its own GPU" : (o.batch_groups > 1 && !stages.empty())
? "it does not combine with --batch-groups (pipelined slot groups) yet"
? "it needs each stage of a layer split on its own GPU"
: !o.serve ? "it needs --serve" : nullptr;
// the groups it would run with (the default gives way to it: one group; a number or auto given pipelines)
if (why == nullptr && !stages.empty() && batch_groups_for(true).groups > 1)
why = "it does not combine with --batch-groups (pipelined slot groups) yet";
if (why != nullptr) {
std::fprintf(stderr, "strata generate: WARNING: --batch-mtp is off: %s\n", why);
batch_mtp = false;
@@ -4147,17 +4164,22 @@ int main(int argc, char** argv) {
}
// --batch-groups auto: the pipeline needs one group per GPU stage to keep every card busy (4 x R9700, 8 clients:
// 90 tok/s in one group, 136 in 2, 166 in 4). The most groups, at most one per stage, that divide the slots.
// The default (0.1.41: a layer split with --batch pipelines one group per stage; --batch-groups 1 opts out) gives
// way to --batch-mtp, which needs the serial windows: one group, said once.
int groups_said = 0;
auto resolve_groups_auto = [&] {
// default (0.1.41): a layer split with --batch pipelines one group per stage; --batch-groups 1 opts out
if (!o.batch_groups_set && !stages.empty() && o.batch > 1) o.batch_groups_auto = true;
if (!o.batch_groups_auto) return;
int best = 1;
for (int d = 2; d <= (int) stages.size() + 1 && d <= o.batch; ++d)
if (o.batch % d == 0) best = d;
if (stages.empty()) best = 1;
o.batch_groups = best;
std::fprintf(stderr, "strata generate: --batch-groups auto: %d group%s of %d slot%s\n", best, best == 1 ? "" : "s",
o.batch / best, o.batch / best == 1 ? "" : "s");
const auto r = batch_groups_for(batch_mtp);
if (!r.from_auto) return;
o.batch_groups = r.groups;
if (groups_said == r.groups) return; // (the second call, once the slots that fit are known, says nothing new)
groups_said = r.groups;
if (r.serial != strata::program::batch_groups::Serial::None)
std::fprintf(stderr, "strata generate: --batch-groups auto: 1 group of %d slot%s - %s does not run in pipelined "
"groups; --batch-groups %d would pipeline them and turn it off\n", o.batch,
o.batch == 1 ? "" : "s", strata::program::batch_groups::serial_what(r.serial), r.would_be);
else
std::fprintf(stderr, "strata generate: --batch-groups auto: %d group%s of %d slot%s\n", r.groups,
r.groups == 1 ? "" : "s", o.batch / r.groups, o.batch / r.groups == 1 ? "" : "s");
};
if (o.batch > 0) resolve_groups_auto();
if (o.batch > 0 && o.batch_groups > 1 && (stages.empty() || o.batch % o.batch_groups != 0)) {