Reuse long chat history when the last user message is edited
This commit is contained in:
1 parent
9c139846d5
commit
b5de344b73
5 files changed
+138
-3
No files matched your search
@@ -56,6 +56,7 @@
|
||||
#include "strata/core/native_dense.hpp"
|
||||
#include "strata/program/logits_selection.hpp"
|
||||
#include "strata/program/conv_cache.hpp"
|
||||
#include "strata/program/message_boundary.hpp"
|
||||
#include "strata/spec/draft_policy.hpp"
|
||||
#include "strata/spec/draft_source.hpp"
|
||||
#include "strata/spec/suffix_drafter.hpp"
|
||||
@@ -8143,8 +8144,15 @@ int main(int argc, char** argv) {
|
||||
if (i >= o.prompt_cache_root) root_at = i;
|
||||
break;
|
||||
}
|
||||
static const bool message_checkpoint = [] {
|
||||
const char* e = std::getenv("STRATA_CACHE_MESSAGE_BOUNDARY");
|
||||
return e != nullptr && std::atoi(e) != 0;
|
||||
}();
|
||||
// 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;
|
||||
int64_t at = read_from;
|
||||
for (const int64_t to : {reread_to, root_at, turn_at, n - 1}) {
|
||||
for (const int64_t to : {reread_to, root_at, message_at, turn_at, n - 1}) {
|
||||
if (to <= at) continue;
|
||||
err.clear();
|
||||
const bool win = windows_ok(at, to);
|
||||
@@ -8181,10 +8189,15 @@ int main(int argc, char** argv) {
|
||||
break;
|
||||
}
|
||||
at = to;
|
||||
if ((to == turn_at || to == root_at) && !checkpoint_at(to)) {
|
||||
std::printf("ERR saving a conversation checkpoint failed%s\n", ckpt_why.c_str());
|
||||
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
|
||||
std::printf("ERR saving a conversation checkpoint failed%s
|
||||
", ckpt_why.c_str());
|
||||
return 1;
|
||||
}
|
||||
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));
|
||||
}
|
||||
if (!refill(err)) {
|
||||
std::printf("ERR refilling a lent slot failed: %s\n", err.c_str());
|
||||
|
||||
Reference in new issue
Block a user