From c30656aaf908db8181edd8ce16a97a84911bba63 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Mon, 26 Oct 2026 00:27:14 +0100 Subject: [PATCH] route: residency-biased routing is on by default at 2.0 on a card of 13 GiB or less The router's top-10 is picked again with a logit bonus for the experts already in VRAM (route_prior.cu); the weights stay the router's. Measured on an RTX 3060 12 GB, IQ3_XXS, 5 interleaved pairs of fresh engines: story 44.2 -> 60.9 tok/s (+37.6%), code 47.3 -> 64.0 (+35.2%); =1.0 gives +22.6% / +24.6%. Three more pairs against the switch itself read +23.6% / +36.9%. It changes which experts run, so it is a default only where the expert cache cannot hold the model, and the owner approved that trade for 12 GB cards. It is NOT a default on a bigger card: on an RTX PRO 5000 72 GB it measures -1.9% / -0.5% and on 2x RTX A4000 -4.2% / +11.0% (3 pairs each); both were re-run after this change and are unchanged (201.7 / 246.9 and 87.1 / 107.1 tok/s). STRATA_ROUTE_PRIOR=0 turns it off and any explicit value wins. --- src/core/verify.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/core/verify.cpp b/src/core/verify.cpp index 3d6f48b2..145e9d76 100644 --- a/src/core/verify.cpp +++ b/src/core/verify.cpp @@ -1966,9 +1966,23 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { mb.logits = logits_ + t * NE; mb.ids = ids_ + t * K; mb.weights = w_ + t * K; if (!moe_route(wt, g, l, K, mb, mixed_ + t * N, cs, err, nullptr)) return false; } - // STRATA_ROUTE_PRIOR=lambda (opt-in, changes the output): the top-10 picked again with a logit bonus for the - // resident experts; the weights stay the router's (route_prior.cu) - static const float route_prior = [] { const char* v = std::getenv("STRATA_ROUTE_PRIOR"); return v ? (float) std::atof(v) : 0.0f; }(); + // STRATA_ROUTE_PRIOR=lambda: the top-10 picked again with a logit bonus for the resident experts; the weights + // stay the router's (route_prior.cu). **On by default at 2.0 on a card of 13 GiB or less**, where the expert + // cache cannot hold the model: measured on an RTX 3060 12 GB (IQ3_XXS), 5 interleaved pairs, story 44.2 -> + // 60.9 tok/s (+37.6%) and code 47.3 -> 64.0 (+35.2%); at 1.0 it is +22.6% / +24.6%. The owner approved the + // quality trade for 12 GB cards (it changes which experts run). It is NOT a default where the cache holds + // the model: on an RTX PRO 5000 72 GB it measured -1.9% / -0.5% and on 2x RTX A4000 -4.2% / +11.0%, so + // STRATA_ROUTE_PRIOR=0 turns it off and any explicit value wins. + static const float route_prior = [] { + const char* v = std::getenv("STRATA_ROUTE_PRIOR"); + if (v != nullptr) return (float) std::atof(v); + int dev = 0; + if (cudaGetDevice(&dev) != cudaSuccess) return 0.0f; + size_t free_b = 0, total_b = 0; + if (cudaMemGetInfo(&free_b, &total_b) != cudaSuccess) return 0.0f; + cudaGetLastError(); // drop what a query on a device without a context leaves behind + return (double) total_b / 1073741824.0 <= 13.0 ? 2.0f : 0.0f; + }(); if (route_prior > 0.0f && NE == 512 && K == 10 && hits_.d_res != nullptr) route_prior_top10(logits_ + tb * NE, hits_.d_res + l * g.n_expert, route_prior, ids_ + tb * K, w_ + tb * K, n, cs); if (route_resident_cfg().margin > 0.0f && NE == 512 && K == 10 && hits_.d_res != nullptr) {