Skip to content

Compute remaining tokens along the way and exit if over #18

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 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
9 changes: 6 additions & 3 deletions chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,8 @@ int main(int argc, char ** argv) {
" - If you want to submit another line, end your input in '\\'.\n");
}

int remaining_tokens = params.n_predict;
// we may want to slide the input window along with the context, but for now we restrict to the context length
int remaining_tokens = model.hparams.n_ctx - embd_inp.size();
int input_consumed = 0;
bool input_noecho = true;

Expand All @@ -935,7 +936,7 @@ int main(int argc, char ** argv) {



while (true) {
while (remaining_tokens > 0) {
// predict
if (embd.size() > 0) {
const int64_t t_start_us = ggml_time_us();
Expand Down Expand Up @@ -980,7 +981,7 @@ int main(int argc, char ** argv) {
input_noecho = false;

// decrement remaining sampling budget
// --remaining_tokens;
--remaining_tokens;
} else {
// some user input remains from prompt or interaction, forward it to processing
while (embd_inp.size() > input_consumed) {
Expand Down Expand Up @@ -1054,6 +1055,8 @@ int main(int argc, char ** argv) {
embd_inp.insert(embd_inp.end(), line_inp.begin(), line_inp.end());
embd_inp.insert(embd_inp.end(), response_inp.begin(), response_inp.end());

remaining_tokens -= prompt_inp.size() + line_inp.size() + response_inp.size();

input_noecho = true; // do not echo this again
}

Expand Down