From cf9d8efdd374b65dcdea15f8d5bb89b47f98d8ed Mon Sep 17 00:00:00 2001 From: Enrique Shockwave <33002121+qeternity@users.noreply.github.com> Date: Sun, 21 Apr 2024 17:40:12 +0100 Subject: [PATCH] llama3 instruct template (#372) --- python/sglang/lang/chat_template.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/python/sglang/lang/chat_template.py b/python/sglang/lang/chat_template.py index 8e5b9143a..d91dee365 100644 --- a/python/sglang/lang/chat_template.py +++ b/python/sglang/lang/chat_template.py @@ -162,6 +162,28 @@ register_chat_template( ) ) +register_chat_template( + ChatTemplate( + name="llama-3-instruct", + default_system_prompt=None, + role_prefix_and_suffix={ + "system": ( + "<|start_header_id|>system<|end_header_id|>\n\n", + "<|eot_id|>", + ), + "user": ( + "<|start_header_id|>user<|end_header_id|>\n\n", + "<|eot_id|>", + ), + "assistant": ( + "<|start_header_id|>assistant<|end_header_id|>\n\n", + "<|eot_id|>", + ), + }, + stop_str=("<|eot_id|>",), + ) +) + # Reference: https://github.com/01-ai/Yi/tree/main/VL#major-difference-with-llava register_chat_template( ChatTemplate( @@ -233,6 +255,13 @@ def match_llama2_chat(model_path: str): return get_chat_template("llama-2-chat") +@register_chat_template_matching_function +def match_llama3_instruct(model_path: str): + model_path = model_path.lower() + if "llama-3" in model_path and "instruct" in model_path: + return get_chat_template("llama-3-instruct") + + @register_chat_template_matching_function def match_chat_ml(model_path: str): model_path = model_path.lower()