From 0b7211387eccc6e93f2ea5e66c2dc02ae155ab67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Szymczyk?= Date: Sun, 4 Aug 2024 20:47:47 +0200 Subject: [PATCH] llama : Use token_to_id map find() method instead of iterating over all tokens. --- src/llama.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/llama.cpp b/src/llama.cpp index 132a6ea33..d5abe3f58 100644 --- a/src/llama.cpp +++ b/src/llama.cpp @@ -5647,11 +5647,9 @@ static void llm_load_vocab( // TODO: convert scripts should provide this token through the KV metadata LLAMA_KV_TOKENIZER_EOM_ID // for now, we apply this workaround to find the EOM token based on its text if (vocab.special_eom_id == -1) { - for (const auto & t : vocab.token_to_id) { - if (t.first == "<|eom_id|>") { - vocab.special_eom_id = t.second; - break; - } + const auto & t = vocab.token_to_id.find("<|eom_id|>"); + if (t != vocab.token_to_id.end()) { + vocab.special_eom_id = t->second; } }