Skip to content

Commit

Permalink
Revert "Improve Support for Mistral-Instruct (#2547)"
Browse files Browse the repository at this point in the history
This reverts commit f5a4911.
  • Loading branch information
merrymercy authored Oct 12, 2023
1 parent f683fd1 commit 7214f93
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
31 changes: 7 additions & 24 deletions fastchat/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class SeparatorStyle(IntEnum):
PHOENIX = auto()
ROBIN = auto()
FALCON_CHAT = auto()
MISTRAL_INSTRUCT = auto()


@dataclasses.dataclass
Expand Down Expand Up @@ -213,17 +212,6 @@ def get_prompt(self) -> str:
ret += role + ":"

return ret
elif self.sep_style == SeparatorStyle.MISTRAL_INSTRUCT:
ret = self.sep
for i, (role, message) in enumerate(self.messages):
if role == "user":
if self.system_message and i == 0:
ret += "[INST] " + system_prompt + " " + message + " [/INST]"
else:
ret += "[INST] " + message + " [/INST]"
elif role == "assistant" and message:
ret += message + self.sep2 + " "
return ret
else:
raise ValueError(f"Invalid style: {self.sep_style}")

Expand Down Expand Up @@ -852,21 +840,16 @@ def get_conv_template(name: str) -> Conversation:
)
)

# Mistral instruct template
# Mistral template
# source: https://docs.mistral.ai/llm/mistral-instruct-v0.1#chat-template
# https://docs.mistral.ai/usage/guardrailing/
# https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1/blob/main/tokenizer_config.json
register_conv_template(
Conversation(
name="mistral-instruct",
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", "assistant"),
sep_style=SeparatorStyle.MISTRAL_INSTRUCT,
sep="<s>",
sep2="</s>",
name="mistral",
system_template="",
roles=("[INST] ", " [/INST]"),
sep_style=SeparatorStyle.LLAMA2,
sep="",
sep2=" </s>",
)
)

Expand Down
10 changes: 5 additions & 5 deletions fastchat/model/model_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1283,11 +1283,11 @@ def get_default_conv_template(self, model_path: str) -> Conversation:
return get_conv_template("starchat")


class MistralInstructAdapter(BaseModelAdapter):
"""The model adapter for Mistral Instruct AI models"""
class MistralAdapter(BaseModelAdapter):
"""The model adapter for Mistral AI models"""

def match(self, model_path: str):
return "mistral" in model_path.lower() and "instruct" in model_path.lower()
return "mistral" in model_path.lower()

def load_model(self, model_path: str, from_pretrained_kwargs: dict):
model, tokenizer = super().load_model(model_path, from_pretrained_kwargs)
Expand All @@ -1296,7 +1296,7 @@ def load_model(self, model_path: str, from_pretrained_kwargs: dict):
return model, tokenizer

def get_default_conv_template(self, model_path: str) -> Conversation:
return get_conv_template("mistral-instruct")
return get_conv_template("mistral")


class Llama2Adapter(BaseModelAdapter):
Expand Down Expand Up @@ -1716,7 +1716,7 @@ def get_default_conv_template(self, model_path: str) -> Conversation:
register_model_adapter(InternLMChatAdapter)
register_model_adapter(StarChatAdapter)
register_model_adapter(Llama2Adapter)
register_model_adapter(MistralInstructAdapter)
register_model_adapter(MistralAdapter)
register_model_adapter(CuteGPTAdapter)
register_model_adapter(OpenOrcaAdapter)
register_model_adapter(WizardCoderAdapter)
Expand Down
2 changes: 1 addition & 1 deletion fastchat/model/model_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def get_model_info(name: str) -> ModelInfo:
)
register_model_info(
["mistral-7b-instruct"],
"Mistral-Instruct",
"Mistral",
"https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1",
"a large language model by Mistral AI team",
)
Expand Down

0 comments on commit 7214f93

Please sign in to comment.