Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
67b38f5
Supporting Velvet model
fbuciuni90 Feb 6, 2025
07e1d0a
Update convert_hf_to_gguf.py
fbuciuni90 Feb 6, 2025
99be555
Update convert_hf_to_gguf.py
fbuciuni90 Feb 6, 2025
3df9d22
Update include/llama.h
fbuciuni90 Feb 6, 2025
52b0bb3
Update src/llama-chat.cpp
fbuciuni90 Feb 6, 2025
9d86a04
removing whitespaces in src/lla-a-chat.cpp
fbuciuni90 Feb 7, 2025
66e6d10
fixing position of LLM_CHAT_TEMPLATE_VELVET in enum
fbuciuni90 Feb 7, 2025
3979557
updating velvet chat template
fbuciuni90 Feb 7, 2025
0a8995a
adding test case for velvet chat template
fbuciuni90 Feb 7, 2025
e8981aa
upadated llama-vocab.cpp with velvet case
fbuciuni90 Feb 12, 2025
c4c923a
attempt to fix pretokenization regex
fbuciuni90 Feb 20, 2025
50bf79b
fixed pre tokenization regex
fbuciuni90 Feb 21, 2025
308ef21
fixed chat template
fbuciuni90 Feb 21, 2025
22257d8
Merge branch 'master' into master
fbuciuni90 Mar 20, 2025
8e6b29e
Merge branch 'master' into master
fbuciuni90 Mar 26, 2025
8c57157
Merge branch 'master' into master
fbuciuni90 Apr 11, 2025
a7c4895
Merge branch 'ggml-org:master' into master
fbuciuni90 Apr 11, 2025
bc15f90
fix typo in llama-vocab.cpp caused by merge
fbuciuni90 Apr 11, 2025
bd0ffeb
fix indentation tab issue
fbuciuni90 Apr 11, 2025
c516dbd
fix chat template test caused by sync
fbuciuni90 Apr 14, 2025
a78b983
small fix in chat template test
fbuciuni90 Apr 16, 2025
ac6206c
Merge branch 'master' into master
fbuciuni90 May 15, 2025
4e743d8
Merge branch 'ggml-org:master' into master
fbuciuni90 May 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions convert_hf_to_gguf.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,9 @@ def get_vocab_base_pre(self, tokenizer) -> str:
if chkhsh == "b3f499bb4255f8ca19fccd664443283318f2fd2414d5e0b040fbdd0cc195d6c5":
# ref: https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B
res = "deepseek-r1-qwen"
if chkhsh == "a3df2b8943e01cfd7d68c9f8446b294f3d8706d1d6853df65df7fda5d4fcb19f":
# ref: https://huggingface.co/Almawave/Velvet-14B
res = "velvet"

if res is None:
logger.warning("\n")
Expand Down
1 change: 1 addition & 0 deletions convert_hf_to_gguf_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class TOKENIZER_TYPE(IntEnum):
{"name": "megrez", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/Infinigence/Megrez-3B-Instruct"},
{"name": "deepseek-v3", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/deepseek-ai/DeepSeek-V3"},
{"name": "deepseek-r1-qwen", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"},
{"name": "velvet", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/Almawave/Velvet-14B"}
]


Expand Down
1 change: 1 addition & 0 deletions include/llama.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ extern "C" {
LLAMA_VOCAB_PRE_TYPE_CHAMELEON = 26,
LLAMA_VOCAB_PRE_TYPE_MINERVA = 27,
LLAMA_VOCAB_PRE_TYPE_DEEPSEEK3_LLM = 28,
LLAMA_VOCAB_PRE_TYPE_VELVET = 29
};

enum llama_rope_type {
Expand Down
27 changes: 26 additions & 1 deletion src/llama-chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = {
{ "granite", LLM_CHAT_TEMPLATE_GRANITE },
{ "gigachat", LLM_CHAT_TEMPLATE_GIGACHAT },
{ "megrez", LLM_CHAT_TEMPLATE_MEGREZ },
{ "velvet", LLM_CHAT_TEMPLATE_VELVET },
};

llm_chat_template llm_chat_template_from_str(const std::string & name) {
Expand Down Expand Up @@ -167,6 +168,8 @@ llm_chat_template llm_chat_detect_template(const std::string & tmpl) {
return LLM_CHAT_TEMPLATE_GIGACHAT;
} else if (tmpl_contains("<|role_start|>")) {
return LLM_CHAT_TEMPLATE_MEGREZ;
} else if (tmpl_contains("<instruction>")) {
return LLM_CHAT_TEMPLATE_VELVET;
}
return LLM_CHAT_TEMPLATE_UNKNOWN;
}
Expand Down Expand Up @@ -566,10 +569,32 @@ int32_t llm_chat_apply_template(
if (add_ass) {
ss << "<|role_start|>assistant<|role_end|>";
}
} else if (tmpl == LLM_CHAT_TEMPLATE_VELVET) {
// Velvet template
std::string leading_space = "";
std::string trailing_space = "";
bool trim_assistant_message = true;
bool is_inside_turn = false;
for (auto message : chat) {
if (!is_inside_turn) {
ss << leading_space << "<instruction>" << trailing_space;
is_inside_turn = true;
}
std::string role(message->role);
std::string content(message->content);
if (role == "system") {
ss << content << "\n\n";
} else if (role == "user") {
ss << content << leading_space << "</instruction>";
} else {
ss << trailing_space << (trim_assistant_message ? trim(content) : content) << "</s>";
is_inside_turn = false;
}
}
} else {
// template not supported
return -1;
}
}
dest = ss.str();
return dest.size();
}
Expand Down
1 change: 1 addition & 0 deletions src/llama-chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum llm_chat_template {
LLM_CHAT_TEMPLATE_GIGACHAT,
LLM_CHAT_TEMPLATE_MEGREZ,
LLM_CHAT_TEMPLATE_UNKNOWN,
LLM_CHAT_TEMPLATE_VELVET
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also recommended to add a test for this chat template, see test-chat-template.cpp

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, this enum value is in the incorrect place. everything must come before LLM_CHAT_TEMPLATE_UNKNOWN

please also add a test case in test-chat-template.cpp. Otherwise you will expect it to be broken in the future

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the test case for chat template as you suggested and I did the requested changes. Let me know if I still missing something. Thanks.

};

struct llama_chat_message;
Expand Down
Loading