Skip to content
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

Replace EOS with newline to prevent context/memory being flushed by EOS in interactive mode #333

Merged
merged 29 commits into from
Mar 23, 2023
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4fe9734
Improve interactive mode's coherence after EOS
rabidcopy Mar 20, 2023
330b86e
Make newline token a constant
rabidcopy Mar 20, 2023
3eca29e
dynamically determine newline token
rabidcopy Mar 20, 2023
94edeaf
relocate previous newline token const
rabidcopy Mar 20, 2023
ac6a9d9
cleanup whitespace
rabidcopy Mar 20, 2023
4660738
print a new line on end of text in interactive
rabidcopy Mar 20, 2023
d9284a5
only print manual newline with reverse prompt
rabidcopy Mar 20, 2023
2479c78
alternate approach to replace end of text tokens
rabidcopy Mar 20, 2023
8009a8d
Inject the reverse prompt again after eos in interactive mode
slaren Mar 21, 2023
1f4abb8
Merge pull request #2 from slaren/interactive-eos-fix
rabidcopy Mar 21, 2023
3c211c6
tokenize reverse prompt when needed
rabidcopy Mar 21, 2023
e33df8e
tokenize and inject only first reverse prompt
rabidcopy Mar 21, 2023
52f46ef
tokenize first reverse prompt once
rabidcopy Mar 21, 2023
6bcbe50
Merge branch 'master' into interactive-eos-fix
rabidcopy Mar 21, 2023
6fb0db3
Merge branch 'master' into interactive-eos-fix
rabidcopy Mar 22, 2023
1752bc9
add newline token
rabidcopy Mar 22, 2023
23bb78f
add newline token
rabidcopy Mar 22, 2023
da0837f
tokenize/inject reverse prompt for refactor
rabidcopy Mar 22, 2023
c4efdb2
tokenize nothing for antiprompt if no reverse
rabidcopy Mar 22, 2023
879da33
Update main.cpp
rabidcopy Mar 22, 2023
e590787
Update main.cpp
rabidcopy Mar 22, 2023
4e4cfdf
tokenize and inject reverse prompt as needed
rabidcopy Mar 22, 2023
6a4cfc4
not needed
rabidcopy Mar 22, 2023
10206d0
remove newline token
rabidcopy Mar 22, 2023
8f83ce8
remove newline token
rabidcopy Mar 22, 2023
7864eef
tokenize newline token
rabidcopy Mar 23, 2023
666c5a0
Merge branch 'master' into interactive-eos-fix
rabidcopy Mar 23, 2023
88df270
add space to comment
rabidcopy Mar 23, 2023
55b899b
Update main.cpp
rabidcopy Mar 23, 2023
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
21 changes: 15 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ int main(int argc, char ** argv) {
params.interactive = true;
}

// determine newline token
auto llama_token_newline = ::llama_tokenize(ctx, "\n", false);

fprintf(stderr, "\n");
fprintf(stderr, "%s: prompt: '%s'\n", __func__, params.prompt.c_str());
fprintf(stderr, "%s: number of tokens in prompt = %zu\n", __func__, embd_inp.size());
Expand Down Expand Up @@ -359,6 +362,16 @@ int main(int argc, char ** argv) {
last_n_tokens.push_back(id);
}

// replace end of text token with newline token when in interactive mode
if (id == llama_token_eos() && params.interactive) {
id = llama_token_newline.front();
if (params.antiprompt.size() != 0) {
// tokenize and inject first reverse prompt
const auto first_antiprompt = ::llama_tokenize(ctx, params.antiprompt.front(), false);
embd_inp.insert(embd_inp.end(), first_antiprompt.begin(), first_antiprompt.end());
}
}

// add it to the context
embd.push_back(id);

Expand Down Expand Up @@ -451,12 +464,8 @@ int main(int argc, char ** argv) {

// end of text token
if (embd.back() == llama_token_eos()) {
if (params.interactive) {
is_interacting = true;
} else {
fprintf(stderr, " [end of text]\n");
break;
}
fprintf(stderr, " [end of text]\n");
break;
}

// In interactive mode, respect the maximum number of tokens and drop back to user input when reached.
Expand Down