From f67f4651fac0b2f377dc53fe853b1dafa96f9aa9 Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Tue, 28 May 2024 13:27:23 -0400 Subject: [PATCH] llama : work around load crash caused by out-of-vocab token IDs Upstream issue: ggerganov/llama.cpp#2378 --- llama.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/llama.cpp b/llama.cpp index ec67710732123..32653d665d60d 100644 --- a/llama.cpp +++ b/llama.cpp @@ -4703,10 +4703,18 @@ static void llm_load_print_meta(llama_model_loader & ml, llama_model & model) { if (vocab.special_mask_id != -1) { LLAMA_LOG_INFO( "%s: MASK token = %d '%s'\n", __func__, vocab.special_mask_id, vocab.id_to_token[vocab.special_mask_id].text.c_str() ); } if (vocab.linefeed_id != -1) { LLAMA_LOG_INFO( "%s: LF token = %d '%s'\n", __func__, vocab.linefeed_id, vocab.id_to_token[vocab.linefeed_id].text.c_str() ); } - if (vocab.special_prefix_id != -1) { LLAMA_LOG_INFO( "%s: PRE token = %d '%s'\n", __func__, vocab.special_prefix_id, vocab.id_to_token[vocab.special_prefix_id].text.c_str() ); } - if (vocab.special_suffix_id != -1) { LLAMA_LOG_INFO( "%s: SUF token = %d '%s'\n", __func__, vocab.special_suffix_id, vocab.id_to_token[vocab.special_suffix_id].text.c_str() ); } - if (vocab.special_middle_id != -1) { LLAMA_LOG_INFO( "%s: MID token = %d '%s'\n", __func__, vocab.special_middle_id, vocab.id_to_token[vocab.special_middle_id].text.c_str() ); } - if (vocab.special_eot_id != -1) { LLAMA_LOG_INFO( "%s: EOT token = %d '%s'\n", __func__, vocab.special_eot_id, vocab.id_to_token[vocab.special_eot_id].text.c_str() ); } + if (vocab.special_prefix_id != -1 && vocab.special_prefix_id < ptrdiff_t(vocab.id_to_token.size())) { + LLAMA_LOG_INFO( "%s: PRE token = %d '%s'\n", __func__, vocab.special_prefix_id, vocab.id_to_token[vocab.special_prefix_id].text.c_str() ); + } + if (vocab.special_suffix_id != -1 && vocab.special_suffix_id < ptrdiff_t(vocab.id_to_token.size())) { + LLAMA_LOG_INFO( "%s: SUF token = %d '%s'\n", __func__, vocab.special_suffix_id, vocab.id_to_token[vocab.special_suffix_id].text.c_str() ); + } + if (vocab.special_middle_id != -1 && vocab.special_middle_id < ptrdiff_t(vocab.id_to_token.size())) { + LLAMA_LOG_INFO( "%s: MID token = %d '%s'\n", __func__, vocab.special_middle_id, vocab.id_to_token[vocab.special_middle_id].text.c_str() ); + } + if (vocab.special_eot_id != -1 && vocab.special_eot_id < ptrdiff_t(vocab.id_to_token.size())) { + LLAMA_LOG_INFO( "%s: EOT token = %d '%s'\n", __func__, vocab.special_eot_id, vocab.id_to_token[vocab.special_eot_id ].text.c_str() ); + } } // Returns false if cancelled by progress_callback