Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

decode: STRATA_ADAPT_LAG - #463's reproducibility without its stall (#764, ported onto 0.1.40's adaptive tier)

Benjamin Larssond69424c9658e
diff --git a/src/program/generate.cpp b/src/program/generate.cpp
index acb0b39ea..d35979927 100644
--- a/src/program/generate.cpp
+++ b/src/program/generate.cpp
@@ -1179,6 +1179,16 @@ bool adapt_nowait() {
return v;
}
+/// #463 without the stall: a verify window takes the adaptive tier's previous swaps only once they are this many windows
+/// old, and then waits for their copies (which have landed by then). The window that first computes a swapped-in expert on
+/// the GPU depends only on the window count, as with #463's wait, so the answers are as reproducible. Default 1 = #463 and
+/// 0.1.39 (the very next window waits for the copies: ~4.6 ms per window on an RTX 2060 SUPER over PCIe 3.0 x8); lag 2 is
+/// opt-in (STRATA_ADAPT_LAG=2). The batch paths, --pipeline-windows and the peer tier are not lagged. (#764)
+int adapt_lag() {
+ static const int v = [] { const char* e = std::getenv("STRATA_ADAPT_LAG"); return e ? std::max(1, std::atoi(e)) : 1; }();
+ return v;
+}
+
/// --adapt-async: one background job at a time (the asynchronous adaptive tier's copies and memcpys). `post` hands
/// it over, `idle` says whether it has finished; the owner never posts while a job runs.
class JobThread {
@@ -6631,6 +6641,7 @@ int main(int argc, char** argv) {
}
// plan v0.3 P6: swaps in flight - (residency index, slot) admitted when adapt_ev has completed
std::vector<std::pair<int32_t, int32_t>> pending;
+ int pending_age = 0; // the windows the pending swaps have waited (adapt_lag)
std::vector<void*> pin_live; // the swaps' locked arena pages (pin_blob), unlocked once they have landed
cudaEvent_t adapt_ev = nullptr;
cudaEventCreateWithFlags(&adapt_ev, cudaEventDisableTiming);
@@ -6661,6 +6672,7 @@ int main(int argc, char** argv) {
srcp->release((int64_t) i / g.n_expert, (int64_t) i % g.n_expert); // in VRAM now: RAM not needed
}
pending.clear();
+ pending_age = 0;
res_upload();
};
// --pipeline-windows: set while the tier adapts beside windows in flight (see its use in adapt)
@@ -9171,6 +9183,7 @@ int main(int argc, char** argv) {
pl_landed.push_back(i);
}
pending.clear();
+ pending_age = 0;
res_upload();
stage_record(exch_ev);
exch_wait = true;
@@ -9603,7 +9616,8 @@ int main(int argc, char** argv) {
// #463: the previous adapt round's copies land first - with a non-blocking query, whether a swapped-in
// expert ran on the GPU or the CPU (they round differently) depended on the copy's timing
// (STRATA_ADAPT_NOWAIT=1: 0.1.37's non-blocking query, the A/B)
- apply_pending(!adapt_nowait());
+ if (adapt_nowait()) apply_pending(false);
+ else if (pending.empty() || ++pending_age >= adapt_lag()) apply_pending(true);
if (!adapt_tick(false)) { // --adapt-async: the round in flight moves on a step when it can
std::printf("ERR an adaptive refill failed\n");
return 1;
@@ -10430,6 +10444,7 @@ int main(int argc, char** argv) {
}
// plan v0.3 P6: swaps in flight - (residency index, slot) admitted when adapt_ev has completed
std::vector<std::pair<int32_t, int32_t>> pending;
+ int pending_age = 0; // the windows the pending swaps have waited (adapt_lag)
std::vector<void*> pin_live; // the swaps' locked arena pages (pin_blob), unlocked once they have landed
cudaEvent_t adapt_ev = nullptr;
cudaEventCreateWithFlags(&adapt_ev, cudaEventDisableTiming);
@@ -10454,6 +10469,7 @@ int main(int argc, char** argv) {
srcp->release((int64_t) i / g.n_expert, (int64_t) i % g.n_expert); // in VRAM now: RAM not needed
}
pending.clear();
+ pending_age = 0;
if (d_res != nullptr)
res_put(d_res);
};
@@ -10628,7 +10644,8 @@ int main(int argc, char** argv) {
// #463: the previous adapt round's copies land first - with a non-blocking query, whether a swapped-in
// expert ran on the GPU or the CPU (they round differently) depended on the copy's timing
// (STRATA_ADAPT_NOWAIT=1: 0.1.37's non-blocking query, the A/B)
- apply_pending(!adapt_nowait());
+ if (adapt_nowait()) apply_pending(false);
+ else if (pending.empty() || ++pending_age >= adapt_lag()) apply_pending(true);
if (!ver.run(T, window.data(), p, &drive_pool_multi, &drive, outv.data(), err)) {
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
return 1;