spec: faster start-up adaptation of the expert tier in speculative runs (swap every 2 verify rounds for the first 200, then the normal interval); default on sm_86 only, STRATA_SPEC_ADAPT_EVERY / STRATA_SPEC_ADAPT_WARM set it elsewhere, an explicit --adapt-every is kept

This commit is contained in:
Niko1221 committed 2026-10-21 19:45:52 +02:00
1 parent b7d5ea2f82
commit 2ccf57ec46
3 files changed
+47 -5

No files matched your search

+20 -5
View File
@@ -684,6 +684,10 @@ struct Options {
/// Plan v0.3 P6: every `adapt_every` rounds, swap up to `adapt_swaps` of the most-routed missing experts into
/// the VRAM tier in place of the least-routed resident ones (decayed counts). 0 = static residency.
int adapt_every = 4;
bool adapt_every_given = false; ///< --adapt-every was on the command line (the per-card warm-up interval below does not override it)
int adapt_warm_every = 0; ///< dflash2-kern: > 0: the interval for the first adapt_warm_rounds verify rounds of a speculative run
int64_t adapt_warm_rounds = 0;
int adapt_iv(int64_t rounds) const { return adapt_warm_every > 0 && rounds < adapt_warm_rounds ? adapt_warm_every : adapt_every; } ///< the interval in force at verify round `rounds`
float adapt_decay = 0.7f; ///< the usage counts are multiplied by this after each adaptation (--adapt-decay)
/// an expert is swapped into the VRAM tier only when its decayed routing count beats the one it replaces by more than
/// this (--adapt-min-gain; both the blocking and the asynchronous tier)
@@ -2606,7 +2610,7 @@ int main(int argc, char** argv) {
else if (a == "--mtp") o.mtp = next("--mtp");
else if (a == "--mtp-window") o.mtp_window = std::atoll(next("--mtp-window"));
else if (a == "--pcie-frac") o.pcie_frac = std::atof(next("--pcie-frac"));
else if (a == "--adapt-every") o.adapt_every = std::atoi(next("--adapt-every"));
else if (a == "--adapt-every") { o.adapt_every = std::atoi(next("--adapt-every")); o.adapt_every_given = true; }
else if (a == "--adapt-decay") o.adapt_decay = (float) std::atof(next("--adapt-decay"));
else if (a == "--adapt-min-gain") o.adapt_min_gain = (float) std::atof(next("--adapt-min-gain"));
else if (a == "--adapt-async") o.adapt_async = std::atoi(next("--adapt-async")) != 0 ? 1 : 0;
@@ -2810,7 +2814,7 @@ int main(int argc, char** argv) {
same = cudaDeviceGetAttribute(&m, cudaDevAttrComputeCapabilityMajor, d) == cudaSuccess &&
cudaDeviceGetAttribute(&n, cudaDevAttrComputeCapabilityMinor, d) == cudaSuccess && m == m0 && n == n0;
}
if (same) strata::core::apply_nv_defaults(m0, n0);
if (same) { strata::core::apply_nv_defaults(m0, n0); strata::core::apply_spec_adapt_default(m0, n0); }
}
(void) cudaGetLastError();
}
@@ -3179,6 +3183,17 @@ int main(int argc, char** argv) {
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
}
// 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
// token. For the first STRATA_SPEC_ADAPT_WARM rounds it swaps every STRATA_SPEC_ADAPT_EVERY rounds (set per card by
// nv_defaults, where measured); later the normal interval. An explicit --adapt-every is kept as it is.
if (!o.adapt_every_given && o.spec >= 2 && o.adapt_every > 0) {
const char* e = std::getenv("STRATA_SPEC_ADAPT_EVERY");
const char* w = std::getenv("STRATA_SPEC_ADAPT_WARM");
const int n = e ? std::atoi(e) : 0;
const long long wr = w ? std::atoll(w) : 0;
if (n > 0 && n < o.adapt_every && wr > 0) { o.adapt_warm_every = n; o.adapt_warm_rounds = wr; }
}
strata::core::layer_set_shared_early(!o.shared_late);
if (!o.native_preset.empty()) {
try {
@@ -14292,7 +14307,7 @@ int main(int argc, char** argv) {
}
if (pl_adapt_thr.joinable()) return true; // still adapting
pl_apply();
if (!drive.d.usage.empty() && o.adapt_every > 0 && (rounds % o.adapt_every) == 0 && pending.empty() &&
if (!drive.d.usage.empty() && o.adapt_every > 0 && (rounds % o.adapt_iv(rounds)) == 0 && pending.empty() &&
!exch_wait) {
pl_adapt_done = false;
pl_adapt_thr = std::thread([&] { strata::platform::name_this_thread("strata-adapt"); strata::aux_cpus::pin_current_thread(); pl_adapt_ok = adapt(); pl_adapt_done = true; });
@@ -14964,7 +14979,7 @@ int main(int argc, char** argv) {
std::thread adapt_thr; // the adaptive tier beside the commit and the draft (as in generate)
bool adapt_ok = true;
// (--adapt-async 1: the asynchronous tier above instead, ticked before the window)
if (!drive.d.usage.empty() && !ajob && ((rounds + 1) % o.adapt_every) == 0)
if (!drive.d.usage.empty() && !ajob && ((rounds + 1) % o.adapt_iv(rounds)) == 0)
adapt_thr = std::thread([&] { strata::platform::name_this_thread("strata-adapt"); strata::aux_cpus::pin_current_thread(); adapt_ok = adapt(); });
if (!ver.commit(a + 1, err)) {
if (adapt_thr.joinable()) adapt_thr.join();
@@ -16393,7 +16408,7 @@ int main(int argc, char** argv) {
// GPU commits and drafts; it touches only the residency tables, which nothing reads until the next window
std::thread adapt_thr;
bool adapt_ok = true;
if (!drive.d.usage.empty() && ((rounds + 1) % o.adapt_every) == 0)
if (!drive.d.usage.empty() && ((rounds + 1) % o.adapt_iv(rounds)) == 0)
adapt_thr = std::thread([&] { strata::platform::name_this_thread("strata-adapt"); strata::aux_cpus::pin_current_thread(); adapt_ok = adapt(); });
strata::core::progress_at("spec loop: commit", (int64_t) T);
if (!ver.commit(a + 1, err)) {