Skip to content

Commit 54a3e73

Browse files
committed
Update llama.cpp
1 parent 10532f8 commit 54a3e73

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/llama.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,7 @@ enum llm_chat_template {
15621562
LLM_CHAT_TEMPLATE_MISTRAL_V3_TEKKEN,
15631563
LLM_CHAT_TEMPLATE_MISTRAL_V7,
15641564
LLM_CHAT_TEMPLATE_PHI_3,
1565+
LLM_CHAT_TEMPLATE_PHI_4,
15651566
LLM_CHAT_TEMPLATE_FALCON_3,
15661567
LLM_CHAT_TEMPLATE_ZEPHYR,
15671568
LLM_CHAT_TEMPLATE_MONARCH,
@@ -1594,6 +1595,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = {
15941595
{ "mistral-v3-tekken", LLM_CHAT_TEMPLATE_MISTRAL_V3_TEKKEN },
15951596
{ "mistral-v7", LLM_CHAT_TEMPLATE_MISTRAL_V7 },
15961597
{ "phi3", LLM_CHAT_TEMPLATE_PHI_3 },
1598+
{ "phi4", LLM_CHAT_TEMPLATE_PHI_4 },
15971599
{ "falcon3", LLM_CHAT_TEMPLATE_FALCON_3 },
15981600
{ "zephyr", LLM_CHAT_TEMPLATE_ZEPHYR },
15991601
{ "monarch", LLM_CHAT_TEMPLATE_MONARCH },
@@ -21765,7 +21767,9 @@ static llm_chat_template llama_chat_detect_template(const std::string & tmpl) {
2176521767
return tmpl.find(haystack) != std::string::npos;
2176621768
};
2176721769
if (tmpl_contains("<|im_start|>")) {
21768-
return LLM_CHAT_TEMPLATE_CHATML;
21770+
return tmpl_contains("<|im_sep|>")
21771+
? LLM_CHAT_TEMPLATE_PHI_4
21772+
: LLM_CHAT_TEMPLATE_CHATML;
2176921773
} else if (tmpl.find("mistral") == 0 || tmpl_contains("[INST]")) {
2177021774
if (tmpl_contains("[SYSTEM_PROMPT]")) {
2177121775
return LLM_CHAT_TEMPLATE_MISTRAL_V7;
@@ -21955,6 +21959,14 @@ static int32_t llama_chat_apply_template_internal(
2195521959
if (add_ass) {
2195621960
ss << "<|assistant|>\n";
2195721961
}
21962+
} else if (tmpl == LLM_CHAT_TEMPLATE_PHI_4) {
21963+
// chatml template
21964+
for (auto message : chat) {
21965+
ss << "<|im_start|>" << message->role << "<|im_sep|>" << message->content << "<|im_end|>";
21966+
}
21967+
if (add_ass) {
21968+
ss << "<|im_start|>assistant<|im_sep|>";
21969+
}
2195821970
} else if (tmpl == LLM_CHAT_TEMPLATE_FALCON_3) {
2195921971
// Falcon 3
2196021972
for (auto message : chat) {

0 commit comments

Comments
 (0)