Skip to content

Commit 325d83e

Browse files
ngxsonmglambda
authored andcommitted
llama : fix chat template gguf key (ggml-org#11201)
1 parent bcfa918 commit 325d83e

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

common/common.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,15 +1636,8 @@ std::string common_detokenize(const struct llama_vocab * vocab, const std::vecto
16361636
//
16371637

16381638
std::string common_get_builtin_chat_template(const struct llama_model * model) {
1639-
static const char * template_key = "tokenizer.chat_template";
1640-
// call with NULL buffer to get the total size of the string
1641-
int32_t res = llama_model_meta_val_str(model, template_key, NULL, 0);
1642-
if (res > 0) {
1643-
std::vector<char> model_template(res + 1, 0);
1644-
llama_model_meta_val_str(model, template_key, model_template.data(), model_template.size());
1645-
return std::string(model_template.data(), model_template.size() - 1);
1646-
}
1647-
return "";
1639+
const char * ptr_tmpl = llama_model_chat_template(model);
1640+
return ptr_tmpl == nullptr ? "" : ptr_tmpl;
16481641
}
16491642

16501643
bool common_chat_verify_template(const std::string & tmpl) {

src/llama-arch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static const std::map<llm_kv, const char *> LLM_KV_NAMES = {
178178
{ LLM_KV_TOKENIZER_PRECOMPILED_CHARSMAP, "tokenizer.ggml.precompiled_charsmap" },
179179
{ LLM_KV_TOKENIZER_HF_JSON, "tokenizer.huggingface.json" },
180180
{ LLM_KV_TOKENIZER_RWKV, "tokenizer.rwkv.world" },
181-
{ LLM_KV_TOKENIZER_CHAT_TEMPLATE, "tokenizer.chat.template" },
181+
{ LLM_KV_TOKENIZER_CHAT_TEMPLATE, "tokenizer.chat_template" },
182182
{ LLM_KV_TOKENIZER_FIM_PRE_ID, "tokenizer.ggml.fim_pre_token_id" },
183183
{ LLM_KV_TOKENIZER_FIM_SUF_ID, "tokenizer.ggml.fim_suf_token_id" },
184184
{ LLM_KV_TOKENIZER_FIM_MID_ID, "tokenizer.ggml.fim_mid_token_id" },

0 commit comments

Comments
 (0)