diff --git a/docs/model_support.md b/docs/model_support.md index 25bc3d6e6..969311bee 100644 --- a/docs/model_support.md +++ b/docs/model_support.md @@ -56,6 +56,7 @@ - [Microsoft/Orca-2-7b](https://huggingface.co/microsoft/Orca-2-7b) - [deepseek-ai/deepseek-llm-67b-chat](https://huggingface.co/deepseek-ai/deepseek-llm-67b-chat) - [deepseek-ai/deepseek-coder-33b-instruct](https://huggingface.co/deepseek-ai/deepseek-coder-33b-instruct) +- [meta-math/MetaMath-7B-V1.0](https://huggingface.co/meta-math/MetaMath-7B-V1.0) - Any [EleutherAI](https://huggingface.co/EleutherAI) pythia model such as [pythia-6.9b](https://huggingface.co/EleutherAI/pythia-6.9b) - Any [Peft](https://github.com/huggingface/peft) adapter trained on top of a model above. To activate, must have `peft` in the model path. Note: If diff --git a/fastchat/conversation.py b/fastchat/conversation.py index b6ff0d93d..43c561bfb 100644 --- a/fastchat/conversation.py +++ b/fastchat/conversation.py @@ -30,6 +30,7 @@ class SeparatorStyle(IntEnum): FALCON_CHAT = auto() CHATGLM3 = auto() DEEPSEEK_CHAT = auto() + METAMATH = auto() @dataclasses.dataclass @@ -223,7 +224,17 @@ def get_prompt(self) -> str: ret += role + ": " + message + self.sep else: ret += role + ":" - + return ret + elif self.sep_style == SeparatorStyle.METAMATH: + ret = "" if system_prompt == "" else system_prompt + self.sep + for i, (role, message) in enumerate(self.messages): + # For MetaMath, sep2 is used to prefix the message. + starting_sep = ":\n" if i % 2 == 0 else ": " + self.sep2 + ending_sep = self.sep if i % 2 == 0 else "" + if message: + ret += role + starting_sep + message + ending_sep + else: + ret += role + starting_sep return ret elif self.sep_style == SeparatorStyle.DEEPSEEK_CHAT: seps = [self.sep, self.sep2] @@ -678,6 +689,20 @@ def get_conv_template(name: str) -> Conversation: ) ) +# MetaMath default template +# reference: https://github.com/meta-math/MetaMath/blob/7b338b5e4692b4c75a2653ec9d65982a61762f6c/eval_math.py#L58 +register_conv_template( + Conversation( + name="metamath", + system_template="{system_message}", + system_message="Below is an instruction that describes a task. Write a response that appropriately completes the request.", + roles=("### Instruction", "### Response"), + sep_style=SeparatorStyle.METAMATH, + sep="\n\n", + sep2="Let's think step by step.", + ) +) + # MPT default template register_conv_template( Conversation( diff --git a/fastchat/model/model_adapter.py b/fastchat/model/model_adapter.py index 3a98e6ff9..ce56330d4 100644 --- a/fastchat/model/model_adapter.py +++ b/fastchat/model/model_adapter.py @@ -1959,6 +1959,16 @@ def get_default_conv_template(self, model_path: str) -> Conversation: return get_conv_template("deepseek-chat") +class MetaMathAdapter(BaseModelAdapter): + """The model adapter for MetaMath models""" + + def match(self, model_path: str): + return "metamath" in model_path.lower() + + def get_default_conv_template(self, model_path: str) -> Conversation: + return get_conv_template("metamath") + + # Note: the registration order matters. # The one registered earlier has a higher matching priority. register_model_adapter(PeftModelAdapter) @@ -2032,6 +2042,7 @@ def get_default_conv_template(self, model_path: str) -> Conversation: register_model_adapter(YiAdapter) register_model_adapter(DeepseekCoderAdapter) register_model_adapter(DeepseekChatAdapter) +register_model_adapter(MetaMathAdapter) # After all adapters, try the default base adapter. register_model_adapter(BaseModelAdapter) diff --git a/fastchat/model/model_registry.py b/fastchat/model/model_registry.py index 319eda8e8..6e812eb81 100644 --- a/fastchat/model/model_registry.py +++ b/fastchat/model/model_registry.py @@ -421,3 +421,10 @@ def get_model_info(name: str) -> ModelInfo: "https://huggingface.co/BAAI/AquilaChat2-34B", "Chat models developed by BAAI team", ) + +register_model_info( + ["MetaMath-70B-V1.0", "MetaMath-7B-V1.0"], + "MetaMath", + "https://huggingface.co/meta-math", + "MetaMath is a finetune of Llama2 on [MetaMathQA](https://huggingface.co/datasets/meta-math/MetaMathQA) that specializes in mathematical reasoning.", +) \ No newline at end of file