Skip to content

Fix prompt cache saving and chat-persistent rollover #1678

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jun 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions examples/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ int main(int argc, char ** argv) {
}
}

// if we will use the cache for the full prompt without reaching the end of the cache, force
// reevaluation of the last token token to recalculate the cached logits
if (!embd_inp.empty() && n_matching_session_tokens == embd_inp.size() &&
session_tokens.size() > embd_inp.size()) {
session_tokens.resize(embd_inp.size() - 1);
}

// number of tokens to keep when resetting context
if (params.n_keep < 0 || params.n_keep > (int) embd_inp.size() || params.instruct) {
params.n_keep = (int)embd_inp.size();
Expand Down Expand Up @@ -360,12 +367,6 @@ int main(int argc, char ** argv) {
}
}
if (i > 0) {
// check if we've used up all the prompt but not all cached tokens
if (embd.size() == i && n_session_consumed < (int) session_tokens.size()) {
// force revaluation of the last token to recalculate logits
i--;
n_past--;
}
embd.erase(embd.begin(), embd.begin() + i);
}
}
Expand Down