Skip to content

Commit 675f35d

Browse files
fix hunyuan dense vocab and chat template
Signed-off-by: stevenkuang <[email protected]>
1 parent 6c17323 commit 675f35d

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

convert_hf_to_gguf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,8 @@ def get_vocab_base_pre(self, tokenizer) -> str:
685685
# ref: https://huggingface.co/tencent/Hunyuan-A13B-Instruct
686686
res = "hunyuan"
687687
if chkhsh == "bba3b3366b646dbdded5dbc42d59598b849371afc42f7beafa914afaa5b70aa6":
688-
# ref: https://huggingface.co/tencent/Hunyuan-4B
689-
res = "hunyuan"
688+
# ref: https://huggingface.co/tencent/Hunyuan-4B-Instruct
689+
res = "hunyuan-dense"
690690
if chkhsh == "a6b57017d60e6edb4d88ecc2845188e0eb333a70357e45dcc9b53964a73bbae6":
691691
# ref: https://huggingface.co/tiiuae/Falcon-H1-0.5B-Base
692692
res = "falcon-h1"
@@ -7533,7 +7533,6 @@ class HunYuanModel(TextModel):
75337533
def set_vocab(self):
75347534
if (self.dir_model / "tokenizer.json").is_file():
75357535
self._set_vocab_gpt2()
7536-
self.gguf_writer.add_add_bos_token(True)
75377536
else:
75387537
from transformers import AutoTokenizer
75397538
tokenizer = AutoTokenizer.from_pretrained(self.dir_model, trust_remote_code=True)

convert_hf_to_gguf_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class TOKENIZER_TYPE(IntEnum):
140140
{"name": "glm4", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/THUDM/glm-4-9b-hf", "chkhsh": "a1336059768a55c99a734006ffb02203cd450fed003e9a71886c88acf24fdbc2"},
141141
{"name": "minerva-7b", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/sapienzanlp/Minerva-7B-base-v1.0", "chkhsh": "1431a23e583c97432bc230bff598d103ddb5a1f89960c8f1d1051aaa944d0b35"},
142142
{"name": "hunyuan", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/tencent/Hunyuan-A13B-Instruct", "chkhsh": "7e57df22b1fe23a7b1e1c7f3dc4e3f96d43a4eb0836d0c6bdc3436d7b2f1c664"},
143-
{"name": "hunyuan", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/tencent/Hunyuan-4B", "chkhsh": "bba3b3366b646dbdded5dbc42d59598b849371afc42f7beafa914afaa5b70aa6"},
143+
{"name": "hunyuan-dense", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/tencent/Hunyuan-4B-Instruct", "chkhsh": "bba3b3366b646dbdded5dbc42d59598b849371afc42f7beafa914afaa5b70aa6"},
144144
# falcon-h1 series uses 4 different tokenizers across model sizes (0.5b - 34b), hence we need to define 4 different hashes
145145
{"name": "falcon-h1", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/tiiuae/Falcon-H1-0.5B-Base", "chkhsh": "a6b57017d60e6edb4d88ecc2845188e0eb333a70357e45dcc9b53964a73bbae6"},
146146
{"name": "falcon-h1", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/tiiuae/Falcon-H1-1B-Base", "chkhsh": "60476e1243776c4fb1b993dbd7a5f15ac22f83c80afdf425fa5ae01c8d44ef86"},

src/llama-chat.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ int32_t llm_chat_apply_template(
707707
}
708708
}
709709
} else if (tmpl == LLM_CHAT_TEMPLATE_HUNYUAN_DENSE) {
710-
// tencent/Hunyuan-4B
710+
// tencent/Hunyuan-4B-Instruct
711711
for (size_t i = 0; i < chat.size(); i++) {
712712
std::string role(chat[i]->role);
713713
if (i == 0) {
@@ -719,14 +719,9 @@ int32_t llm_chat_apply_template(
719719
if (role == "assistant") {
720720
ss << "<|hy_Assistant|>" << chat[i]->content << "<|hy_place▁holder▁no▁2|>";
721721
} else if (role == "user") {
722-
ss << "<|hy_User|>" << chat[i]->content;
722+
ss << "<|hy_User|>" << chat[i]->content << "<|hy_Assistant|>";
723723
}
724724
}
725-
if (add_ass) {
726-
ss << "<|hy_Assistant|>";
727-
} else {
728-
ss << "<|hy_place▁holder▁no▁8|>";
729-
}
730725
} else if (tmpl == LLM_CHAT_TEMPLATE_KIMI_K2) {
731726
// moonshotai/Kimi-K2-Instruct
732727
for (auto message : chat) {

src/llama-vocab.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ struct llm_tokenizer_bpe : llm_tokenizer {
307307
};
308308
break;
309309
case LLAMA_VOCAB_PRE_TYPE_DEEPSEEK3_LLM:
310+
case LLAMA_VOCAB_PRE_TYPE_HUNYUAN_DENSE:
310311
regex_exprs = {
311312
"\\p{N}{1,3}",
312313
"[一-龥぀-ゟ゠-ヿ]+",
@@ -1964,6 +1965,10 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
19641965
tokenizer_pre == "hunyuan") {
19651966
pre_type = LLAMA_VOCAB_PRE_TYPE_HUNYUAN;
19661967
clean_spaces = false;
1968+
} else if (
1969+
tokenizer_pre == "hunyuan-dense") {
1970+
pre_type = LLAMA_VOCAB_PRE_TYPE_HUNYUAN_DENSE;
1971+
clean_spaces = false;
19671972
} else if (
19681973
tokenizer_pre == "kimi-k2") {
19691974
pre_type = LLAMA_VOCAB_PRE_TYPE_KIMI_K2;

src/llama-vocab.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ enum llama_vocab_pre_type {
4646
LLAMA_VOCAB_PRE_TYPE_SEED_CODER = 35,
4747
LLAMA_VOCAB_PRE_TYPE_HUNYUAN = 36,
4848
LLAMA_VOCAB_PRE_TYPE_KIMI_K2 = 37,
49+
LLAMA_VOCAB_PRE_TYPE_HUNYUAN_DENSE = 38,
4950
};
5051

5152
struct LLM_KV;

0 commit comments

Comments
 (0)