@@ -1616,6 +1616,7 @@ enum llm_chat_template {
16161616 LLM_CHAT_TEMPLATE_MISTRAL_V3_TEKKEN,
16171617 LLM_CHAT_TEMPLATE_MISTRAL_V7,
16181618 LLM_CHAT_TEMPLATE_PHI_3,
1619+ LLM_CHAT_TEMPLATE_FALCON_3,
16191620 LLM_CHAT_TEMPLATE_ZEPHYR,
16201621 LLM_CHAT_TEMPLATE_MONARCH,
16211622 LLM_CHAT_TEMPLATE_GEMMA,
@@ -1648,6 +1649,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = {
16481649 { "mistral-v3-tekken", LLM_CHAT_TEMPLATE_MISTRAL_V3_TEKKEN },
16491650 { "mistral-v7", LLM_CHAT_TEMPLATE_MISTRAL_V7 },
16501651 { "phi3", LLM_CHAT_TEMPLATE_PHI_3 },
1652+ { "falcon3", LLM_CHAT_TEMPLATE_FALCON_3 },
16511653 { "zephyr", LLM_CHAT_TEMPLATE_ZEPHYR },
16521654 { "monarch", LLM_CHAT_TEMPLATE_MONARCH },
16531655 { "gemma", LLM_CHAT_TEMPLATE_GEMMA },
@@ -6477,6 +6479,11 @@ static void llm_load_vocab(
64776479 } else if (
64786480 tokenizer_pre == "falcon") {
64796481 vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_FALCON;
6482+ } else if (
6483+ tokenizer_pre == "falcon3") {
6484+ vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_LLAMA3;
6485+ vocab.tokenizer_ignore_merges = true;
6486+ vocab.tokenizer_add_bos = true;
64806487 } else if (
64816488 tokenizer_pre == "mpt") {
64826489 vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_MPT;
@@ -22228,6 +22235,8 @@ static llm_chat_template llama_chat_detect_template(const std::string & tmpl) {
2222822235 }
2222922236 } else if (tmpl_contains("<|assistant|>") && tmpl_contains("<|end|>")) {
2223022237 return LLM_CHAT_TEMPLATE_PHI_3;
22238+ } else if (tmpl_contains("<|assistant|>") && tmpl_contains("<|user|>")) {
22239+ return LLM_CHAT_TEMPLATE_FALCON_3;
2223122240 } else if (tmpl_contains("<|user|>") && tmpl_contains("<|endoftext|>")) {
2223222241 return LLM_CHAT_TEMPLATE_ZEPHYR;
2223322242 } else if (tmpl_contains("bos_token + message['role']")) {
@@ -22380,6 +22389,15 @@ static int32_t llama_chat_apply_template_internal(
2238022389 if (add_ass) {
2238122390 ss << "<|assistant|>\n";
2238222391 }
22392+ } else if (tmpl == LLM_CHAT_TEMPLATE_FALCON_3) {
22393+ // Falcon 3
22394+ for (auto message : chat) {
22395+ std::string role(message->role);
22396+ ss << "<|" << role << "|>\n" << message->content << "\n";
22397+ }
22398+ if (add_ass) {
22399+ ss << "<|assistant|>\n";
22400+ }
2238322401 } else if (tmpl == LLM_CHAT_TEMPLATE_ZEPHYR) {
2238422402 // zephyr template
2238522403 for (auto message : chat) {
0 commit comments