Skip to content

Commit c82d48e

Browse files
authored
llama : fix --reverse-prompt crashing issue (ggml-org#14794)
Signed-off-by: Molly Sophia <mollysophia379@gmail.com>
1 parent b4efd77 commit c82d48e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

tools/main/main.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -785,14 +785,17 @@ int main(int argc, char ** argv) {
785785
}
786786

787787
// check for reverse prompt using special tokens
788-
llama_token last_token = common_sampler_last(smpl);
789-
for (auto token : antiprompt_token) {
790-
if (token == last_token) {
791-
if (params.interactive) {
792-
is_interacting = true;
788+
// avoid calling common_sampler_last() if last_output is empty
789+
if (!last_output.empty()) {
790+
llama_token last_token = common_sampler_last(smpl);
791+
for (auto token : antiprompt_token) {
792+
if (token == last_token) {
793+
if (params.interactive) {
794+
is_interacting = true;
795+
}
796+
is_antiprompt = true;
797+
break;
793798
}
794-
is_antiprompt = true;
795-
break;
796799
}
797800
}
798801

0 commit comments

Comments
 (0)