Supporting Velvet model
This commit is contained in:
		
							parent
							
								
									9ab42dc722
								
							
						
					
					
						commit
						67b38f5849
					
				
					 5 changed files with 32 additions and 1 deletions
				
			
		|  | @ -699,6 +699,9 @@ class Model: | ||||||
|         if chkhsh == "b3f499bb4255f8ca19fccd664443283318f2fd2414d5e0b040fbdd0cc195d6c5": |         if chkhsh == "b3f499bb4255f8ca19fccd664443283318f2fd2414d5e0b040fbdd0cc195d6c5": | ||||||
|             # ref: https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B |             # ref: https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B | ||||||
|             res = "deepseek-r1-qwen" |             res = "deepseek-r1-qwen" | ||||||
|  |         if chkhsh == "a3df2b8943e01cfd7d68c9f8446b294f3d8706d1d6853df65df7fda5d4fcb19f": | ||||||
|  |             # ref: https://huggingface.co/Almawave/Velvet-14B | ||||||
|  |             res = "velvet"     | ||||||
| 
 | 
 | ||||||
|         if res is None: |         if res is None: | ||||||
|             logger.warning("\n") |             logger.warning("\n") | ||||||
|  |  | ||||||
|  | @ -109,6 +109,7 @@ models = [ | ||||||
|     {"name": "megrez",           "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/Infinigence/Megrez-3B-Instruct"}, |     {"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-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": "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"} | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -105,6 +105,7 @@ extern "C" { | ||||||
|         LLAMA_VOCAB_PRE_TYPE_CHAMELEON      = 26, |         LLAMA_VOCAB_PRE_TYPE_CHAMELEON      = 26, | ||||||
|         LLAMA_VOCAB_PRE_TYPE_MINERVA        = 27, |         LLAMA_VOCAB_PRE_TYPE_MINERVA        = 27, | ||||||
|         LLAMA_VOCAB_PRE_TYPE_DEEPSEEK3_LLM  = 28, |         LLAMA_VOCAB_PRE_TYPE_DEEPSEEK3_LLM  = 28, | ||||||
|  |         LLAMA_VOCAB_PRE_TYPE_VELVET         = 29 | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     enum llama_rope_type { |     enum llama_rope_type { | ||||||
|  |  | ||||||
|  | @ -58,6 +58,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = { | ||||||
|     { "granite",           LLM_CHAT_TEMPLATE_GRANITE           }, |     { "granite",           LLM_CHAT_TEMPLATE_GRANITE           }, | ||||||
|     { "gigachat",          LLM_CHAT_TEMPLATE_GIGACHAT          }, |     { "gigachat",          LLM_CHAT_TEMPLATE_GIGACHAT          }, | ||||||
|     { "megrez",            LLM_CHAT_TEMPLATE_MEGREZ            }, |     { "megrez",            LLM_CHAT_TEMPLATE_MEGREZ            }, | ||||||
|  |     { "velvet",            LLM_CHAT_TEMPLATE_VELVET            }, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| llm_chat_template llm_chat_template_from_str(const std::string & name) { | 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; |         return LLM_CHAT_TEMPLATE_GIGACHAT; | ||||||
|     } else if (tmpl_contains("<|role_start|>")) { |     } else if (tmpl_contains("<|role_start|>")) { | ||||||
|         return LLM_CHAT_TEMPLATE_MEGREZ; |         return LLM_CHAT_TEMPLATE_MEGREZ; | ||||||
|  |     } else if (tmpl_contains("<instruction>")) { | ||||||
|  |         return LLM_CHAT_TEMPLATE_VELVET;     | ||||||
|     } |     } | ||||||
|     return LLM_CHAT_TEMPLATE_UNKNOWN; |     return LLM_CHAT_TEMPLATE_UNKNOWN; | ||||||
| } | } | ||||||
|  | @ -566,6 +569,28 @@ int32_t llm_chat_apply_template( | ||||||
|         if (add_ass) { |         if (add_ass) { | ||||||
|             ss << "<|role_start|>assistant<|role_end|>"; |             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 { |     } else { | ||||||
|         // template not supported
 |         // template not supported
 | ||||||
|         return -1; |         return -1; | ||||||
|  |  | ||||||
|  | @ -39,6 +39,7 @@ enum llm_chat_template { | ||||||
|     LLM_CHAT_TEMPLATE_GIGACHAT, |     LLM_CHAT_TEMPLATE_GIGACHAT, | ||||||
|     LLM_CHAT_TEMPLATE_MEGREZ, |     LLM_CHAT_TEMPLATE_MEGREZ, | ||||||
|     LLM_CHAT_TEMPLATE_UNKNOWN, |     LLM_CHAT_TEMPLATE_UNKNOWN, | ||||||
|  |     LLM_CHAT_TEMPLATE_VELVET | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| struct llama_chat_message; | struct llama_chat_message; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue