Verify and batch windows of up to 16 rows: HIP builds default to 16, narrow builds unchanged
A pipelined group of a layer split is its own window, so 32 slots on four cards were four groups of 8 and nothing larger could run. The window limit is now a build option (STRATA_WINDOW_MAX_T = auto | 8 | 16; auto is 16 for HIP, 8 for CUDA; SYCL and Metal never set it): include/strata/kernels/window_limits.hpp. A window of up to 8 rows runs exactly the kernels it ran before (HIP gfx1201 window 8 against main: 3096 of 3097 kernels identical, the other a debug variant; CUDA sm_86 and sm_60: identical or renamed but for a few prefill kernels NVVM compiles differently, with identical results). The code for 9 to 16 rows is only reached by a wider window: - per-row arrays of the verifier, the expert source tables (128 / 256 entries) and the remote / peer expert tables follow the window; CPU expert jobs stay at 8 tokens (a 9..16-row group is two jobs over the same expert); - the hyper-connection read is made in slices of 8 rows (its Q8_0 launch would otherwise skip rows); - the grouped expert kernels run a second pass (SKIP template argument) instead of a 16-entry shared array (51 KB, over the 48 KB static limit of CUDA); - resident_plan runs on 128 threads (up to 8 rows, as it was) or 256; MMVQ, bf16 GEMV, shared expert and MoE combine take 9..16 columns only in a wide build; the sm_60 packed path runs wide calls in passes of 8; - STRATA_P4_TIMING and STRATA_P4_TRACE (include/strata/program/pipe_probe.hpp): opt-in timing and trace of the pipelined windows, off unless set. Tests: src/core/window_limits_test.cpp (target window_limits_test). Real 16-row windows (--batch 64 on four stages, --batch 16 --batch-groups 1) decode the tokens they decode alone.
This commit is contained in:
1 parent
46c152a131
commit
9d3c8c3664
23 files changed
+678
-122
No files matched your search
@@ -7,6 +7,7 @@
|
||||
#include "strata/core/remote_experts.hpp"
|
||||
#include "strata/core/peer_experts.hpp"
|
||||
#include "strata/kernels/cpu/expert_layout.hpp"
|
||||
#include "strata/kernels/window_limits.hpp"
|
||||
#include "strata/artifact/gguf_reader.hpp"
|
||||
|
||||
#include "strata/core/pinned.hpp"
|
||||
@@ -4786,10 +4787,10 @@ void expert_pool_dispatch(void* user, const float* x_f, const int32_t* ids, cons
|
||||
|
||||
namespace {
|
||||
// the verify window's per-entry tables in `expert_pool_dispatch_multi` (`kind`, `distinct`, `first_of`)
|
||||
// are fixed arrays of this many entries: MAXT tokens of the model's 10 routed experts must fit, and a larger k is
|
||||
// refused at run time rather than written past them.
|
||||
constexpr int64_t kMaxWindowEntries = 128;
|
||||
static_assert(strata::kernels::cpu::MAXT * 10 <= kMaxWindowEntries, "a verify window's entries overflow the tables");
|
||||
// are fixed arrays of this many entries: a window's rows (kWindowMaxT) of the model's 10 routed experts must fit, and a
|
||||
// larger k is refused at run time rather than written past them. 128 for the 8-row window (as it was), 256 for 16.
|
||||
constexpr int64_t kMaxWindowEntries = strata::kernels::kWindowMaxT <= 8 ? 128 : 256;
|
||||
static_assert(strata::kernels::kWindowMaxT * 10 <= kMaxWindowEntries, "a verify window's entries overflow the tables");
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
@@ -4813,7 +4814,7 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32
|
||||
float* out, strata::kernels::cpu::NativeArithmetic arithmetic) {
|
||||
using namespace strata::kernels::cpu;
|
||||
if (d.failed) return;
|
||||
if (n_tok < 1 || n_tok > MAXT) {
|
||||
if (n_tok < 1 || n_tok > strata::kernels::kWindowMaxT) {
|
||||
d.failed = true;
|
||||
d.fail = "a verify window has more tokens than the multi-token expert kernel takes";
|
||||
d.fail_layer = d.layers;
|
||||
@@ -4832,12 +4833,13 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32
|
||||
d.fail_layer = d.layers;
|
||||
return;
|
||||
}
|
||||
if ((int64_t) d.act_multi.size() < n_tok) d.act_multi.resize((size_t) MAXT);
|
||||
if ((int64_t) d.act_multi.size() < n_tok) d.act_multi.resize((size_t) strata::kernels::kWindowMaxT);
|
||||
const ExpertLayout& lay = expert_layout();
|
||||
const bool native = lay.native;
|
||||
if (native && d.nact_multi.size() < (size_t) MAXT * kNativeActBytes) d.nact_multi.resize((size_t) MAXT * kNativeActBytes);
|
||||
if (native && d.nact_multi.size() < (size_t) strata::kernels::kWindowMaxT * kNativeActBytes)
|
||||
d.nact_multi.resize((size_t) strata::kernels::kWindowMaxT * kNativeActBytes);
|
||||
if (d.job_of.size() != (size_t) d.n_expert) d.job_of.assign((size_t) d.n_expert, (int16_t) -1);
|
||||
if (d.jobs_multi.size() < (size_t) (n_tok * k)) d.jobs_multi.resize((size_t) (MAXT * k));
|
||||
if (d.jobs_multi.size() < (size_t) (n_tok * k)) d.jobs_multi.resize((size_t) (strata::kernels::kWindowMaxT * k));
|
||||
static const bool ptrace = std::getenv("STRATA_POOL_TRACE") != nullptr;
|
||||
auto pt = [&](const char* what, long long a = -1) {
|
||||
if (ptrace) { std::fprintf(stderr, "pool trace: layer %lld %s %lld\n", (long long) d.layers, what, a); std::fflush(stderr); }
|
||||
@@ -5151,6 +5153,17 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32
|
||||
++d.cold_zc;
|
||||
}
|
||||
}
|
||||
if (d.jobs_multi[(size_t) jo].nt == MAXT) {
|
||||
// a window of 9..16 rows routes more than MAXT tokens to this expert: the kernels and the pool's scratch
|
||||
// take MAXT tokens a job, so the rest are a further job over the same blob (each token's rows are its own,
|
||||
// so the split changes no value; the blob is read once more)
|
||||
const int16_t prev = jo;
|
||||
jo = (int16_t) njobs++;
|
||||
ExpertJobMulti& nj = d.jobs_multi[(size_t) jo];
|
||||
nj.blob = d.jobs_multi[(size_t) prev].blob;
|
||||
nj.fmt = d.jobs_multi[(size_t) prev].fmt;
|
||||
nj.nt = 0;
|
||||
}
|
||||
ExpertJobMulti& jb = d.jobs_multi[(size_t) jo];
|
||||
jb.act[jb.nt] = &d.act_multi[(size_t) t];
|
||||
jb.nact[jb.nt] = native ? d.nact_multi.data() + (size_t) t * kNativeActBytes : nullptr;
|
||||
|
||||
Reference in new issue
Block a user