From 95d7593e4a45219affeb3d15861f5dd3a5ac9aea Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Mon, 14 Aug 2023 21:18:19 +0300 Subject: [PATCH] llama : sync gguf-llama.cpp --- examples/gguf/gguf-llama-simple.cpp | 2 +- gguf-llama.cpp | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/gguf/gguf-llama-simple.cpp b/examples/gguf/gguf-llama-simple.cpp index f6b4a59e0..0679240d3 100644 --- a/examples/gguf/gguf-llama-simple.cpp +++ b/examples/gguf/gguf-llama-simple.cpp @@ -54,7 +54,7 @@ int main(int argc, char ** argv) { const int max_context_size = llama_n_ctx(ctx); const int max_tokens_list_size = max_context_size - 4; - if ((int)tokens_list.size() > max_tokens_list_size) { + if ((int) tokens_list.size() > max_tokens_list_size) { fprintf(stderr, "%s: error: prompt too long (%d tokens, max %d)\n", __func__, (int) tokens_list.size(), max_tokens_list_size); return 1; } diff --git a/gguf-llama.cpp b/gguf-llama.cpp index 1fc9a2972..8275c7357 100644 --- a/gguf-llama.cpp +++ b/gguf-llama.cpp @@ -4555,24 +4555,24 @@ int llama_token_to_str_with_model(const struct llama_model * model, llama_token if (0 <= token && token < llama_n_vocab_from_model(model)) { if (llama_is_normal_token(model->vocab, token)) { std::string result = model->vocab.id_to_token[token].tok; - if (llama_vocab_type(model->vocab) == "spm") { + if(llama_vocab_type(model->vocab) == "spm") { result = llama_unescape_whitespace(result); } if (length < (int) result.length()) { return -result.length(); } - strcpy(str, result.c_str()); + strncpy(str, result.c_str(), result.length()); return result.length(); } else if (llama_is_unknown_token(model->vocab, token)) { if (length < 3) { return -3; } - strcpy(str, "\xe2\x96\x85"); + strncpy(str, "\xe2\x96\x85", 3); return 3; } else if (llama_is_control_token(model->vocab, token)) { ; } else if (llama_is_byte_token(model->vocab, token)) { - if(1 > length) { + if (length < 1) { return -1; } str[0] = llama_byte_to_char(model->vocab, token); @@ -4607,7 +4607,7 @@ int llama_token_to_str_bpe(const struct llama_context * ctx, llama_token token, if (length < (int) result.length()) { return -result.length(); } - strcpy(str, result.c_str()); + strncpy(str, result.c_str(), result.length()); return result.length(); } return 0; @@ -4618,9 +4618,8 @@ std::string llama_token_to_str_bpe(const struct llama_context * ctx, llama_token const int length = llama_token_to_str_bpe(ctx, token, result.data(), result.size()); if (length < 0) { result.resize(-length); - const int check = llama_token_to_str_bpe(ctx, token, (char*)result.data(), result.size()); + const int check = llama_token_to_str_bpe(ctx, token, result.data(), result.size()); GGML_ASSERT(check == -length); - GGML_UNUSED(check); } else { result.resize(length); }