Skip to content

Commit 7e0f4f2

Browse files
committed
add mistral-v7-tekken
1 parent c6e0f92 commit 7e0f4f2

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/llama-chat.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = {
3535
{ "mistral-v3", LLM_CHAT_TEMPLATE_MISTRAL_V3 },
3636
{ "mistral-v3-tekken", LLM_CHAT_TEMPLATE_MISTRAL_V3_TEKKEN },
3737
{ "mistral-v7", LLM_CHAT_TEMPLATE_MISTRAL_V7 },
38+
{ "mistral-v7-tekken", LLM_CHAT_TEMPLATE_MISTRAL_V7_TEKKEN },
3839
{ "phi3", LLM_CHAT_TEMPLATE_PHI_3 },
3940
{ "phi4", LLM_CHAT_TEMPLATE_PHI_4 },
4041
{ "falcon3", LLM_CHAT_TEMPLATE_FALCON_3 },
@@ -202,19 +203,20 @@ int32_t llm_chat_apply_template(
202203
if (add_ass) {
203204
ss << "<|im_start|>assistant\n";
204205
}
205-
} else if (tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7) {
206+
} else if (tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7 || tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7_TEKKEN) {
206207
// Official mistral 'v7' template
207208
// See: https://huggingface.co/mistralai/Mistral-Large-Instruct-2411#basic-instruct-template-v7
209+
// https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Instruct-2503#basic-instruct-template-v7-tekken
210+
const char * trailing_space = tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7 ? " " : "";
208211
for (auto message : chat) {
209212
std::string role(message->role);
210213
std::string content(message->content);
211214
if (role == "system") {
212-
ss << "[SYSTEM_PROMPT] " << content << "[/SYSTEM_PROMPT]";
215+
ss << "[SYSTEM_PROMPT]" << trailing_space << content << "[/SYSTEM_PROMPT]";
213216
} else if (role == "user") {
214-
ss << "[INST] " << content << "[/INST]";
215-
}
216-
else {
217-
ss << " " << content << "</s>";
217+
ss << "[INST]" << trailing_space << content << "[/INST]";
218+
} else {
219+
ss << trailing_space << content << "</s>";
218220
}
219221
}
220222
} else if (tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V1

src/llama-chat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum llm_chat_template {
1414
LLM_CHAT_TEMPLATE_MISTRAL_V3,
1515
LLM_CHAT_TEMPLATE_MISTRAL_V3_TEKKEN,
1616
LLM_CHAT_TEMPLATE_MISTRAL_V7,
17+
LLM_CHAT_TEMPLATE_MISTRAL_V7_TEKKEN,
1718
LLM_CHAT_TEMPLATE_PHI_3,
1819
LLM_CHAT_TEMPLATE_PHI_4,
1920
LLM_CHAT_TEMPLATE_FALCON_3,

src/llama-model.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13392,7 +13392,7 @@ const char * llama_model_chat_template(const llama_model * model, const char * n
1339213392
// Mistral-Small-2503 does not have built-in chat template
1339313393
llama_vocab_pre_type pre_type = model->vocab.get_pre_type();
1339413394
if (pre_type == LLAMA_VOCAB_PRE_TYPE_TEKKEN && model->layers.size() == 40) {
13395-
return "mistral-v7";
13395+
return "mistral-v7-tekken";
1339613396
}
1339713397

1339813398
return nullptr;

0 commit comments

Comments
 (0)