]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
llama : fix `--reverse-prompt` crashing issue (#14794)
authorMolly Sophia <redacted>
Mon, 21 Jul 2025 09:38:36 +0000 (17:38 +0800)
committerGitHub <redacted>
Mon, 21 Jul 2025 09:38:36 +0000 (17:38 +0800)
Signed-off-by: Molly Sophia <redacted>
tools/main/main.cpp

index 516bf09652484aadcbc8dbbad87d96daaa5cf313..eb36c6884059cdaec00b5225b54756f2485258c6 100644 (file)
@@ -785,14 +785,17 @@ int main(int argc, char ** argv) {
                 }
 
                 // check for reverse prompt using special tokens
-                llama_token last_token = common_sampler_last(smpl);
-                for (auto token : antiprompt_token) {
-                    if (token == last_token) {
-                        if (params.interactive) {
-                            is_interacting = true;
+                // avoid calling common_sampler_last() if last_output is empty
+                if (!last_output.empty()) {
+                    llama_token last_token = common_sampler_last(smpl);
+                    for (auto token : antiprompt_token) {
+                        if (token == last_token) {
+                            if (params.interactive) {
+                                is_interacting = true;
+                            }
+                            is_antiprompt = true;
+                            break;
                         }
-                        is_antiprompt = true;
-                        break;
                     }
                 }