Skip to content

Commit

Permalink
Update vigogne template (#2580)
Browse files Browse the repository at this point in the history
  • Loading branch information
bofenghuang authored Oct 18, 2023
1 parent 7fbf5b1 commit 29de51f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 38 deletions.
41 changes: 37 additions & 4 deletions fastchat/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,14 +962,32 @@ def get_conv_template(name: str) -> Conversation:
)
)

# Vigogne Chat default template
# Vigogne Instruct default template
# source: https://github.com/bofenghuang/vigogne
register_conv_template(
Conversation(
name="vigogne-chat",
name="vigogne_instruct",
system_template="### System:\n{system_message}\n\n",
system_message=(
"Ci-dessous se trouve une instruction qui décrit une tâche à accomplir. Rédigez une réponse qui répond de manière"
" précise à la demande."
),
roles=("### Instruction", "### Response"),
sep_style=SeparatorStyle.DOLLY,
sep="\n\n",
sep2="</s>",
)
)

# Vigogne Chat default template
register_conv_template(
Conversation(
name="vigogne_chat_v2",
system_template="<|system|>: {system_message}",
system_message="Vous êtes l'assistant IA nommé Vigogne, créé par Zaion Lab (https://zaion.ai). "
"Vous suivez extrêmement bien les instructions. Aidez autant que vous le pouvez.",
system_message=(
"Vous êtes Vigogne, un assistant IA créé par Zaion Lab. Vous suivez extrêmement bien les instructions. Aidez"
" autant que vous le pouvez."
),
roles=("<|user|>", "<|assistant|>"),
sep_style=SeparatorStyle.ADD_COLON_TWO,
sep="\n",
Expand All @@ -978,6 +996,21 @@ def get_conv_template(name: str) -> Conversation:
)
)

register_conv_template(
Conversation(
name="vigogne_chat_v3",
system_template="[INST] <<SYS>>\n{system_message}\n<</SYS>>\n\n",
system_message=(
"Vous êtes Vigogne, un assistant IA créé par Zaion Lab. Vous suivez extrêmement bien les instructions. Aidez"
" autant que vous le pouvez."
),
roles=("[INST]", "[/INST]"),
sep_style=SeparatorStyle.LLAMA2,
sep=" ",
sep2=" </s>",
)
)

# Falcon 180B chat template
# source: https://huggingface.co/spaces/tiiuae/falcon-180b-demo/blob/d1590ee7fae9b6ce331ba7808e61a29dcce9239f/app.py#L28-L37
register_conv_template(
Expand Down
43 changes: 9 additions & 34 deletions fastchat/model/model_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,13 +1549,13 @@ def get_default_conv_template(self, model_path: str) -> Conversation:
return get_conv_template("llama2-chinese")


class VigogneInstructAdapter(BaseModelAdapter):
"""The model adapter for Vigogne-Instruct (e.g., bofenghuang/vigogne-2-7b-instruct)"""
class VigogneAdapter(BaseModelAdapter):
"""The model adapter for vigogne (e.g., bofenghuang/vigogne-2-7b-chat)"""

use_fast_tokenizer = False

def match(self, model_path: str):
return "vigogne" in model_path.lower() and "instruct" in model_path.lower()
return bool(re.search(r"vigogne|vigostral", model_path, re.I))

def load_model(self, model_path: str, from_pretrained_kwargs: dict):
revision = from_pretrained_kwargs.get("revision", "main")
Expand All @@ -1574,35 +1574,11 @@ 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("alpaca")


class VigogneChatAdapter(BaseModelAdapter):
"""The model adapter for Vigogne-Chat (e.g., bofenghuang/vigogne-7b-chat)"""

use_fast_tokenizer = False

def match(self, model_path: str):
return "vigogne" in model_path.lower() and "chat" in model_path.lower()

def load_model(self, model_path: str, from_pretrained_kwargs: dict):
revision = from_pretrained_kwargs.get("revision", "main")
tokenizer = AutoTokenizer.from_pretrained(
model_path,
use_fast=self.use_fast_tokenizer,
trust_remote_code=True,
revision=revision,
)
model = AutoModelForCausalLM.from_pretrained(
model_path,
trust_remote_code=True,
low_cpu_mem_usage=True,
**from_pretrained_kwargs,
).eval()
return model, tokenizer

def get_default_conv_template(self, model_path: str) -> Conversation:
return get_conv_template("vigogne-chat")
if "chat" in model_path.lower():
if "vigostral" in model_path.lower():
return get_conv_template("vigogne_chat_v3")
return get_conv_template("vigogne_chat_v2")
return get_conv_template("vigogne_instruct")


class OpenLLaMaOpenInstructAdapter(BaseModelAdapter):
Expand Down Expand Up @@ -1746,8 +1722,7 @@ def get_default_conv_template(self, model_path: str) -> Conversation:
register_model_adapter(BGEAdapter)
register_model_adapter(E5Adapter)
register_model_adapter(Lamma2ChineseAdapter)
register_model_adapter(VigogneInstructAdapter)
register_model_adapter(VigogneChatAdapter)
register_model_adapter(VigogneAdapter)
register_model_adapter(OpenLLaMaOpenInstructAdapter)
register_model_adapter(ReaLMAdapter)
register_model_adapter(PhindCodeLlamaAdapter)
Expand Down

0 comments on commit 29de51f

Please sign in to comment.