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++
--kv-grow: STRATA_KV_GROW_HOLD=1 keeps the K/V as long as a parked conversation (#1128)
Niko122156ae98dde9fb
diff --git a/include/strata/core/conversation_cache.hpp b/include/strata/core/conversation_cache.hppindex c28ae01f6..86e04c6b1 100644--- a/include/strata/core/conversation_cache.hpp+++ b/include/strata/core/conversation_cache.hpp@@ -191,6 +191,12 @@ public:size_t bytes() const { return bytes_ + reuse_.bytes(); }size_t size() const { return entries_.size(); }size_t evictions() const { return evictions_; }+ // the longest parked conversation, in tokens (--kv-grow keeps the K/V that long while it could be restored)+ int64_t longest_tokens() const {+ int64_t n = 0;+ for (const auto& e : entries_) n = std::max<int64_t>(n, (int64_t) e.live.ids.size());+ return n;+ }// Retain only the restored K/V buffers, not duplicate running checkpoints.// This optimization never evicts a parked conversation to make itself fit.diff --git a/src/program/generate.cpp b/src/program/generate.cppindex 04b309397..24114a617 100644--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@ -5433,9 +5433,13 @@ int main(int argc, char** argv) {};// A request that needs far fewer cells than the K/V holds gives the rest back: the slots refill with the// profile's hottest experts the GPU does not hold. Run on a quiet device (as kvg_ensure's `quiesce`).- auto kvg_trim = [&](int64_t cells) -> bool {+ auto kvg_trim = [&](int64_t cells, int64_t hold) -> bool { // `hold`: the cells a parked conversation could needif (!kvg.on) return true;- const int64_t target = std::max<int64_t>(kvg.step, (cells + kvg.step - 1) / kvg.step * kvg.step);+ // #1128: a parked conversation comes back through kvg_ensure's grow, so a K/V that fell to a short request's+ // size is grown again (its experts shuffled again) after every short request in between: the K/V keeps the+ // longest parked conversation's cells while it is parked+ const int64_t want = std::max<int64_t>(cells, hold);+ const int64_t target = std::max<int64_t>(kvg.step, (want + kvg.step - 1) / kvg.step * kvg.step);if (kvg.cells < target + 2 * kvg.step || kvg.lo >= kvg.top) return true;strata::core::qsa_kv_elastic_shrink(target, [&](strata::core::VmmChunk h) { kvg.spare.push_back(h); });kvg.cells = strata::core::qsa_kv_elastic_cells();@@ -8637,7 +8641,9 @@ int main(int argc, char** argv) {// so cells past this prompt's are no longer anyone's - far more than it needs go back to the cacheif (kvg.on) {kv_quiesce();- if (!kvg_trim(n + 256)) {+ // STRATA_KV_GROW_HOLD=1 (opt-in): keep the K/V as long as the longest parked conversation; default: trim to this request alone, as 0.1.40+ static const bool hold_on = [] { const char* v = std::getenv("STRATA_KV_GROW_HOLD"); return v != nullptr && std::atoi(v) != 0; }();+ if (!kvg_trim(n + 256, hold_on ? conversations.longest_tokens() + 256 : 0)) {std::printf("ERR the K/V could not give its VRAM back to the expert cache\n");std::fflush(stdout);return 1;