mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-04 15:28:40 +00:00
serve + engine: opt-in "effort_position": "end" keeps the cached conversation when the effort changes (#458)
The effort's instruction is the first thing the template renders, so a request that only changes reasoning_effort (or turns thinking off) read the whole prompt again. With "effort_position": "end" in the run config the server renders every prompt's start as the default effort's and puts a low/medium effort in a short system turn right before the answer (thinking off: just the template's empty thinking block); the rendering is template-agnostic (history + turn + the generation prompt). Engine: --tail-role-token ID (default -1, off) moves the turn checkpoint in front of such a trailing turn, so it holds the conversation and not the effort text; INFO reports tail_role_token. The server passes the id of "system" only when the engine binary knows the flag, and says so when it does not. Without the key nothing changes: the same prompt ids, no flag.
This commit is contained in:
1 parent
c16f31f850
commit
9eceb375ab
4 files changed
+195
-4
No files matched your search
@@ -413,6 +413,11 @@ struct Options {
|
||||
/// --serve: the token that opens a chat turn (<|im_start|>). The last one in a prompt is where the chat's
|
||||
/// history ends and the new assistant turn begins, which is the checkpoint the next request can reuse.
|
||||
int64_t turn_token = 248045;
|
||||
/// --serve (#458, opt-in): the role token of a short turn the server puts right before the new assistant turn
|
||||
/// (the "system" of a trailing reasoning-effort turn). When the turn before the last <|im_start|> opens with it,
|
||||
/// the checkpoint goes in front of that turn instead, so it holds the conversation and not the effort text.
|
||||
/// -1 = off (the checkpoint at the last <|im_start|>, as before).
|
||||
int64_t tail_role_token = -1;
|
||||
/// --serve: a text part of the prompt of at most N tokens (a chat message, the assistant header, a short tool
|
||||
/// result) goes through the verify windows, S tokens at a time, instead of the batched prompt path (0 = always
|
||||
/// the batched path)
|
||||
@@ -517,6 +522,8 @@ void usage() {
|
||||
" --conversation-cache-min-free-mib N --serve: physical RAM floor when parking (default 2560)\n"
|
||||
" --prompt-cache-every N --serve: also checkpoint every N fresh prompt tokens (default 16384, 0 = off)\n"
|
||||
" --turn-token ID --serve: the token that opens a chat turn (default 248045, <|im_start|>)\n"
|
||||
" --tail-role-token ID --serve: a turn of this role right before the last turn is left out of\n"
|
||||
" the conversation checkpoint (a trailing effort turn; default -1 = off)\n"
|
||||
" --short-read N --serve: read at most N fresh text tokens through the decode windows instead\n"
|
||||
" of the batched prompt path (default 64, 0 = off)\n"
|
||||
" --suffix-draft N prompt lookup: draft from an earlier repeat of the last N+ tokens of context\n"
|
||||
@@ -1248,6 +1255,7 @@ int main(int argc, char** argv) {
|
||||
else if (a == "--prompt-cache-every") o.prompt_cache_every = std::max(0LL, std::atoll(next("--prompt-cache-every")));
|
||||
else if (a == "--prompt-cache-root") o.prompt_cache_root = std::max(0LL, std::atoll(next("--prompt-cache-root")));
|
||||
else if (a == "--turn-token") o.turn_token = std::atoll(next("--turn-token"));
|
||||
else if (a == "--tail-role-token") o.tail_role_token = std::atoll(next("--tail-role-token"));
|
||||
else if (a == "--short-read") o.short_read = std::max(0LL, std::atoll(next("--short-read")));
|
||||
else if (a == "--suffix-draft") o.suffix_draft = std::max(0, std::atoi(next("--suffix-draft")));
|
||||
else if (a == "--mtp-max-t") o.mtp_max_t = std::max(0, std::atoi(next("--mtp-max-t")));
|
||||
@@ -4986,7 +4994,7 @@ int main(int argc, char** argv) {
|
||||
"expert_slots_primary=%lld expert_cache_primary_mib=%lld spec=%d "
|
||||
"mtp_max=%d lookup=%d vram_free_mib=%lld cvec=%s arena_mib=%lld pool_workers=%d pcie_frac=%.2f "
|
||||
"spec_min_p=%.2f conversation_cache_mib=%lld conversation_cache_slots=%d "
|
||||
"conversation_cache_min_free_mib=%lld engine=" STRATA_VERSION "\n",
|
||||
"conversation_cache_min_free_mib=%lld tail_role_token=%lld engine=" STRATA_VERSION "\n",
|
||||
(long long) o.max_context, o.kv.c_str(),
|
||||
(long long) (g.n_qsa_layers() > 0 && ss.qsa_states[ss.qsa_primary()].kv_mode == 1
|
||||
? ss.qsa_states[ss.qsa_primary()].n_slots * 4 : 0),
|
||||
@@ -4997,7 +5005,7 @@ int main(int argc, char** argv) {
|
||||
(long long) ((o.mmap_experts ? src.resident_bytes() : strata::kernels::cpu::expert_layout().total) >> 20),
|
||||
pool.workers(), o.pcie_frac,
|
||||
o.spec_min_p, (long long) o.conversation_cache_mib, o.conversation_cache_slots,
|
||||
(long long) o.conversation_cache_min_free_mib);
|
||||
(long long) o.conversation_cache_min_free_mib, (long long) o.tail_role_token);
|
||||
}
|
||||
// issue #29: a request whose heartbeat (tokens, prompt chunks, verify windows) stops for this long is stuck on
|
||||
// a flag nobody will raise - end the engine with where it was, so the server starts it again instead of the
|
||||
@@ -5597,6 +5605,15 @@ int main(int argc, char** argv) {
|
||||
if (o.prompt_cache > 0 && o.turn_token >= 0)
|
||||
for (int64_t i = n - 1; i > resume; --i)
|
||||
if (ids[(size_t) i] == o.turn_token) { turn_at = i; break; }
|
||||
// #458 (opt-in): a short turn of --tail-role-token's role right before the new assistant turn (the
|
||||
// server's trailing reasoning-effort turn) stays out of the checkpoint, so the next request - another
|
||||
// effort, or the next turn of the chat - finds the conversation without it
|
||||
if (turn_at > 0 && o.tail_role_token >= 0)
|
||||
for (int64_t i = turn_at - 1; i > resume; --i)
|
||||
if (ids[(size_t) i] == o.turn_token) {
|
||||
if (ids[(size_t) i + 1] == o.tail_role_token) turn_at = i;
|
||||
break;
|
||||
}
|
||||
// A prompt read from token 0 also stops at its FIRST turn boundary: the end of the system prompt (with
|
||||
// the tools), which every new chat of the same client shares. That checkpoint becomes the chain's root,
|
||||
// which the retention policy pins (conv_cache.hpp), so the next new chat reads only what comes after it.
|
||||
|
||||
Reference in new issue
Block a user