STRATA_ROUTE_TAIL_SKIP=7 on by default on CUDA serve (=0 off): single GPU and layer splits; not with every expert in VRAM, --batch slots, a peer or helper GPU, HIP; one start-up line names the opt-out

This commit is contained in:
Niko1221 committed 2026-10-09 22:52:22 +02:00
1 parent 8b0c241ca0
commit b4e3407bd2
3 files changed
+42 -6

No files matched your search

+4
View File
@@ -463,6 +463,10 @@ void expert_pool_dispatch(void* user, const float* x_f, const int32_t* ids, cons
/// Plan v0.3 P6: the pool for a verify window of `n_tok` tokens. `x_f` is (n_tok, n_embd), `ids` (n_tok, k) and
/// `out` (n_tok * k, n_embd). Each distinct missed expert is computed once for all the tokens routed to it;
/// resident experts' rows are zeroed (the GPU adds them). Requires `host_res` (the token-graph residency).
/// STRATA_ROUTE_TAIL_SKIP rank (0: off). Unset in the environment: 0 until the serve start-up sets the default.
int tail_skip_rank();
void set_tail_skip_rank(int r);
void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32_t* ids, int64_t n_tok, int64_t k,
float* out);
+19 -6
View File
@@ -3370,6 +3370,23 @@ constexpr int64_t kMaxWindowEntries = 128;
static_assert(strata::kernels::cpu::MAXT * 10 <= kMaxWindowEntries, "a verify window's entries overflow the tables");
} // namespace
namespace {
// STRATA_ROUTE_TAIL_SKIP: the rank from which a missed expert that every token of the window routes that low is skipped. An
// explicit environment value is read once; the serve start-up (generate.cpp) sets the CUDA default where it applies.
std::atomic<int> g_tail_skip_rank{-1}; // -1: not resolved yet
} // namespace
int tail_skip_rank() {
int r = g_tail_skip_rank.load(std::memory_order_relaxed);
if (r < 0) {
const char* v = std::getenv("STRATA_ROUTE_TAIL_SKIP");
r = v != nullptr ? std::atoi(v) : 0;
r = r > 0 && r < 10 ? r : 0;
g_tail_skip_rank.store(r, std::memory_order_relaxed);
}
return r;
}
void set_tail_skip_rank(int r) { g_tail_skip_rank.store(r > 0 && r < 10 ? r : 0, std::memory_order_relaxed); }
void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32_t* ids, int64_t n_tok, int64_t k,
float* out) {
using namespace strata::kernels::cpu;
@@ -3431,14 +3448,10 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32
!(d.peer != nullptr && d.peer->has(d.layers, e)) && !helper_holds(e)) ++nmiss;
}
}
// STRATA_ROUTE_TAIL_SKIP=R (opt-in, changes the output): a missed expert that EVERY token of the window routes
// STRATA_ROUTE_TAIL_SKIP=R (default 7 on CUDA serve, =0 off; changes the output): a missed expert that EVERY token of the window routes
// only at rank >= R (the smallest weights of the top-10) is neither copied nor computed; its contribution is
// zero, without renormalisation (the others keep the weight the router gave them). Less PCIe and CPU work.
static const int tail_rank = [] {
const char* v = std::getenv("STRATA_ROUTE_TAIL_SKIP");
const int r = v != nullptr ? std::atoi(v) : 0;
return r > 0 && r < 10 ? r : 0;
}();
const int tail_rank = tail_skip_rank();
bool skip_d[kMaxWindowEntries];
for (int q = 0; q < nd; ++q) skip_d[q] = false;
if (tail_rank > 0 && d.peer == nullptr && d.remote_count == 0) {
+19
View File
@@ -8012,6 +8012,25 @@ int main(int argc, char** argv) {
drive.d.pcie_num = std::max(0, std::min(256, (int) (o.pcie_frac * 256.0 + 0.5)));
const bool all_experts_resident = !host_res.empty() &&
std::all_of(host_res.begin(), host_res.end(), [](int32_t r) { return r >= 0; });
// STRATA_ROUTE_TAIL_SKIP: ON BY DEFAULT on CUDA builds (owner decision, 0.1.42): a missed expert that every token of
// a verify window routes at rank 7 or lower is neither copied nor computed (answers differ slightly from 0.1.41,
// KL ~0.003-0.006; docs/DETAILS.md). =0 restores 0.1.41's bytes. Nothing to do, so no default and no line, when every
// expert is in VRAM; off with --batch slots (a window then mixes requests, and one request's skip would depend on
// another's tokens) and, as in the dispatch, with a peer or helper GPU. A layer split is fine: each stage skips by itself.
{
const char* tse = std::getenv("STRATA_ROUTE_TAIL_SKIP");
#if !defined(STRATA_USE_HIP)
const bool tail_default_ok = tse == nullptr && !all_experts_resident && o.batch == 0 && o.peer_device < 0;
#else
const bool tail_default_ok = false; // HIP and SYCL stay as they were
#endif
if (tail_default_ok) strata::core::set_tail_skip_rank(7);
if (strata::core::tail_skip_rank() > 0 && !all_experts_resident)
std::fprintf(stderr, "strata serve: STRATA_ROUTE_TAIL_SKIP=%d is ON%s: a missed expert that every token of a verify window routes at rank %d or "
"lower is skipped (+15..25%% decode on 8-16 GB cards, answers differ slightly from 0.1.41); "
"STRATA_ROUTE_TAIL_SKIP=0 turns it off\n", strata::core::tail_skip_rank(),
tse == nullptr ? " (default)" : "", strata::core::tail_skip_rank());
}
if (o.adapt_every > 0 && o.adapt_swaps > 0 && !all_experts_resident)
drive.d.usage.assign((size_t) (g.n_layers * g.n_expert), 0.0f);
// #477 --expert-profile-save: what the adaptive tier learned, kept across restarts (opt-in; off: `heat` stays