From e12f3fb88414199226c12b7a3bb972a4a8055c9c Mon Sep 17 00:00:00 2001 From: Tom 7 <499244+tom7@users.noreply.github.com> Date: Fri, 19 May 2023 12:50:07 -0400 Subject: [PATCH 1/4] Fix bug in main.cpp where penalize_nl=false has no effect. It modifies the underlying logits array, but at this point we are already working on the candidates copy. --- examples/main/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/main/main.cpp b/examples/main/main.cpp index 18673ed2e00f2..3d18a52394265 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -428,7 +428,12 @@ int main(int argc, char ** argv) { last_n_tokens.data() + last_n_tokens.size() - last_n_repeat, last_n_repeat, alpha_frequency, alpha_presence); if (!penalize_nl) { - logits[llama_token_nl()] = nl_logit; + for (size_t idx = 0; idx < candidates_p.size; idx++) { + if (candidates_p.data[idx].id == llama_token_nl()) { + candidates_p.data[idx].logit = nl_logit; + break; + } + } } if (temp <= 0) { From 311bd6d2940d564f4c919b3a49b6af8a16d9c8de Mon Sep 17 00:00:00 2001 From: Tom 7 <499244+tom7@users.noreply.github.com> Date: Fri, 19 May 2023 12:52:16 -0400 Subject: [PATCH 2/4] Suppress redefinition warning for NOMINMAX on mingw. In my installation, this macro is already defined by /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/x86_64-w64-mingw32/bits/os_defines.h:45. --- examples/main/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/main/main.cpp b/examples/main/main.cpp index 3d18a52394265..9b49eaeb46a3d 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -23,7 +23,9 @@ #include #elif defined (_WIN32) #define WIN32_LEAN_AND_MEAN +#ifndef NOMINMAX #define NOMINMAX +#endif #include #include #endif From f5d4b48297bc015a09bbe077fe46c510425d5d7c Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sat, 26 Aug 2023 21:02:41 +0300 Subject: [PATCH 3/4] main : fix indentation --- examples/main/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/main/main.cpp b/examples/main/main.cpp index 9b49eaeb46a3d..b78a88b06686b 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -430,12 +430,12 @@ int main(int argc, char ** argv) { last_n_tokens.data() + last_n_tokens.size() - last_n_repeat, last_n_repeat, alpha_frequency, alpha_presence); if (!penalize_nl) { - for (size_t idx = 0; idx < candidates_p.size; idx++) { - if (candidates_p.data[idx].id == llama_token_nl()) { - candidates_p.data[idx].logit = nl_logit; - break; + for (size_t idx = 0; idx < candidates_p.size; idx++) { + if (candidates_p.data[idx].id == llama_token_nl()) { + candidates_p.data[idx].logit = nl_logit; + break; + } } - } } if (temp <= 0) { From 1bf050c2a89506b06b42f3ebe836fb0322fe6234 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sat, 26 Aug 2023 21:06:41 +0300 Subject: [PATCH 4/4] main : pass ctx to llama_token_nl() --- examples/main/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/main/main.cpp b/examples/main/main.cpp index 656db4547ea19..11d7a7e4f4fe1 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -605,7 +605,7 @@ int main(int argc, char ** argv) { last_n_repeat, alpha_frequency, alpha_presence); if (!penalize_nl) { for (size_t idx = 0; idx < candidates_p.size; idx++) { - if (candidates_p.data[idx].id == llama_token_nl()) { + if (candidates_p.data[idx].id == llama_token_nl(ctx)) { candidates_p.data[idx].logit = nl_logit; break; }