diff options
author | Kawrakow <iwankawrakow@gmail.com> | 2025-06-26 08:48:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-26 08:48:52 +0200 |
commit | 8e5106b20f694c84811b073b3a4f86ca9d871441 (patch) | |
tree | 6ad8aa062eb29a993ba1a0efcccbd1e240bc86bc | |
parent | b5f2f0010624f9d2fc64f084113f7d38eb851a52 (diff) |
Add Falcon-Edge support (#555)
Co-authored-by: Iwan Kawrakow <iwan.kawrakow@gmail.com>
-rw-r--r-- | include/llama.h | 2 | ||||
-rw-r--r-- | src/llama-vocab.cpp | 14 | ||||
-rw-r--r-- | src/llama.cpp | 20 |
3 files changed, 34 insertions, 2 deletions
diff --git a/include/llama.h b/include/llama.h index bf26a55f..aa0f3980 100644 --- a/include/llama.h +++ b/include/llama.h @@ -108,6 +108,8 @@ extern "C" { LLAMA_VOCAB_PRE_TYPE_TRILLION = 31, LLAMA_VOCAB_PRE_TYPE_BAILINGMOE = 32, LLAMA_VOCAB_PRE_TYPE_LLAMA4 = 33, + LLAMA_VOCAB_PRE_TYPE_FALCON_3 = 34, + LLAMA_VOCAB_PRE_TYPE_FALCON_E = 35, }; // note: these values should be synchronized with ggml_rope diff --git a/src/llama-vocab.cpp b/src/llama-vocab.cpp index abf48824..65ca5e38 100644 --- a/src/llama-vocab.cpp +++ b/src/llama-vocab.cpp @@ -393,6 +393,20 @@ struct llm_tokenizer_bpe { "[0-9][0-9][0-9]", }; break; + case LLAMA_VOCAB_PRE_TYPE_FALCON_3: + regex_exprs = { + "[\\p{P}\\$\\+<=>\\^~\\|`]+", + "'s|'t|'re|'ve|'m|'ll|'d| ?\\p{L}+| ?\\p{N}+| ?[^\\s\\p{L}\\p{N}]+|\\s+(?!\\S)", + "[0-9]", + }; + break; + case LLAMA_VOCAB_PRE_TYPE_FALCON_E: + regex_exprs = { + "[\\p{P}\\$\\+<=>\\^~\\|`]+", + "'s|'t|'re|'ve|'m|'ll|'d| ?\\p{L}+| ?\\p{N}+| ?[^\\s\\p{L}\\p{N}]+|\\s+(?!\\S)", + "[0-9]", + }; + break; case LLAMA_VOCAB_PRE_TYPE_STARCODER: case LLAMA_VOCAB_PRE_TYPE_REFACT: case LLAMA_VOCAB_PRE_TYPE_COMMAND_R: diff --git a/src/llama.cpp b/src/llama.cpp index a70d2582..7c10cebd 100644 --- a/src/llama.cpp +++ b/src/llama.cpp @@ -1615,6 +1615,7 @@ enum llm_chat_template { LLM_CHAT_TEMPLATE_MISTRAL_V7, LLM_CHAT_TEMPLATE_PHI_3, LLM_CHAT_TEMPLATE_FALCON_3, + LLM_CHAT_TEMPLATE_FALCON_E, LLM_CHAT_TEMPLATE_ZEPHYR, LLM_CHAT_TEMPLATE_MONARCH, LLM_CHAT_TEMPLATE_GEMMA, @@ -1652,6 +1653,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = { { "mistral-v7", LLM_CHAT_TEMPLATE_MISTRAL_V7 }, { "phi3", LLM_CHAT_TEMPLATE_PHI_3 }, { "falcon3", LLM_CHAT_TEMPLATE_FALCON_3 }, + { "falcon_e", LLM_CHAT_TEMPLATE_FALCON_E }, { "zephyr", LLM_CHAT_TEMPLATE_ZEPHYR }, { "monarch", LLM_CHAT_TEMPLATE_MONARCH }, { "gemma", LLM_CHAT_TEMPLATE_GEMMA }, @@ -6191,8 +6193,7 @@ static void llm_load_vocab( } else if ( tokenizer_pre == "llama3" || tokenizer_pre == "llama-v3" || - tokenizer_pre == "llama-bpe"|| - tokenizer_pre == "falcon3") { + tokenizer_pre == "llama-bpe") { vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_LLAMA3; vocab.tokenizer_ignore_merges = true; vocab.tokenizer_add_bos = true; @@ -6211,6 +6212,10 @@ static void llm_load_vocab( } else if ( tokenizer_pre == "falcon") { vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_FALCON; + } else if (tokenizer_pre == "falcon3") { + vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_FALCON_3; + } else if (tokenizer_pre == "falcon_e") { + vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_FALCON_E; } else if ( tokenizer_pre == "mpt") { vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_MPT; @@ -22672,6 +22677,8 @@ static llm_chat_template llama_chat_detect_template(const std::string & tmpl) { return LLM_CHAT_TEMPLATE_PHI_3; } else if (tmpl_contains("<|assistant|>") && tmpl_contains("<|user|>")) { return LLM_CHAT_TEMPLATE_FALCON_3; + } else if (tmpl == "falcon_e" && (tmpl_contains("assistant") && tmpl_contains("user"))) { + return LLM_CHAT_TEMPLATE_FALCON_E; } else if (tmpl_contains("<|user|>") && tmpl_contains("<|endoftext|>")) { return LLM_CHAT_TEMPLATE_ZEPHYR; } else if (tmpl_contains("bos_token + message['role']")) { @@ -22838,6 +22845,15 @@ static int32_t llama_chat_apply_template_internal( if (add_ass) { ss << "<|assistant|>\n"; } + } else if (tmpl == LLM_CHAT_TEMPLATE_FALCON_E) { + // Falcon Edge + for (auto message : chat) { + std::string role(message->role); + ss << role << message->content << "\n"; + } + if (add_ass) { + ss << "assistant\n"; + } } else if (tmpl == LLM_CHAT_TEMPLATE_ZEPHYR) { // zephyr template for (auto message : chat) { |