With --batch-groups above 1 on a layer split the pipelined batch loop never starts a round of the adaptive VRAM tier (the serial batch windows start one every --adapt-every windows). While the slots are busy the tier only moves when they go back to the solo path, so a fresh engine keeps its start-up profile for minutes. STRATA_PIPE_ADAPT_EVERY=N (opt-in; unset, 0 or not a number is off): after N group windows pump starts no new group on the first stage, lets the groups in flight finish, then runs one round as batch_step does between serial windows, adapt() and apply_pending(true), so nothing in flight reads a cache slot while experts swap and the new experts have landed before the next launch. Not while a prompt is read beside the slots (in_prompt_read, its loan of cache slots), not with --adapt-async, not while the last round's copies are in flight, not with the tier off. The rule is two pure functions in include/strata/program/batch_groups.hpp (pipe_adapt_every, pipe_adapt_due) with 12 new cases in batch_groups_test. With the switch set the engine says so once at start and the "strata batch (pipelined ...)" line adds the rounds, the experts swapped in and the time spent. docs/BATCHING.md documents the switch with the author's table (2x RTX 5090, six streams, 309 to 410 rows/s over eight bursts after a fresh start, two engines per setting). Reviewed: unset costs one counter increment per group window and one false check where a group starts, and prints no new line. A due round cannot wait forever: no new group starts, the groups in flight finish, then the round runs. A prompt read sets in_prompt_read before the reader thread starts (including STRATA_PIPED_CONCURRENT) and clears it after the reader joined; the drain after the read runs the round if it is due. Tests: batch_groups_test (the new cases). Not covered and still the author's to show (the PR is a draft): a soak with prompts read beside the slots, a Linux run, another GPU pair, more than two stages, and exactness settings with the switch set. The model gate is written down.
169 lines
7.8 KiB
C++
169 lines
7.8 KiB
C++
// 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 (or --adapt-async 1) turns that default into one group, and says which feature did it;
|
|
// 4. a number or `auto` given explicitly is honoured, with or without those features;
|
|
// 5. no layer split: the number given (1) stays;
|
|
// 6. STRATA_PIPE_ADAPT_EVERY: off unless a positive number; a round is due after N group windows, never with the tier
|
|
// off, beside --adapt-async, while a prompt is read or while the last round's copies are in flight.
|
|
#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 production shape: parallel 2 on a 2-GPU split with --batch-mtp
|
|
bg::Input i = in(2, 1);
|
|
i.batch_mtp = true;
|
|
auto r = bg::resolve(i);
|
|
check(r.groups == 2 && r.from_auto && r.serial == bg::Serial::None && r.mtp_dropped,
|
|
"--batch-mtp, nothing given: the pipeline wins, --batch-mtp is dropped");
|
|
i.mtp_serial = true;
|
|
r = bg::resolve(i);
|
|
check(r.groups == 1 && r.from_auto && r.serial == bg::Serial::BatchMtp && r.would_be == 2 && !r.mtp_dropped,
|
|
"STRATA_BATCH_MTP_SERIAL: one group, because of --batch-mtp");
|
|
check(bg::serial_what(r.serial)[0] == '-', "the reason names the feature");
|
|
}
|
|
{
|
|
bg::Input i = in(2, 1);
|
|
i.adapt_async = true;
|
|
const auto r = bg::resolve(i);
|
|
check(r.groups == 1 && r.serial == bg::Serial::AdaptAsync, "--adapt-async 1, nothing given: one group");
|
|
}
|
|
{
|
|
bg::Input i = in(2, 1);
|
|
i.batch_mtp = true;
|
|
i.adapt_async = true;
|
|
check(bg::resolve(i).serial == bg::Serial::AdaptAsync, "both: --adapt-async 1 still gives one group");
|
|
i.mtp_serial = true;
|
|
check(bg::resolve(i).serial == bg::Serial::BatchMtp, "both with STRATA_BATCH_MTP_SERIAL: --batch-mtp is named");
|
|
}
|
|
{ // 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");
|
|
}
|
|
{ // PROPOSED NVIDIA default: two cards, nothing given: serial windows (measured +12..16% on 2x A4000)
|
|
bg::Input i = in(4, 1);
|
|
i.nv_serial_faster = true;
|
|
auto r = bg::resolve(i);
|
|
check(r.groups == 1 && r.from_auto && r.serial == bg::Serial::TwoCardsSerialFaster && r.would_be == 2,
|
|
"nv_serial_faster, 2 cards, 4 slots, nothing given: one group, named");
|
|
check(bg::serial_what(r.serial)[0] == 's', "the reason names the measurement");
|
|
check(bg::resolve(in(4, 1)).groups == 2, "flag off: the pipeline default stays");
|
|
i = in(8, 1); i.nv_serial_faster = true; // measured too: +15%
|
|
check(bg::resolve(i).groups == 1, "8 slots (measured +15%): serial too");
|
|
i = in(4, 3); i.nv_serial_faster = true;
|
|
check(bg::resolve(i).groups == 4, "4 cards (not measured): the pipeline stays");
|
|
i = in(4, 1); i.nv_serial_faster = true; i.batch_mtp = true;
|
|
check(bg::resolve(i).groups == 2 && bg::resolve(i).mtp_dropped, "with --batch-mtp the 0.1.43.1 rule is unchanged");
|
|
i = in(4, 1); i.nv_serial_faster = true; i.set = true; i.auto_given = true;
|
|
check(bg::resolve(i).groups == 2, "--batch-groups auto given: the pipeline");
|
|
i.auto_given = false; i.given = 2;
|
|
check(bg::resolve(i).groups == 2, "--batch-groups 2 given: 2");
|
|
}
|
|
{ // explicit values are honoured
|
|
bg::Input i = in(4, 1);
|
|
i.set = true;
|
|
i.given = 2;
|
|
i.batch_mtp = true;
|
|
i.adapt_async = 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)");
|
|
}
|
|
|
|
// STRATA_PIPE_ADAPT_EVERY
|
|
check(bg::pipe_adapt_every(nullptr) == 0 && bg::pipe_adapt_every("") == 0 && bg::pipe_adapt_every("0") == 0,
|
|
"pipe adapt: unset, empty or 0 is off");
|
|
check(bg::pipe_adapt_every("-5") == 0 && bg::pipe_adapt_every("off") == 0, "pipe adapt: negative or not a number is off");
|
|
check(bg::pipe_adapt_every("128") == 128 && bg::pipe_adapt_every("1") == 1, "pipe adapt: a positive number is the interval");
|
|
{
|
|
bg::PipeAdapt p;
|
|
p.every = 128;
|
|
p.tier_on = true;
|
|
p.windows = 127;
|
|
check(!bg::pipe_adapt_due(p), "pipe adapt: not before N group windows");
|
|
p.windows = 128;
|
|
check(bg::pipe_adapt_due(p), "pipe adapt: due after N group windows");
|
|
p.last = 128;
|
|
p.windows = 200;
|
|
check(!bg::pipe_adapt_due(p), "pipe adapt: counted again from the last round");
|
|
p.windows = 256;
|
|
check(bg::pipe_adapt_due(p), "pipe adapt: due N windows after the last round");
|
|
bg::PipeAdapt q = p;
|
|
q.every = 0;
|
|
check(!bg::pipe_adapt_due(q), "pipe adapt: never when off");
|
|
q = p;
|
|
q.tier_on = false;
|
|
check(!bg::pipe_adapt_due(q), "pipe adapt: never with the adaptive tier off");
|
|
q = p;
|
|
q.async_tier = true;
|
|
check(!bg::pipe_adapt_due(q), "pipe adapt: never beside --adapt-async 1");
|
|
q = p;
|
|
q.prompt_read = true;
|
|
check(!bg::pipe_adapt_due(q), "pipe adapt: never while a prompt is read beside the slots");
|
|
q = p;
|
|
q.swaps_pending = true;
|
|
check(!bg::pipe_adapt_due(q), "pipe adapt: never while the last round's copies are in flight");
|
|
}
|
|
|
|
std::printf("%s\n", g_fail == 0 ? "batch_groups_test: all passed" : "batch_groups_test: FAILED");
|
|
return g_fail == 0 ? 0 : 1;
|
|
}
|