Merge branch 'f-1402-u' into f-1402

This commit is contained in:
Niko1221 committed 2026-10-07 03:36:42 +02:00
commit 6d69cd5032
4 files changed
+44 -11

No files matched your search

+9 -3
View File
@@ -5730,9 +5730,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 need
if (!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();
@@ -8943,7 +8947,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 cache
if (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;