Merge f-028-par
This commit is contained in:
commit
32f0c44f08
29 files changed
+1024
-128
No files matched your search
+64
-21
@@ -101,6 +101,7 @@
|
||||
#include "strata/spec/suffix_drafter.hpp"
|
||||
#include "strata/spec/spec_start.hpp"
|
||||
#include "strata/program/batch_groups.hpp"
|
||||
#include "strata/program/pipe_probe.hpp"
|
||||
#include "strata/kernels/cvec.hpp"
|
||||
#include "strata/core/progress.hpp"
|
||||
#include "strata/core/device.hpp"
|
||||
@@ -3756,7 +3757,14 @@ int main(int argc, char** argv) {
|
||||
if (o.lookup_chain > 0 && o.spec >= 2) {
|
||||
if (o.mtp_max_t == 0) o.mtp_max_t = o.spec;
|
||||
const int chain_base = o.spec;
|
||||
o.spec = std::max(chain_base, std::min(std::max(chain_base, o.mtp_max_t) + o.lookup_chain, 8)); // kVerifyMaxT
|
||||
o.spec = std::max(chain_base, std::min(std::max(chain_base, o.mtp_max_t) + o.lookup_chain, 8)); // kVerifyNarrowT
|
||||
}
|
||||
// A speculative (solo) window holds at most kVerifyNarrowT rows: the hand-offs, the penalty history and the drafters'
|
||||
// buffers are sized for that. Only a plain --batch forms the wider windows of a build with kVerifyMaxT > 8.
|
||||
if (o.spec > (int) strata::kernels::kVerifyNarrowT) {
|
||||
std::fprintf(stderr, "strata generate: --spec %d: a speculative window holds 2..%d tokens\n", o.spec,
|
||||
(int) strata::kernels::kVerifyNarrowT);
|
||||
return 1;
|
||||
}
|
||||
// dflash2-kern: right after the start the resident experts are the profile's, not this text's; a speculative round carries
|
||||
// 2-5 tokens, so the adaptive tier (one swap round per adapt_every VERIFY rounds) learned the text 2-5 times slower per
|
||||
@@ -6003,17 +6011,19 @@ int main(int argc, char** argv) {
|
||||
int pm_drafts = 0;
|
||||
if (piped_mtp) {
|
||||
pm_drafts = std::clamp(std::atoi(std::getenv("STRATA_PIPED_MTP")), 1,
|
||||
std::max(1, std::min(o.spec - 1, (int) strata::kernels::kVerifyMaxT - 1)));
|
||||
std::max(1, std::min(o.spec - 1, (int) strata::kernels::kVerifyNarrowT - 1)));
|
||||
}
|
||||
// The verifiers' window: the solo path's drafts (--spec rows), the plain batch windows (the slots) and, with
|
||||
// STRATA_PIPED_MTP, a group's rows: its slots, each its token and its proposals ((slots) * (1 + proposals), one slot
|
||||
// per group = at most --spec rows). A function, not a number: --batch (the slots that fit) and the groups are final
|
||||
// only after this point, at the verifiers' init, and the plain value must stay what it was there.
|
||||
auto batch_max_t = [&]() -> int {
|
||||
if (batch_mtp && !piped_mtp) return (int) strata::kernels::kVerifyMaxT;
|
||||
// (--batch-mtp and STRATA_PIPED_MTP draft with the draft layer's kernels, built for the narrow window: their windows
|
||||
// stay at most kVerifyNarrowT rows; only the plain batch windows are wide)
|
||||
if (batch_mtp && !piped_mtp) return (int) strata::kernels::kVerifyNarrowT;
|
||||
const int plain = std::max(o.spec, std::min(o.batch, (int) strata::kernels::kVerifyMaxT));
|
||||
const int group_rows = (piped_mtp && o.batch_groups > 1 && o.batch > 0)
|
||||
? std::min<int>(strata::kernels::kVerifyMaxT, (o.batch / o.batch_groups) * (1 + pm_drafts)) : 0;
|
||||
? std::min<int>(strata::kernels::kVerifyNarrowT, (o.batch / o.batch_groups) * (1 + pm_drafts)) : 0;
|
||||
return std::max(plain, group_rows);
|
||||
};
|
||||
// The most slots, up to n, whose windows hold at most kVerifyMaxT rows each: n itself up to that, more only as
|
||||
@@ -6149,10 +6159,10 @@ int main(int argc, char** argv) {
|
||||
why = buf;
|
||||
} else if (sc != nullptr && sc[0] != '\0' && sc[0] != '0') {
|
||||
why = "it does not combine with STRATA_BATCH_SELF_COMMIT (the window would keep its rows itself)";
|
||||
} else if ((o.batch / o.batch_groups) * (1 + pm_drafts) > (int) strata::kernels::kVerifyMaxT) {
|
||||
} else if ((o.batch / o.batch_groups) * (1 + pm_drafts) > (int) strata::kernels::kVerifyNarrowT) {
|
||||
std::snprintf(buf, sizeof buf, "a group's window would hold %d rows (%d slots x %d), more than %d",
|
||||
(o.batch / o.batch_groups) * (1 + pm_drafts), o.batch / o.batch_groups, 1 + pm_drafts,
|
||||
(int) strata::kernels::kVerifyMaxT);
|
||||
(int) strata::kernels::kVerifyNarrowT);
|
||||
why = buf;
|
||||
}
|
||||
if (why != nullptr) {
|
||||
@@ -6215,7 +6225,7 @@ int main(int argc, char** argv) {
|
||||
const strata::core::OnDevice on_mtp(last_st && !mtp_first ? last_st->dev : -1);
|
||||
// --pipeline-windows 2: 8 rows (the chain runs on past the window in flight: its drafts, its bonus token and
|
||||
// the next window's drafts), and the round/step graphs carry the forcing kernel
|
||||
const int mtp_t = o.pipeline_windows >= 2 ? strata::kernels::kVerifyMaxT : o.spec;
|
||||
const int mtp_t = o.pipeline_windows >= 2 ? strata::kernels::kVerifyNarrowT : o.spec;
|
||||
if (o.pipeline_windows >= 2) mtp.set_force_capture(true);
|
||||
if (!o.mtp.empty() && !mtp.load(o.mtp, draft_geometry, last_st && !mtp_first ? last_st->ss : ss, mtp_t, err, o.mtp_window)) { std::fprintf(stderr, "strata generate: %s%s\n", err.c_str(), vram_free_note().c_str()); return 1; }
|
||||
mtp.set_ple_session(&ss);
|
||||
@@ -9879,7 +9889,9 @@ int main(int argc, char** argv) {
|
||||
// the widest window; a request without penalties gets a null buffer and takes the byte-for-byte
|
||||
// neutral path (no upload, no buffer handed to the sampler).
|
||||
constexpr int kPenaltyWindowCap = 4096;
|
||||
constexpr size_t kHistSlots = (size_t) kPenaltyWindowCap * (size_t) strata::kernels::kVerifyMaxT;
|
||||
// (the widest window the run can have: a batch of more than kVerifyNarrowT slots is the only way to a wider one)
|
||||
const size_t kHistSlots = (size_t) kPenaltyWindowCap *
|
||||
(size_t) (o.batch > strata::kernels::kVerifyNarrowT ? strata::kernels::kVerifyMaxT : strata::kernels::kVerifyNarrowT);
|
||||
int32_t* d_hist = nullptr;
|
||||
std::vector<int32_t> hist_stage(kHistSlots, -1);
|
||||
const int hist_dev = last_st ? last_st->dev : -1; // with the head: the last stage's device
|
||||
@@ -9947,11 +9959,15 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
if (n_stages > 1) {
|
||||
// pipelined slot groups write their rows at hbase = group * rows-per-group, so with more than
|
||||
// kVerifyMaxT slots in groups the hand-off holds one row per slot (otherwise kVerifyMaxT, as before)
|
||||
// kVerifyNarrowT slots in groups the hand-off holds one row per slot (otherwise kVerifyNarrowT, as before; a
|
||||
// wide build holds more only for a batch of more than that: the buffer is not made larger for a run that
|
||||
// never forms a window of 9..16 rows)
|
||||
// (STRATA_PIPED_MTP: per slot its token and up to pm_drafts proposals)
|
||||
const int hrows = piped_mtp ? std::max<int>(strata::kernels::kVerifyMaxT, (1 + pm_drafts) * o.batch)
|
||||
: !batch_mtp && o.batch_groups > 1 ? std::max<int>(strata::kernels::kVerifyMaxT, o.batch)
|
||||
: strata::kernels::kVerifyMaxT;
|
||||
const int hrows = piped_mtp ? std::max<int>(strata::kernels::kVerifyNarrowT, (1 + pm_drafts) * o.batch)
|
||||
: !batch_mtp && o.batch_groups > 1 ? std::max<int>(strata::kernels::kVerifyNarrowT, o.batch)
|
||||
: !batch_mtp ? std::max<int>(strata::kernels::kVerifyNarrowT,
|
||||
std::min<int>(o.batch, strata::kernels::kVerifyMaxT))
|
||||
: strata::kernels::kVerifyNarrowT;
|
||||
const size_t hb = (size_t) hrows * (size_t) strata::core::Verifier::handoff_floats(g) * sizeof(float);
|
||||
std::vector<float*> hand((size_t) n_stages - 1, nullptr);
|
||||
for (float*& h : hand) {
|
||||
@@ -9990,7 +10006,7 @@ int main(int argc, char** argv) {
|
||||
for (int st = 0; st < n_stages; ++st) {
|
||||
stage_ver(st).set_stage(st == 0 ? 0 : split_at[(size_t) st - 1], st + 1 < n_stages ? split_at[(size_t) st] : -1,
|
||||
st == 0 ? nullptr : hand[(size_t) st - 1], st + 1 < n_stages ? hand[(size_t) st] : nullptr);
|
||||
if (hrows > strata::kernels::kVerifyMaxT) stage_ver(st).set_handoff_rows(hrows);
|
||||
if (hrows > strata::kernels::kVerifyNarrowT) stage_ver(st).set_handoff_rows(hrows);
|
||||
if (overlap)
|
||||
stage_ver(st).set_handoff_flags(st == 0 ? nullptr : hflag_h[(size_t) st - 1],
|
||||
st == 0 ? nullptr : hflag_d[(size_t) st - 1],
|
||||
@@ -10043,7 +10059,7 @@ int main(int argc, char** argv) {
|
||||
// watchdog's verifier), and the drafter's own row buffer, which either parity's rows are copied into
|
||||
float* pl_mtp_R = nullptr;
|
||||
if (pipe) {
|
||||
const size_t hb = (size_t) strata::kernels::kVerifyMaxT *
|
||||
const size_t hb = (size_t) strata::kernels::kVerifyNarrowT *
|
||||
(size_t) strata::core::Verifier::handoff_floats(g) * sizeof(float);
|
||||
std::vector<float*> hand_b((size_t) n_stages - 1, nullptr); // the odd windows' hand-off per boundary
|
||||
for (float*& h : hand_b) {
|
||||
@@ -10075,7 +10091,7 @@ int main(int argc, char** argv) {
|
||||
gs.dev, st + 1, err.c_str());
|
||||
return 1;
|
||||
}
|
||||
if (last && !mtp_first && cudaMalloc((void**) &pl_mtp_R, (size_t) strata::kernels::kVerifyMaxT * (size_t) (g.hc * g.n_embd) *
|
||||
if (last && !mtp_first && cudaMalloc((void**) &pl_mtp_R, (size_t) strata::kernels::kVerifyNarrowT * (size_t) (g.hc * g.n_embd) *
|
||||
sizeof(float)) != cudaSuccess) {
|
||||
std::fprintf(stderr, "strata serve: --pipeline-windows: the drafter's row buffer does not fit\n");
|
||||
return 1;
|
||||
@@ -10083,7 +10099,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
if (mtp_first) { // the drafter's row buffer on its own card (the first)
|
||||
const strata::core::OnDevice on_m(mtp.device());
|
||||
if (cudaMalloc((void**) &pl_mtp_R, (size_t) strata::kernels::kVerifyMaxT * (size_t) (g.hc * g.n_embd) *
|
||||
if (cudaMalloc((void**) &pl_mtp_R, (size_t) strata::kernels::kVerifyNarrowT * (size_t) (g.hc * g.n_embd) *
|
||||
sizeof(float)) != cudaSuccess) {
|
||||
std::fprintf(stderr, "strata serve: --pipeline-windows: the drafter's row buffer does not fit\n");
|
||||
return 1;
|
||||
@@ -10146,7 +10162,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
// STRATA_PIPED_MTP: the rows a group's commit replays after the verdict, one hand-off row each
|
||||
if (piped_mtp && bslot_ss.size() > 1 &&
|
||||
!vk.init_deferred_commit(std::max<int>(strata::kernels::kVerifyMaxT, (1 + pm_drafts) * o.batch), err)) {
|
||||
!vk.init_deferred_commit(std::max<int>(strata::kernels::kVerifyNarrowT, (1 + pm_drafts) * o.batch), err)) {
|
||||
std::fprintf(stderr, "strata serve: STRATA_PIPED_MTP, stage %zu: %s\n", k + 1, err.c_str());
|
||||
return 1;
|
||||
}
|
||||
@@ -12416,7 +12432,7 @@ int main(int argc, char** argv) {
|
||||
struct BSlot {
|
||||
bool active = false, stop = false;
|
||||
int32_t x = 0; ///< the token the next window feeds (not yet in the slot's state)
|
||||
std::array<int32_t, strata::kernels::kVerifyMaxT> draft{}; ///< the slot's next MTP proposal
|
||||
std::array<int32_t, strata::kernels::kVerifyNarrowT> draft{}; ///< the slot's next MTP proposal
|
||||
bool draft_ready = false;
|
||||
int n_drafts = 1; ///< STRATA_PIPED_MTP: how many of `draft` its next window checks
|
||||
int64_t p = 0; ///< its position
|
||||
@@ -12687,7 +12703,9 @@ int main(int argc, char** argv) {
|
||||
static size_t next_slot = 0;
|
||||
// Each MTP slot uses two rows; rotate slots when more than four are active.
|
||||
int A = 0;
|
||||
for (size_t offset = 0; offset < bs.size() && S + (batch_mtp ? 2 : 1) <= strata::kernels::kVerifyMaxT; ++offset) {
|
||||
// (--batch-mtp: two rows a slot, at most kVerifyNarrowT; the plain windows hold up to kVerifyMaxT)
|
||||
const int win_cap = batch_mtp ? (int) strata::kernels::kVerifyNarrowT : (int) strata::kernels::kVerifyMaxT;
|
||||
for (size_t offset = 0; offset < bs.size() && S + (batch_mtp ? 2 : 1) <= win_cap; ++offset) {
|
||||
const int b = (int) ((next_slot + offset) % bs.size());
|
||||
if (bs[(size_t) b].active) {
|
||||
first[A] = S;
|
||||
@@ -13131,11 +13149,28 @@ int main(int argc, char** argv) {
|
||||
p.last = pa_last;
|
||||
return strata::program::batch_groups::pipe_adapt_due(p);
|
||||
};
|
||||
// STRATA_P4_TIMING=1 / STRATA_P4_TRACE=PATH: where a pipelined window's time goes (pipe_probe.hpp; off: a branch)
|
||||
strata::program::PipeProbe p4(n_pipe, pg.size());
|
||||
// one turn: serve every running stage, hand finished groups on, start what can start
|
||||
auto pump = [&](bool may_start) -> bool {
|
||||
++pipe_tick;
|
||||
const strata::program::PipeProbe::PumpScope p4_scope(p4);
|
||||
if (p4.timing()) {
|
||||
int nb = 0, nf = 0;
|
||||
for (int k = 0; k < n_pipe; ++k) if (stage_group[(size_t) k] >= 0) ++nb;
|
||||
for (const PGroup& x : pg) if (x.inflight) ++nf;
|
||||
p4.busy(nb, nf);
|
||||
// a stage free with no group waiting at it = starved by the stage before, else it was only idle a moment
|
||||
for (int k = 1; k < n_pipe; ++k) {
|
||||
if (stage_group[(size_t) k] >= 0) continue;
|
||||
bool ready = false;
|
||||
for (size_t g2 = 0; g2 < pg.size() && !ready; ++g2) ready = pg[g2].inflight && pg[g2].stage == k;
|
||||
p4.free_stage(k, ready);
|
||||
}
|
||||
}
|
||||
if (bt_windows == 0 && !pipe_inflight()) {
|
||||
bt_start = Clock::now();
|
||||
p4.span_start(bt_start);
|
||||
bt_wait0 = ver.ms_wait; bt_pool0 = ver.ms_pool;
|
||||
bt_miss0 = drive.d.multi_misses; bt_hits0 = drive.d.cache_hits; bt_pcie0 = drive.d.pcie_experts;
|
||||
}
|
||||
@@ -13143,9 +13178,12 @@ int main(int argc, char** argv) {
|
||||
const int gi = stage_group[(size_t) k];
|
||||
if (gi < 0) continue;
|
||||
strata::core::Verifier& vk = stage_verifier(k);
|
||||
const auto p4_p0 = p4.now();
|
||||
const int r = vk.batch_poll(win_pool_fn, win_pool_user, err);
|
||||
p4.polled(p4_p0);
|
||||
if (r < 0) { std::printf("ERR %s\n", err.c_str()); return false; }
|
||||
if (r == 0) continue;
|
||||
p4.done(k, gi);
|
||||
if (batch_telemetry_enabled) stage_in_flight.complete(k, Clock::now());
|
||||
stage_group[(size_t) k] = -1;
|
||||
PGroup& G = pg[(size_t) gi];
|
||||
@@ -13153,6 +13191,7 @@ int main(int argc, char** argv) {
|
||||
// the last stage: the group's picks
|
||||
const int32_t* outb = vk.batch_out();
|
||||
if (pmtp && !pmtp_verdict(G, vk, outb)) return false;
|
||||
const strata::program::PipeProbe::VerdictScope p4_verdict(p4);
|
||||
for (int t = 0; t < G.S && !pmtp; ++t) {
|
||||
BSlot& sl = bs[(size_t) (gi * GS + t)];
|
||||
if (!sl.active) continue;
|
||||
@@ -13283,11 +13322,13 @@ int main(int argc, char** argv) {
|
||||
PGroup& G = pg[(size_t) pick];
|
||||
strata::core::progress().busy.store(true);
|
||||
if (batch_telemetry_enabled) stage_in_flight.launch(k, Clock::now());
|
||||
const auto p4_l0 = p4.now();
|
||||
if (!(pmtp ? stage_verifier(k).batch_launch_rows(G.rows, G.S, G.hbase, G.tok, G.pos, err)
|
||||
: stage_verifier(k).batch_launch(pick * GS, G.S, G.tok, G.pos, err))) {
|
||||
std::printf("ERR %s\n", err.c_str());
|
||||
return false;
|
||||
}
|
||||
p4.launched(k, pick, p4_l0);
|
||||
stage_group[(size_t) k] = pick;
|
||||
if (conc_serving) { // the doorbell thread may be waiting between windows: the launch above is seen
|
||||
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||
@@ -13324,6 +13365,7 @@ int main(int argc, char** argv) {
|
||||
if (pmtp && !pipe_inflight() && !batch_on() && !pmtp_settle()) return false;
|
||||
if (!pipe_inflight() && !batch_on() && bt_windows > 0) { // all idle: the timing line, as batch_step
|
||||
const double w = (double) bt_windows, wall = std::chrono::duration<double, std::milli>(Clock::now() - bt_start).count();
|
||||
p4.span_end(wall);
|
||||
char pa_txt[160] = "";
|
||||
if (pipe_adapt_every > 0)
|
||||
std::snprintf(pa_txt, sizeof pa_txt, "; adaptive tier (STRATA_PIPE_ADAPT_EVERY): %lld rounds, %lld experts "
|
||||
@@ -13334,6 +13376,7 @@ int main(int argc, char** argv) {
|
||||
if (pmtp)
|
||||
std::fprintf(stderr, " (%lld of %lld MTP proposals kept)", (long long) bt_accepted, (long long) bt_tokens);
|
||||
std::fprintf(stderr, "\n");
|
||||
p4.flush();
|
||||
pa_rounds = pa_swaps = 0;
|
||||
pa_ms = 0;
|
||||
for (int k = 0; k < n_pipe; ++k) {
|
||||
@@ -16339,7 +16382,7 @@ int main(int argc, char** argv) {
|
||||
++pl_on;
|
||||
// the chain over A, forced through B's drafts: B's bonus guess and the next window's drafts
|
||||
mtp.set_source_R(V1(A).final_R(0));
|
||||
chain_n = std::min(strata::kernels::kVerifyMaxT - 1, B.T + S_mtp - 1);
|
||||
chain_n = std::min(strata::kernels::kVerifyNarrowT - 1, B.T + S_mtp - 1);
|
||||
if (!mtp.chain_launch(A.T, outp.data(), A.p, a, B.tok + 1, B.T - 1, chain_n, chain_n, err))
|
||||
return die(err);
|
||||
chain_kind = 1;
|
||||
@@ -16368,7 +16411,7 @@ int main(int argc, char** argv) {
|
||||
B = PW{};
|
||||
if (!last) {
|
||||
mtp.set_source_R(V1(A).final_R(0));
|
||||
chain_n = strata::kernels::kVerifyMaxT - 1;
|
||||
chain_n = strata::kernels::kVerifyNarrowT - 1;
|
||||
if (!mtp.chain_launch(A.T, outp.data(), A.p, a, nullptr, 0, chain_n, chain_n, err))
|
||||
return die(err);
|
||||
chain_kind = 2;
|
||||
|
||||
Reference in new issue
Block a user