@@ -1562,6 +1562,7 @@ enum llm_chat_template {
1562
1562
LLM_CHAT_TEMPLATE_MISTRAL_V3_TEKKEN,
1563
1563
LLM_CHAT_TEMPLATE_MISTRAL_V7,
1564
1564
LLM_CHAT_TEMPLATE_PHI_3,
1565
+ LLM_CHAT_TEMPLATE_FALCON_3,
1565
1566
LLM_CHAT_TEMPLATE_ZEPHYR,
1566
1567
LLM_CHAT_TEMPLATE_MONARCH,
1567
1568
LLM_CHAT_TEMPLATE_GEMMA,
@@ -1593,6 +1594,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = {
1593
1594
{ "mistral-v3-tekken", LLM_CHAT_TEMPLATE_MISTRAL_V3_TEKKEN },
1594
1595
{ "mistral-v7", LLM_CHAT_TEMPLATE_MISTRAL_V7 },
1595
1596
{ "phi3", LLM_CHAT_TEMPLATE_PHI_3 },
1597
+ { "falcon3", LLM_CHAT_TEMPLATE_FALCON_3 },
1596
1598
{ "zephyr", LLM_CHAT_TEMPLATE_ZEPHYR },
1597
1599
{ "monarch", LLM_CHAT_TEMPLATE_MONARCH },
1598
1600
{ "gemma", LLM_CHAT_TEMPLATE_GEMMA },
@@ -6377,7 +6379,8 @@ static void llm_load_vocab(
6377
6379
} else if (
6378
6380
tokenizer_pre == "llama3" ||
6379
6381
tokenizer_pre == "llama-v3" ||
6380
- tokenizer_pre == "llama-bpe") {
6382
+ tokenizer_pre == "llama-bpe" ||
6383
+ tokenizer_pre == "falcon3") {
6381
6384
vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_LLAMA3;
6382
6385
vocab.tokenizer_ignore_merges = true;
6383
6386
vocab.tokenizer_add_bos = true;
@@ -21794,6 +21797,8 @@ static llm_chat_template llama_chat_detect_template(const std::string & tmpl) {
21794
21797
}
21795
21798
} else if (tmpl_contains("<|assistant|>") && tmpl_contains("<|end|>")) {
21796
21799
return LLM_CHAT_TEMPLATE_PHI_3;
21800
+ } else if (tmpl_contains("<|assistant|>") && tmpl_contains("<|user|>")) {
21801
+ return LLM_CHAT_TEMPLATE_FALCON_3;
21797
21802
} else if (tmpl_contains("<|user|>") && tmpl_contains("<|endoftext|>")) {
21798
21803
return LLM_CHAT_TEMPLATE_ZEPHYR;
21799
21804
} else if (tmpl_contains("bos_token + message['role']")) {
@@ -21944,6 +21949,15 @@ static int32_t llama_chat_apply_template_internal(
21944
21949
if (add_ass) {
21945
21950
ss << "<|assistant|>\n";
21946
21951
}
21952
+ } else if (tmpl == LLM_CHAT_TEMPLATE_FALCON_3) {
21953
+ // Falcon 3
21954
+ for (auto message : chat) {
21955
+ std::string role(message->role);
21956
+ ss << "<|" << role << "|>\n" << message->content << "\n";
21957
+ }
21958
+ if (add_ass) {
21959
+ ss << "<|assistant|>\n";
21960
+ }
21947
21961
} else if (tmpl == LLM_CHAT_TEMPLATE_ZEPHYR) {
21948
21962
// zephyr template
21949
21963
for (auto message : chat) {
0 commit comments