From 67b38f5849ac5b116ed869ac8499aace0435457a Mon Sep 17 00:00:00 2001 From: fbuciuni90 Date: Thu, 6 Feb 2025 16:02:00 +0000 Subject: [PATCH] Supporting Velvet model --- convert_hf_to_gguf.py | 3 +++ convert_hf_to_gguf_update.py | 1 + include/llama.h | 1 + src/llama-chat.cpp | 27 ++++++++++++++++++++++++++- src/llama-chat.h | 1 + 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/convert_hf_to_gguf.py b/convert_hf_to_gguf.py index 018a2a588..9da7963c4 100755 --- a/convert_hf_to_gguf.py +++ b/convert_hf_to_gguf.py @@ -699,6 +699,9 @@ class Model: 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") diff --git a/convert_hf_to_gguf_update.py b/convert_hf_to_gguf_update.py index cea34413f..241d04557 100755 --- a/convert_hf_to_gguf_update.py +++ b/convert_hf_to_gguf_update.py @@ -109,6 +109,7 @@ models = [ {"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"} ] diff --git a/include/llama.h b/include/llama.h index 61907ed40..a1fbd213a 100644 --- a/include/llama.h +++ b/include/llama.h @@ -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 { diff --git a/src/llama-chat.cpp b/src/llama-chat.cpp index 028a64794..0cae2bb10 100644 --- a/src/llama-chat.cpp +++ b/src/llama-chat.cpp @@ -58,6 +58,7 @@ static const std::map 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) { @@ -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("")) { + return LLM_CHAT_TEMPLATE_VELVET; } return LLM_CHAT_TEMPLATE_UNKNOWN; } @@ -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 << "" << 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 << ""; + } else { + ss << trailing_space << (trim_assistant_message ? trim(content) : content) << ""; + is_inside_turn = false; + } + } } else { // template not supported return -1; - } + } dest = ss.str(); return dest.size(); } diff --git a/src/llama-chat.h b/src/llama-chat.h index 2f6a0e3e2..e91f09f2c 100644 --- a/src/llama-chat.h +++ b/src/llama-chat.h @@ -39,6 +39,7 @@ enum llm_chat_template { LLM_CHAT_TEMPLATE_GIGACHAT, LLM_CHAT_TEMPLATE_MEGREZ, LLM_CHAT_TEMPLATE_UNKNOWN, + LLM_CHAT_TEMPLATE_VELVET }; struct llama_chat_message;