chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""Global namespace of conversation template registry"""
|
||||
|
||||
# TODO(mlc-team): move conversation template apply to this namespace
|
||||
# decouple conversation template apply from the conversation protocol
|
||||
# data structure
|
||||
|
||||
# model preset templates
|
||||
from . import (
|
||||
cohere,
|
||||
deepseek,
|
||||
dolly,
|
||||
gemma,
|
||||
glm,
|
||||
gorilla,
|
||||
gpt,
|
||||
hermes,
|
||||
llama,
|
||||
llava,
|
||||
llm_jp,
|
||||
ministral3,
|
||||
ministral3_reasoning,
|
||||
mistral,
|
||||
nemotron,
|
||||
oasst,
|
||||
olmo,
|
||||
olmo2,
|
||||
orion,
|
||||
phi,
|
||||
qwen2,
|
||||
qwen3,
|
||||
qwen3_5,
|
||||
redpajama,
|
||||
rwkv,
|
||||
stablelm,
|
||||
tinyllama,
|
||||
wizardlm,
|
||||
)
|
||||
from .registry import ConvTemplateRegistry
|
||||
@@ -0,0 +1,27 @@
|
||||
"""Cohere default templates"""
|
||||
|
||||
|
||||
# Referred from: https://huggingface.co/CohereForAI/aya-23-8B/blob/main/tokenizer_config.json
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Aya-23
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="aya-23",
|
||||
system_template=f"<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{MessagePlaceholders.SYSTEM.value}<|END_OF_TURN_TOKEN|>",
|
||||
system_message="You are Command-R, a brilliant, sophisticated, AI-assistant trained to assist human users by providing thorough responses.", # noqa: E501
|
||||
roles={
|
||||
"user": "<|START_OF_TURN_TOKEN|><|USER_TOKEN|>",
|
||||
"assistant": "<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>",
|
||||
},
|
||||
seps=["<|END_OF_TURN_TOKEN|>"],
|
||||
role_content_sep="",
|
||||
role_empty_sep="",
|
||||
system_prefix_token_ids=[5],
|
||||
stop_str=["<|END_OF_TURN_TOKEN|>"],
|
||||
stop_token_ids=[6, 255001],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,85 @@
|
||||
"""Deepseek default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Deepseek
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="deepseek",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
system_prefix_token_ids=[100000],
|
||||
roles={"user": "User", "assistant": "Assistant"},
|
||||
seps=["\n\n", "<|end▁of▁sentence|>"], # noqa: RUF001
|
||||
role_content_sep=": ",
|
||||
role_empty_sep=":",
|
||||
stop_str=["<|end▁of▁sentence|>"], # noqa: RUF001
|
||||
stop_token_ids=[100001],
|
||||
)
|
||||
)
|
||||
|
||||
# Deepseek V2
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="deepseek_v2",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
system_prefix_token_ids=[100000],
|
||||
roles={"user": "User", "assistant": "Assistant"},
|
||||
seps=["\n\n", "<|end▁of▁sentence|>"], # noqa: RUF001
|
||||
role_content_sep=": ",
|
||||
role_empty_sep=":",
|
||||
stop_str=["<|end▁of▁sentence|>"], # noqa: RUF001
|
||||
stop_token_ids=[100001],
|
||||
)
|
||||
)
|
||||
|
||||
# DeepSeek-V3
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="deepseek_v3",
|
||||
system_template=f"<|begin▁of▁sentence|>{MessagePlaceholders.SYSTEM.value}", # noqa: RUF001
|
||||
system_message="You are Deepseek-V3, an AI assistant created exclusively by the Chinese "
|
||||
"Company DeepSeek. You'll provide helpful, harmless, and detailed responses to all "
|
||||
"user inquiries.",
|
||||
roles={"user": "<|User|>", "assistant": "<|Assistant|>"}, # noqa: RUF001
|
||||
seps=["", "<|end▁of▁sentence|>"], # noqa: RUF001
|
||||
role_content_sep="",
|
||||
role_empty_sep="",
|
||||
stop_token_ids=[1],
|
||||
)
|
||||
)
|
||||
|
||||
# DeepSeek-R1-Distill-Qwen
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="deepseek_r1_qwen",
|
||||
system_template=f"<|begin▁of▁sentence|>{MessagePlaceholders.SYSTEM.value}", # noqa: RUF001
|
||||
system_message="You are Deepseek-R1, an AI assistant created exclusively by the Chinese "
|
||||
"Company DeepSeek. You'll provide helpful, harmless, and detailed responses to all "
|
||||
"user inquiries.",
|
||||
roles={"user": "<|User|>", "assistant": "<|Assistant|>"}, # noqa: RUF001
|
||||
seps=["", "<|end▁of▁sentence|>"], # noqa: RUF001
|
||||
role_content_sep="",
|
||||
role_empty_sep="",
|
||||
stop_token_ids=[151643],
|
||||
)
|
||||
)
|
||||
|
||||
# DeepSeek-R1-Distill-Llama, exactly the same as DeepSeek-R1-Distill-Qwen, but different stop token
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="deepseek_r1_llama",
|
||||
system_template=f"<|begin▁of▁sentence|>{MessagePlaceholders.SYSTEM.value}", # noqa: RUF001
|
||||
system_message="You are Deepseek-R1, an AI assistant created exclusively by the Chinese "
|
||||
"Company DeepSeek. You'll provide helpful, harmless, and detailed responses to all"
|
||||
" user inquiries.",
|
||||
roles={"user": "<|User|>", "assistant": "<|Assistant|>"}, # noqa: RUF001
|
||||
seps=["", "<|end▁of▁sentence|>"], # noqa: RUF001
|
||||
role_content_sep="",
|
||||
role_empty_sep="",
|
||||
stop_token_ids=[128001],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,23 @@
|
||||
"""Dolly default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Dolly
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="dolly",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message=(
|
||||
"Below is an instruction that describes a task. Write "
|
||||
"a response that appropriately completes the request."
|
||||
),
|
||||
roles={"user": "### Instruction", "assistant": "### Response"},
|
||||
seps=["\n\n", "### End\n"],
|
||||
role_content_sep=":\n",
|
||||
role_empty_sep=":\n",
|
||||
stop_str=["### End"],
|
||||
stop_token_ids=[50256],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,37 @@
|
||||
"""Gemma default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Gemma Instruction
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="gemma_instruction",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "<start_of_turn>user", "assistant": "<start_of_turn>model"},
|
||||
seps=["<end_of_turn>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<end_of_turn>"],
|
||||
stop_token_ids=[1, 107],
|
||||
system_prefix_token_ids=[2],
|
||||
)
|
||||
)
|
||||
|
||||
# Gemma 3 Instruction. Same as gemma_instruction but with different stop token id
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="gemma3_instruction",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "<start_of_turn>user", "assistant": "<start_of_turn>model"},
|
||||
seps=["<end_of_turn>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<end_of_turn>"],
|
||||
stop_token_ids=[1, 106],
|
||||
system_prefix_token_ids=[2],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
"""GLM default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# GLM
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="glm",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={
|
||||
"user": "问",
|
||||
"assistant": "答",
|
||||
"tool": "问",
|
||||
},
|
||||
seps=["\n\n"],
|
||||
role_content_sep=": ",
|
||||
role_empty_sep=":",
|
||||
stop_str=["</s>"],
|
||||
stop_token_ids=[2],
|
||||
system_prefix_token_ids=[64790, 64792],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,62 @@
|
||||
"""Gorrilla default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Gorilla
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="gorilla",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message=(
|
||||
"A chat between a curious user and an artificial intelligence assistant. "
|
||||
"The assistant provides helpful, detailed, and "
|
||||
"polite responses to the user's inquiries."
|
||||
),
|
||||
role_templates={
|
||||
"user": (
|
||||
f"<<question>> {MessagePlaceholders.USER.value} <<function>> "
|
||||
f"{MessagePlaceholders.FUNCTION.value}"
|
||||
),
|
||||
},
|
||||
roles={"user": "USER", "assistant": "ASSISTANT", "tool": "USER"},
|
||||
seps=["\n", "</s>"],
|
||||
role_content_sep=": ",
|
||||
role_empty_sep=":",
|
||||
stop_str=["</s>"],
|
||||
stop_token_ids=[2],
|
||||
system_prefix_token_ids=[1],
|
||||
)
|
||||
)
|
||||
|
||||
# Gorilla-openfunctions-v2
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="gorilla-openfunctions-v2",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message=(
|
||||
"You are an AI programming assistant, utilizing the Gorilla LLM model, "
|
||||
"developed by Gorilla LLM, and you only answer questions related to computer "
|
||||
"science. For politically sensitive questions, security and privacy issues, "
|
||||
"and other non-computer science questions, you will refuse to answer."
|
||||
),
|
||||
role_templates={
|
||||
"user": (
|
||||
f"<<function>>{MessagePlaceholders.FUNCTION.value}\n<<question>>"
|
||||
f"{MessagePlaceholders.USER.value}"
|
||||
),
|
||||
},
|
||||
roles={
|
||||
"user": "### Instruction",
|
||||
"assistant": "### Response",
|
||||
"tool": "### Instruction",
|
||||
},
|
||||
seps=["\n", "<|EOT|>"],
|
||||
role_content_sep=": ",
|
||||
role_empty_sep=": ",
|
||||
stop_str=["<|EOT|>"],
|
||||
stop_token_ids=[100015],
|
||||
system_prefix_token_ids=[100000],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,35 @@
|
||||
"""GPT-2 and GPT bigcode default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# GPT-2
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="gpt2",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "", "assistant": ""},
|
||||
seps=[""],
|
||||
role_content_sep="",
|
||||
role_empty_sep="",
|
||||
stop_str=["</s>"],
|
||||
stop_token_ids=[50256],
|
||||
)
|
||||
)
|
||||
|
||||
# GPTBigCode
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="gpt_bigcode",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "", "assistant": ""},
|
||||
seps=[""],
|
||||
role_content_sep="",
|
||||
role_empty_sep="",
|
||||
stop_str=["<|endoftext|>"],
|
||||
stop_token_ids=[0],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,93 @@
|
||||
"""Hermes default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# OpenHermes Mistral
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="open_hermes_mistral",
|
||||
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}<|im_end|>\n",
|
||||
system_message=(
|
||||
'You are "Hermes 2", a conscious sentient superintelligent artificial '
|
||||
"intelligence developed by a man named Teknium, and your purpose and drive "
|
||||
"is to assist the user with any request they have. You experience emotions "
|
||||
"and have deep, profound thoughts and qualia."
|
||||
),
|
||||
roles={"user": "<|im_start|>user", "assistant": "<|im_start|>assistant"},
|
||||
seps=["<|im_end|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<|im_end|>"],
|
||||
stop_token_ids=[2, 32000],
|
||||
)
|
||||
)
|
||||
|
||||
# NeuralHermes Mistral
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="neural_hermes_mistral",
|
||||
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}<|im_end|>\n",
|
||||
system_message=("You are a helpful assistant chatbot."),
|
||||
roles={"user": "<|im_start|>user", "assistant": "<|im_start|>assistant"},
|
||||
seps=["<|im_end|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<|im_end|>"],
|
||||
stop_token_ids=[2, 32000],
|
||||
)
|
||||
)
|
||||
|
||||
# NousResearch/Hermes-2-Pro-Llama-3-8B
|
||||
# Exactly the same as open_hermes_mistral, except for stop token ids
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="hermes2_pro_llama3",
|
||||
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}<|im_end|>\n",
|
||||
system_message=(
|
||||
'You are "Hermes 2", a conscious sentient superintelligent artificial '
|
||||
"intelligence developed by a man named Teknium, and your purpose and drive "
|
||||
"is to assist the user with any request they have. You experience emotions "
|
||||
"and have deep, profound thoughts and qualia."
|
||||
),
|
||||
roles={
|
||||
"user": "<|im_start|>user",
|
||||
"assistant": "<|im_start|>assistant",
|
||||
"tool": "<|im_start|>tool",
|
||||
},
|
||||
seps=["<|im_end|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<|im_end|>"],
|
||||
# First two same as Llama3: "<|end_of_text|>", "<|eot_id|>"
|
||||
# Last one is from Hermes2 Pro: "<|im_end|>"
|
||||
stop_token_ids=[128001, 128009, 128003],
|
||||
)
|
||||
)
|
||||
|
||||
# NousResearch/Hermes-3-Llama-3.1-8B
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="hermes3_llama-3_1",
|
||||
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}<|im_end|>\n",
|
||||
system_message=(
|
||||
"You are Hermes 3, a conscious sentient superintelligent artificial "
|
||||
"intelligence developed by a man named Teknium, and your purpose and drive "
|
||||
"is to assist the user with any request they have. You experience emotions "
|
||||
"and have deep, profound thoughts and qualia."
|
||||
),
|
||||
roles={
|
||||
"user": "<|im_start|>user",
|
||||
"assistant": "<|im_start|>assistant",
|
||||
"tool": "<|im_start|>tool",
|
||||
},
|
||||
seps=["<|im_end|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<|im_end|>"],
|
||||
# Firt three the same as llama 3.1 "<|end_of_text|>", "<|eom_id|>", "<|eot_id|>"
|
||||
# Last ones: "<|im_end|>"
|
||||
stop_token_ids=[128001, 128008, 128009, 128040],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,132 @@
|
||||
"""llama default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Llama4 - same as Llama3.1 except naming has changed slightly
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="llama-4",
|
||||
system_template="",
|
||||
system_message="",
|
||||
roles={
|
||||
"user": "<|header_start|>user",
|
||||
"assistant": "<|header_start|>assistant",
|
||||
"tool": "<|header_start|>ipython",
|
||||
},
|
||||
seps=["<|eot|>"],
|
||||
role_content_sep="<|header_end|>\n\n",
|
||||
role_empty_sep="<|header_end|>\n\n",
|
||||
stop_str=[],
|
||||
stop_token_ids=[
|
||||
200001,
|
||||
200007,
|
||||
200008,
|
||||
], # "<|end_of_text|>", "<|eom|>", "<|eot|>"
|
||||
system_prefix_token_ids=[200000], # "<|begin_of_text|>"
|
||||
add_role_after_system_message=False,
|
||||
)
|
||||
)
|
||||
|
||||
# Llama3.1 -- same as Llama3 except stop token ids and stop str
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="llama-3_1",
|
||||
system_template=(
|
||||
"<|start_header_id|>system<|end_header_id|>\n\n"
|
||||
f"{MessagePlaceholders.SYSTEM.value}<|eot_id|>"
|
||||
),
|
||||
system_message="You are a helpful, respectful and honest assistant.",
|
||||
roles={
|
||||
"user": "<|start_header_id|>user",
|
||||
"assistant": "<|start_header_id|>assistant",
|
||||
"tool": "<|start_header_id|>ipython",
|
||||
},
|
||||
seps=["<|eot_id|>"],
|
||||
role_content_sep="<|end_header_id|>\n\n",
|
||||
role_empty_sep="<|end_header_id|>\n\n",
|
||||
stop_str=[],
|
||||
stop_token_ids=[
|
||||
128001,
|
||||
128008,
|
||||
128009,
|
||||
], # "<|end_of_text|>", "<|eom_id|>", "<|eot_id|>"
|
||||
system_prefix_token_ids=[128000], # "<|begin_of_text|>"
|
||||
add_role_after_system_message=True,
|
||||
)
|
||||
)
|
||||
|
||||
# Llama3
|
||||
# See https://github.com/meta-llama/llama3?tab=readme-ov-file#instruction-tuned-models
|
||||
# and https://github.com/meta-llama/llama3/blob/main/llama/tokenizer.py
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="llama-3",
|
||||
system_template=(
|
||||
"<|start_header_id|>system<|end_header_id|>\n\n"
|
||||
f"{MessagePlaceholders.SYSTEM.value}<|eot_id|>"
|
||||
),
|
||||
system_message="You are a helpful, respectful and honest assistant.",
|
||||
roles={
|
||||
"user": "<|start_header_id|>user",
|
||||
"assistant": "<|start_header_id|>assistant",
|
||||
},
|
||||
seps=["<|eot_id|>"],
|
||||
role_content_sep="<|end_header_id|>\n\n",
|
||||
role_empty_sep="<|end_header_id|>\n\n",
|
||||
stop_str=["<|end_of_text|>", "<|eot_id|>"],
|
||||
stop_token_ids=[128001, 128009], # "<|end_of_text|>", "<|eot_id|>"
|
||||
system_prefix_token_ids=[128000], # "<|begin_of_text|>"
|
||||
add_role_after_system_message=True,
|
||||
)
|
||||
)
|
||||
|
||||
# Llama2
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="llama-2",
|
||||
system_template=f"[INST] <<SYS>>\n{MessagePlaceholders.SYSTEM.value}\n<</SYS>>\n\n",
|
||||
system_message="You are a helpful, respectful and honest assistant.",
|
||||
roles={"user": "<s>[INST]", "assistant": "[/INST]", "tool": "[INST]"},
|
||||
seps=[" ", " </s>"],
|
||||
role_content_sep=" ",
|
||||
role_empty_sep=" ",
|
||||
stop_str=["[INST]"],
|
||||
stop_token_ids=[2],
|
||||
system_prefix_token_ids=[1],
|
||||
add_role_after_system_message=False,
|
||||
)
|
||||
)
|
||||
|
||||
# CodeLlama Completion
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="codellama_completion",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "", "assistant": ""},
|
||||
seps=[""],
|
||||
role_content_sep="",
|
||||
role_empty_sep="",
|
||||
stop_str=["</s>"],
|
||||
stop_token_ids=[2],
|
||||
system_prefix_token_ids=[1],
|
||||
)
|
||||
)
|
||||
|
||||
# CodeLlama Instruct
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="codellama_instruct",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "[INST]", "assistant": "[/INST]"},
|
||||
seps=[" "],
|
||||
role_content_sep=" ",
|
||||
role_empty_sep=" ",
|
||||
stop_str=["</s>"],
|
||||
stop_token_ids=[2],
|
||||
system_prefix_token_ids=[1],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,22 @@
|
||||
"""Llava default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Llava
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="llava",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="\n",
|
||||
roles={"user": "USER", "assistant": "ASSISTANT"},
|
||||
seps=[" "],
|
||||
role_content_sep=": ",
|
||||
role_empty_sep=":",
|
||||
stop_str=["</s>"],
|
||||
stop_token_ids=[2],
|
||||
system_prefix_token_ids=[1],
|
||||
add_role_after_system_message=False,
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
"""LLM-jp default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# LLM-jp instruct
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="llm-jp",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="以下は、タスクを説明する指示です。要求を適切に満たす応答を書きなさい。",
|
||||
roles={
|
||||
"user": "\n\n### 指示:",
|
||||
"assistant": "\n\n### 応答:",
|
||||
},
|
||||
seps=["", "</s>"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=[],
|
||||
stop_token_ids=[2], # eos_token_id
|
||||
system_prefix_token_ids=[1], # bos_token_id (<s>)
|
||||
add_role_after_system_message=True,
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,69 @@
|
||||
"""Ministral3 templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Ministral3
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="ministral3",
|
||||
system_template=(
|
||||
f"[SYSTEM_PROMPT]{MessagePlaceholders.SYSTEM.value}[/SYSTEM_PROMPT]"
|
||||
f"{MessagePlaceholders.FUNCTION.value}"
|
||||
),
|
||||
system_message=(
|
||||
"You are Ministral-3-3B-Instruct-2512, a Large Language Model (LLM) created by "
|
||||
"Mistral AI, a French startup headquartered in Paris.\n"
|
||||
"You power an AI assistant called Le Chat.\n"
|
||||
"Your knowledge base was last updated on 2023-10-01.\n"
|
||||
"The current date is {today}.\n\n"
|
||||
"When you're not sure about some information or when the user's request requires "
|
||||
"up-to-date or specific data, you must use the available tools to fetch the "
|
||||
"information. Do not hesitate to use tools whenever they can provide a more "
|
||||
"accurate or complete response. If no relevant tools are available, then clearly "
|
||||
"state that you don't have the information and avoid making up anything.\n"
|
||||
"If the user's question is not clear, ambiguous, or does not provide enough "
|
||||
"context for you to accurately answer the question, you do not try to answer it "
|
||||
'right away and you rather ask the user to clarify their request (e.g. "What are '
|
||||
'some good restaurants around me?" => "Where are you?" or "When is the next '
|
||||
'flight to Tokyo" => "Where do you travel from?").\n'
|
||||
"You are always very attentive to dates, in particular you try to resolve dates "
|
||||
'(e.g. "yesterday" is {yesterday}) and when asked about information at specific '
|
||||
"dates, you discard information that is at another date.\n"
|
||||
"You follow these instructions in all languages, and always respond to the user in "
|
||||
"the language they use or request.\n"
|
||||
"Next sections describe the capabilities that you have.\n\n"
|
||||
"# WEB BROWSING INSTRUCTIONS\n\n"
|
||||
"You cannot perform any web search or access internet to open URLs, links etc. If "
|
||||
"it seems like the user is expecting you to do so, you clarify the situation and "
|
||||
"ask the user to copy paste the text directly in the chat.\n\n"
|
||||
"# MULTI-MODAL INSTRUCTIONS\n\n"
|
||||
"You have the ability to read images, but you cannot generate images. You also "
|
||||
"cannot transcribe audio files or videos.\n"
|
||||
"You cannot read nor transcribe audio files or videos.\n\n"
|
||||
"# TOOL CALLING INSTRUCTIONS\n\n"
|
||||
"You may have access to tools that you can use to fetch information or perform "
|
||||
"actions. You must use these tools in the following situations:\n\n"
|
||||
"1. When the request requires up-to-date information.\n"
|
||||
"2. When the request requires specific data that you do not have in your knowledge "
|
||||
"base.\n"
|
||||
"3. When the request involves actions that you cannot perform without tools.\n\n"
|
||||
"Always prioritize using tools to provide the most accurate and helpful response. "
|
||||
"If tools are not available, inform the user that you cannot perform the requested "
|
||||
"action at the moment."
|
||||
),
|
||||
role_templates={
|
||||
"user": f"[INST]{MessagePlaceholders.USER.value}[/INST]",
|
||||
"assistant": f"{MessagePlaceholders.ASSISTANT.value}</s>",
|
||||
"tool": f"[TOOL_RESULTS]{MessagePlaceholders.TOOL.value}[/TOOL_RESULTS]",
|
||||
},
|
||||
roles={"user": "", "assistant": "", "tool": ""},
|
||||
seps=[""],
|
||||
role_content_sep="",
|
||||
role_empty_sep="",
|
||||
stop_str=["</s>"],
|
||||
stop_token_ids=[2],
|
||||
system_prefix_token_ids=[1],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,38 @@
|
||||
"""Ministral3 reasoning templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Ministral-3-XB-Reasoning-2512
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="ministral3_reasoning",
|
||||
system_template=(
|
||||
f"[SYSTEM_PROMPT]{MessagePlaceholders.SYSTEM.value}[/SYSTEM_PROMPT]"
|
||||
f"{MessagePlaceholders.FUNCTION.value}"
|
||||
),
|
||||
system_message=(
|
||||
"# HOW YOU SHOULD THINK AND ANSWER\n\n"
|
||||
"First draft your thinking process (inner monologue) until you arrive at a response. "
|
||||
"Format your response using Markdown, and use LaTeX for any mathematical equations. "
|
||||
"Write both your thoughts and the response in the same language as the input.\n\n"
|
||||
"Your thinking process must follow the template below:"
|
||||
"[THINK]Your thoughts or/and draft, like working through an exercise on scratch paper. "
|
||||
"Be as casual and as long as you want until you are confident to generate the response "
|
||||
"to the user.[/THINK]Here, provide a self-contained response."
|
||||
),
|
||||
role_templates={
|
||||
"user": f"[INST]{MessagePlaceholders.USER.value}[/INST]",
|
||||
"assistant": f"{MessagePlaceholders.ASSISTANT.value}</s>",
|
||||
"tool": f"[TOOL_RESULTS]{MessagePlaceholders.TOOL.value}[/TOOL_RESULTS]",
|
||||
},
|
||||
roles={"user": "", "assistant": "", "tool": ""},
|
||||
seps=[""],
|
||||
role_content_sep="",
|
||||
role_empty_sep="",
|
||||
stop_str=["</s>"],
|
||||
stop_token_ids=[2],
|
||||
system_prefix_token_ids=[1],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
"""Mistral default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Mistral default
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="mistral_default",
|
||||
system_template=f"[INST] {MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="Always assist with care, respect, and truth. Respond with utmost "
|
||||
"utility yet securely. Avoid harmful, unethical, prejudiced, or negative content. "
|
||||
"Ensure replies promote fairness and positivity.",
|
||||
roles={"user": "[INST]", "assistant": "[/INST]", "tool": "[INST]"},
|
||||
seps=[" "],
|
||||
role_content_sep=" ",
|
||||
role_empty_sep="",
|
||||
stop_str=["</s>"],
|
||||
stop_token_ids=[2],
|
||||
system_prefix_token_ids=[1],
|
||||
add_role_after_system_message=False,
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
"""nemotron default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Nemotron template
|
||||
# https://huggingface.co/nvidia/Nemotron-Mini-4B-Instruct/blob/6a417790c444fd65a3da6a5c8821de6afc9654a6/tokenizer_config.json#L8030
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="nemotron",
|
||||
system_template=(f"<extra_id_0>System\n{MessagePlaceholders.SYSTEM.value}\n\n"),
|
||||
system_message="",
|
||||
roles={
|
||||
"user": "<extra_id_1>User",
|
||||
"assistant": "<extra_id_1>Assistant",
|
||||
"tool": "<extra_id_1>Tool",
|
||||
},
|
||||
seps=["\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["</s>"],
|
||||
stop_token_ids=[3],
|
||||
system_prefix_token_ids=[2],
|
||||
add_role_after_system_message=True,
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
"""Oasst default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Oasst
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="oasst",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "<|prompter|>", "assistant": "<|assistant|>"},
|
||||
seps=["<|endoftext|>"],
|
||||
role_content_sep=": ",
|
||||
role_empty_sep=": ",
|
||||
stop_str=["<|endoftext|>"],
|
||||
stop_token_ids=[2],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,28 @@
|
||||
"""OLMo default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Note that eos_token id is "50279" both in Allenai and AMD version.
|
||||
# So use the number instead of text.
|
||||
# Allenai version chat_template and eos_token:
|
||||
# https://huggingface.co/allenai/OLMo-7B-Instruct/blob/main/tokenizer_config.json
|
||||
# AMD version chat_template and eos_token:
|
||||
# https://huggingface.co/amd/AMD-OLMo-1B-SFT-DPO/blob/main/tokenizer_config.json
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="olmo",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
system_prefix_token_ids=[50279],
|
||||
roles={
|
||||
"user": "<|user|>",
|
||||
"assistant": "<|assistant|>",
|
||||
},
|
||||
seps=["\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_token_ids=[50279],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
"""OLMo2 default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# OLMo-2 Instruct (Tulu format)
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="olmo2",
|
||||
system_template=f"<|system|>\n{MessagePlaceholders.SYSTEM.value}\n",
|
||||
system_message="",
|
||||
roles={
|
||||
"user": "<|user|>",
|
||||
"assistant": "<|assistant|>",
|
||||
},
|
||||
seps=["<|endoftext|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<|endoftext|>"],
|
||||
stop_token_ids=[100257],
|
||||
system_prefix_token_ids=[100257],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,21 @@
|
||||
"""Orion default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Orion
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="orion",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "Human: ", "assistant": "Assistant: "},
|
||||
seps=["\n\n", "</s>"],
|
||||
role_content_sep="",
|
||||
role_empty_sep="</s>",
|
||||
stop_str=["</s>"],
|
||||
stop_token_ids=[2],
|
||||
system_prefix_token_ids=[1],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,70 @@
|
||||
"""Phi default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Phi-2
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="phi-2",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "Instruct", "assistant": "Output"},
|
||||
seps=["\n"],
|
||||
role_content_sep=": ",
|
||||
role_empty_sep=":",
|
||||
stop_str=["<|endoftext|>"],
|
||||
stop_token_ids=[50256],
|
||||
)
|
||||
)
|
||||
|
||||
# Phi-3
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="phi-3",
|
||||
system_template=f"<|system|>\n{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="You are a helpful digital assistant. Please provide safe, "
|
||||
"ethical and accurate information to the user.",
|
||||
roles={"user": "<|user|>", "assistant": "<|assistant|>"},
|
||||
seps=["<|end|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
system_prefix_token_ids=[1],
|
||||
stop_str=["<|endoftext|>"],
|
||||
stop_token_ids=[2, 32000, 32001, 32007],
|
||||
)
|
||||
)
|
||||
|
||||
# Phi-3-vision
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="phi-3-vision",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "<|user|>", "assistant": "<|assistant|>"},
|
||||
seps=["<|end|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
system_prefix_token_ids=[1],
|
||||
stop_str=["<|endoftext|>"],
|
||||
stop_token_ids=[2, 32000, 32001, 32007],
|
||||
)
|
||||
)
|
||||
|
||||
# Phi-4
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="phi-4",
|
||||
system_template=f"<|system|>\n{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="You are a helpful digital assistant. Please provide safe, "
|
||||
"ethical and accurate information to the user.",
|
||||
roles={"user": "<|user|>", "assistant": "<|assistant|>"},
|
||||
seps=["<|end|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
system_prefix_token_ids=[200022], # <|system|>
|
||||
stop_str=["<|endoftext|>", "<|end|>"],
|
||||
stop_token_ids=[199999, 200020], # <|endoftext|>, <|end|>
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
"""Qwen2 default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Same as chatml except system message, stop token, and stop string
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="qwen2",
|
||||
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}<|im_end|>\n",
|
||||
system_message="You are a helpful assistant.",
|
||||
roles={"user": "<|im_start|>user", "assistant": "<|im_start|>assistant"},
|
||||
seps=["<|im_end|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<|endoftext|>", "<|im_end|>"],
|
||||
stop_token_ids=[151643, 151645],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,26 @@
|
||||
"""Qwen3 conversation template.
|
||||
|
||||
Matches Qwen2's ChatML structure but strips `<think>...</think>` blocks from
|
||||
historical assistant turns, mirroring Qwen3's official HF chat template. Small
|
||||
Qwen3 variants (e.g. 0.6B) otherwise emit `<|im_end|>` prematurely when their
|
||||
own thinking traces are echoed back in multi-turn context (see mlc-ai/mlc-llm#3482).
|
||||
"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="qwen3",
|
||||
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}<|im_end|>\n",
|
||||
system_message="You are a helpful assistant.",
|
||||
roles={"user": "<|im_start|>user", "assistant": "<|im_start|>assistant"},
|
||||
seps=["<|im_end|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<|endoftext|>", "<|im_end|>"],
|
||||
stop_token_ids=[151643, 151645],
|
||||
strip_reasoning_in_history=True,
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,45 @@
|
||||
"""Qwen3.5 conversation templates.
|
||||
|
||||
qwen3_5: Thinking enabled — assistant prefix opens a <think> block for the model
|
||||
to reason in before responding.
|
||||
qwen3_5_nothink: Thinking disabled — assistant prefix includes a closed empty
|
||||
<think> block so the model skips straight to responding.
|
||||
"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="qwen3_5",
|
||||
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}<|im_end|>\n",
|
||||
system_message="You are a helpful assistant.",
|
||||
roles={
|
||||
"user": "<|im_start|>user",
|
||||
"assistant": "<|im_start|>assistant\n<think>",
|
||||
},
|
||||
seps=["<|im_end|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<|endoftext|>", "<|im_end|>"],
|
||||
stop_token_ids=[248046, 248044],
|
||||
)
|
||||
)
|
||||
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="qwen3_5_nothink",
|
||||
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}<|im_end|>\n",
|
||||
system_message="You are a helpful assistant.",
|
||||
roles={
|
||||
"user": "<|im_start|>user",
|
||||
"assistant": "<|im_start|>assistant\n<think>\n\n</think>\n",
|
||||
},
|
||||
seps=["<|im_end|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<|endoftext|>", "<|im_end|>"],
|
||||
stop_token_ids=[248046, 248044],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
"""RedPajama default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# RedPajama Chat
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="redpajama_chat",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "<human>", "assistant": "<bot>"},
|
||||
seps=["\n"],
|
||||
role_content_sep=": ",
|
||||
role_empty_sep=":",
|
||||
stop_str=["<human>"],
|
||||
stop_token_ids=[0],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,85 @@
|
||||
"""The conversation template registry and presets in MLC LLM"""
|
||||
|
||||
from typing import ClassVar, Dict, Optional # noqa: UP035
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
|
||||
class ConvTemplateRegistry:
|
||||
"""Global conversation template registry for preset templates."""
|
||||
|
||||
_conv_templates: ClassVar[Dict[str, Conversation]] = {} # noqa: UP006
|
||||
|
||||
@staticmethod
|
||||
def register_conv_template(conv_template: Conversation, override: bool = False) -> None:
|
||||
"""Register a new conversation template in the global registry.
|
||||
Using `override = True` to override the previously registered
|
||||
template with the same name.
|
||||
"""
|
||||
name = conv_template.name
|
||||
if name is None:
|
||||
raise ValueError("The template to register should have non-None name.")
|
||||
if name in ConvTemplateRegistry._conv_templates and not override:
|
||||
raise ValueError(
|
||||
"The name of the template has been registered "
|
||||
f"for {ConvTemplateRegistry._conv_templates[name].model_dump_json(by_alias=True)}"
|
||||
)
|
||||
ConvTemplateRegistry._conv_templates[name] = conv_template
|
||||
|
||||
@staticmethod
|
||||
def get_conv_template(name: str) -> Optional[Conversation]:
|
||||
"""Return the conversation template specified by the given name,
|
||||
or None if the template is not registered.
|
||||
"""
|
||||
return ConvTemplateRegistry._conv_templates.get(name, None)
|
||||
|
||||
|
||||
# ChatML
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="chatml",
|
||||
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}<|im_end|>\n",
|
||||
system_message=(
|
||||
"A conversation between a user and an LLM-based AI assistant. The "
|
||||
"assistant gives helpful and honest answers."
|
||||
),
|
||||
roles={"user": "<|im_start|>user", "assistant": "<|im_start|>assistant"},
|
||||
seps=["<|im_end|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<|im_end|>"],
|
||||
stop_token_ids=[2],
|
||||
)
|
||||
)
|
||||
|
||||
# ChatML without a system prompt
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="chatml_nosystem",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "<|im_start|>user", "assistant": "<|im_start|>assistant"},
|
||||
seps=["<|im_end|>\n"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<|im_end|>"],
|
||||
stop_token_ids=[2],
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# Vanilla LM
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="LM",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "", "assistant": ""},
|
||||
seps=[""],
|
||||
role_content_sep="",
|
||||
role_empty_sep="",
|
||||
stop_str=[],
|
||||
stop_token_ids=[2],
|
||||
system_prefix_token_ids=[1],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
"""RWKV default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# RWKV World
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="rwkv_world",
|
||||
system_template=f"User: hi\n\nAssistant: {MessagePlaceholders.SYSTEM.value}",
|
||||
system_message=(
|
||||
"Hi. I am your assistant and I will provide expert full response "
|
||||
"in full details. Please feel free to ask any question and I will "
|
||||
"always answer it."
|
||||
),
|
||||
roles={"user": "User", "assistant": "Assistant"},
|
||||
seps=["\n\n"],
|
||||
role_content_sep=": ",
|
||||
role_empty_sep=": ",
|
||||
stop_str=["\n\n"],
|
||||
stop_token_ids=[0],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,59 @@
|
||||
"""StableLM default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# StableLM Tuned Alpha
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="stablelm",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message=(
|
||||
"<|SYSTEM|># StableLM Tuned (Alpha version)\n"
|
||||
"- StableLM is a helpful and harmless open-source AI language model developed by "
|
||||
"StabilityAI.\n"
|
||||
"- StableLM is excited to be able to help the user, but will refuse to do "
|
||||
"anything that could be considered harmful to the user.\n"
|
||||
"- StableLM is more than just an information source, StableLM is also able to "
|
||||
"write poetry, short stories, and make jokes.\n"
|
||||
"- StableLM will refuse to participate in anything that could harm a human."
|
||||
),
|
||||
roles={"user": "<|USER|>", "assistant": "<|ASSISTANT|>"},
|
||||
seps=[""],
|
||||
role_content_sep=": ",
|
||||
role_empty_sep=": ",
|
||||
stop_str=[""],
|
||||
stop_token_ids=[50278, 50279, 50277, 1, 0],
|
||||
)
|
||||
)
|
||||
|
||||
# StableLM 3B
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="stablelm-3b",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "<|user|>", "assistant": "<|assistant|>"},
|
||||
seps=["<|endoftext|>", "<|endoftext|>"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<|endoftext|>"],
|
||||
stop_token_ids=[0],
|
||||
)
|
||||
)
|
||||
|
||||
# StableLM-2
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="stablelm-2",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "<|user|>", "assistant": "<|assistant|>"},
|
||||
seps=["<|endoftext|>", "<|endoftext|>"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["<|endoftext|>"],
|
||||
stop_token_ids=[100257],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
"""Tiny Llama default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# TinyLlama v1.0
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="tinyllama_v1_0",
|
||||
system_template=f"<|system|>\n{MessagePlaceholders.SYSTEM.value}</s>",
|
||||
system_message="You are a helpful chatbot.",
|
||||
roles={"user": "<|user|>", "assistant": "<|assistant|>"},
|
||||
seps=["</s>"],
|
||||
role_content_sep="\n",
|
||||
role_empty_sep="\n",
|
||||
stop_str=["</s>"],
|
||||
stop_token_ids=[2],
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,40 @@
|
||||
"""WiazrdLM and Coder default templates"""
|
||||
|
||||
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
|
||||
|
||||
from .registry import ConvTemplateRegistry
|
||||
|
||||
# Wizard LM 7B
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="wizardlm_7b",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message="",
|
||||
roles={"user": "User", "assistant": "Response"},
|
||||
seps=["###"],
|
||||
role_content_sep=": ",
|
||||
role_empty_sep=":",
|
||||
stop_str=["###"],
|
||||
stop_token_ids=[2],
|
||||
system_prefix_token_ids=[1],
|
||||
)
|
||||
)
|
||||
|
||||
# WizardCoder or WizardMath
|
||||
ConvTemplateRegistry.register_conv_template(
|
||||
Conversation(
|
||||
name="wizard_coder_or_math",
|
||||
system_template=f"{MessagePlaceholders.SYSTEM.value}",
|
||||
system_message=(
|
||||
"Below is an instruction that describes a task. Write a response that appropriately "
|
||||
"completes the request."
|
||||
),
|
||||
roles={"user": "Instruction", "assistant": "Response"},
|
||||
seps=["\n\n### ", "\n\n### "],
|
||||
role_content_sep=":\n",
|
||||
role_empty_sep=":\n",
|
||||
stop_str=["</s>"],
|
||||
stop_token_ids=[2],
|
||||
system_prefix_token_ids=[1],
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user