From af6c5357d5cb283341ef21f8aeb093753bd10a2b Mon Sep 17 00:00:00 2001 From: Enrique Shockwave <33002121+qeternity@users.noreply.github.com> Date: Mon, 20 Jan 2025 22:40:12 +0000 Subject: [PATCH] deepseek v3 and r1 chat template (#3015) --- python/sglang/lang/chat_template.py | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/python/sglang/lang/chat_template.py b/python/sglang/lang/chat_template.py index 845e1e52d..a2c91c561 100644 --- a/python/sglang/lang/chat_template.py +++ b/python/sglang/lang/chat_template.py @@ -354,6 +354,37 @@ register_chat_template( ) +register_chat_template( + ChatTemplate( + name="deepseek-v3", + default_system_prompt=None, + role_prefix_and_suffix={ + "system": ( + "", + "", + ), + "user": ( + "<|User|>", + "", + ), + "assistant": ( + "<|Assistant|>", + "<|end▁of▁sentence|>", + ), + }, + stop_str=("<|end▁of▁sentence|>",), + ) +) + + +@register_chat_template_matching_function +def match_deepseek(model_path: str): + if ( + "deepseek-v3" in model_path.lower() or "deepseek-r1" in model_path.lower() + ) and "base" not in model_path.lower(): + return get_chat_template("deepseek-v3") + + @register_chat_template_matching_function def match_dbrx(model_path: str): if "dbrx" in model_path.lower() and "instruct" in model_path.lower():