Merge branch 'f-1402-r' into f-1402

This commit is contained in:
Niko1221 committed 2026-10-07 04:05:58 +02:00
commit d19c07650b
13 files changed
+613 -14

No files matched your search

+58 -5
View File
@@ -7010,8 +7010,16 @@ int main(int argc, char** argv) {
// the tail checkpoint serves only a branch of the last request: it leaves before a periodic one
std::unique_ptr<bool[]> tail_flags(new bool[is_tail.size()]);
for (size_t i = 0; i < is_tail.size(); ++i) tail_flags[i] = is_tail[i] != 0;
// the pin=N prefix is never the victim (flags only when one is pinned: nothing changes without)
std::unique_ptr<bool[]> pin_flags;
for (const ConvCheckpoint& k : checks)
if (k.pinned) {
pin_flags.reset(new bool[checks.size()]);
for (size_t i = 0; i < checks.size(); ++i) pin_flags[i] = checks[i].pinned;
break;
}
const size_t victim = strata::program::conv_cache::eviction_victim(
stamps.data(), stamps.size(), o.prompt_cache, tail_flags.get());
stamps.data(), stamps.size(), o.prompt_cache, tail_flags.get(), pin_flags.get());
checks.erase(checks.begin() + (std::ptrdiff_t) victim);
}
return true;
@@ -8605,6 +8613,11 @@ int main(int argc, char** argv) {
// parked after it. It still resumes from a checkpoint it matches, and still saves the system-prompt root
// when that reaches --prompt-cache-root. Absent = checkpointed as before.
int req_ckpt = 1;
// pin=N: the first N prompt tokens are a shared read-only prefix (a long document that many short queries
// follow). The prompt is read in two parts at N, the checkpoint there is PINNED (retention never evicts it,
// a parked conversation holding it stays parked) and a later request that resumes from it does not park the
// branch it leaves: N queries cost one prefix, not N. Absent = as before.
int64_t req_pin = 0;
// tuning keys (setup's calibration measures settings without restarting the engine): the PCIe share of
// the missed experts and the draft-probability floor, for this request only
double req_pcie_frac = o.pcie_frac, req_spec_min_p = o.spec_min_p;
@@ -8622,6 +8635,7 @@ int main(int argc, char** argv) {
const float fv = std::strtof(tok.c_str() + eq + 1, nullptr);
if (key == "cvec") req_cvec = std::atoi(tok.c_str() + eq + 1);
else if (key == "ckpt") req_ckpt = std::atoi(tok.c_str() + eq + 1) != 0;
else if (key == "pin") req_pin = std::max<long long>(0, std::atoll(tok.c_str() + eq + 1));
else if (key == "temperature") req_temperature = fv;
else if (key == "top_p") req_top_p = fv;
else if (key == "top_k") req_top_k = std::atoi(tok.c_str() + eq + 1);
@@ -8853,7 +8867,16 @@ int main(int argc, char** argv) {
}
// Preserve the outgoing branch before any checkpoint rewind, reset,
// or incoming restore overwrites the positional state it requires.
if ((!from_live || incoming || slot_source >= 0) && !park_current(incoming ? incoming->bytes() : 0)) {
// pin=N: this request resumes exactly at the pinned shared prefix of the conversation the session holds
// (a sibling query of the last one). What the last query added past it is its private suffix - a few
// dozen tokens, cheaper to read than the prefix's whole K/V is to copy to the host - so it is not parked:
// N queries keep one prefix. A request without pin=, or one that resumes anywhere else, parks as before.
bool pin_sibling = false;
if (req_pin > 0 && req_ckpt && o.prompt_cache >= 3 && !from_live && !incoming && slot_source < 0 &&
resume == req_pin && live_ok)
for (const ConvCheckpoint& c : checks)
if ((int64_t) c.ids.size() == resume && c.pinned) pin_sibling = true;
if ((!from_live || incoming || slot_source >= 0) && !pin_sibling && !park_current(incoming ? incoming->bytes() : 0)) {
std::printf("ERR %s\n", err.c_str());
return 1;
}
@@ -9509,8 +9532,36 @@ int main(int argc, char** argv) {
// Only add a snapshot; the existing token and image checks still decide reuse.
const int64_t message_at = message_checkpoint && !multi_gpu && o.prompt_cache > 0
? strata::program::message_checkpoint_boundary(ids, resume, turn_at, o.turn_token) : -1;
// pin=N (opt-in): one more place the prompt is read to and checkpointed. One pinned prefix at a time: a
// new pin replaces the old; it needs room for the root, the pin and a rotating checkpoint
int64_t pin_at = -1;
auto pin_checkpoint = [&](int64_t L) {
bool found = false;
for (ConvCheckpoint& c : checks) {
c.pinned = (int64_t) c.ids.size() == L;
found = found || c.pinned;
}
return found;
};
if (req_pin > 0) {
if (o.prompt_cache < 3 || !req_ckpt)
std::fprintf(stderr, "strata serve: pin=%lld ignored: %s\n", (long long) req_pin,
req_ckpt ? "it needs --prompt-cache 3 or more" : "ckpt=0 keeps no checkpoint");
else if (req_pin >= n - 1)
std::fprintf(stderr, "strata serve: pin=%lld ignored: the prefix must be shorter than the prompt "
"(%lld tokens)\n", (long long) req_pin, (long long) n);
else if (req_pin > read_from) pin_at = req_pin;
else if (!pin_checkpoint(req_pin))
std::fprintf(stderr, "strata serve: pin=%lld: the cache has no checkpoint there to pin (it resumed from "
"%lld)\n", (long long) req_pin, (long long) read_from);
}
std::vector<int64_t> cuts = {reread_to, root_at, message_at, turn_at, n - 1};
if (pin_at >= 0) {
cuts.push_back(pin_at);
std::sort(cuts.begin(), cuts.end()); // the skipped -1s first, n - 1 still last
}
int64_t at = read_from;
for (const int64_t to : {reread_to, root_at, message_at, turn_at, n - 1}) {
for (const int64_t to : cuts) {
if (to <= at) continue;
err.clear();
const bool win = windows_ok(at, to);
@@ -9547,11 +9598,13 @@ int main(int argc, char** argv) {
break;
}
at = to;
if ((to == turn_at || to == root_at || to == message_at) &&
!checkpoint_at(to, nullptr, to == message_at && to != turn_at && to != root_at)) { // the tail kind leaves first
if ((to == turn_at || to == root_at || to == message_at || to == pin_at) &&
!checkpoint_at(to, nullptr, to == message_at && to != turn_at && to != root_at && to != pin_at)) { // the tail kind leaves first
std::printf("ERR saving a conversation checkpoint failed%s\n", ckpt_why.c_str());
return 1;
}
if (to == pin_at && !pin_checkpoint(pin_at))
std::fprintf(stderr, "strata serve: pin=%lld: its checkpoint was not kept\n", (long long) pin_at);
if (trace && to == message_at)
std::fprintf(stderr, "strata serve: message boundary checkpoint: %lld tokens, %lld tail\n",
(long long) message_at, (long long) (turn_at - message_at));