Skip to content

Commit

Permalink
Add support for Vigogne models (#2236)
Browse files Browse the repository at this point in the history
  • Loading branch information
bofenghuang authored Aug 16, 2023
1 parent 5b245e8 commit d9c3970
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/model_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
- [Qwen/Qwen-7B-Chat](https://huggingface.co/Qwen/Qwen-7B-Chat)
- [BAAI/AquilaChat-7B](https://huggingface.co/BAAI/AquilaChat-7B)
- [HuggingFaceH4/starchat-beta](https://huggingface.co/HuggingFaceH4/starchat-beta)
- [bofenghuang/vigogne-2-7b-instruct](https://huggingface.co/bofenghuang/vigogne-2-7b-instruct)
- [bofenghuang/vigogne-2-7b-chat](https://huggingface.co/bofenghuang/vigogne-2-7b-chat)
- 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
Expand Down
18 changes: 18 additions & 0 deletions fastchat/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,24 @@ def get_conv_template(name: str) -> Conversation:
)
)

# Vigogne Chat default template
# source: https://github.com/bofenghuang/vigogne
register_conv_template(
Conversation(
name="vigogne-chat",
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.",
roles=("<|user|>", "<|assistant|>"),
messages=(),
offset=0,
sep_style=SeparatorStyle.ADD_COLON_TWO,
sep="\n",
sep2="</s>\n",
stop_str="<|user|>",
)
)

if __name__ == "__main__":
print("Vicuna template:")
conv = get_conv_template("vicuna_v1.1")
Expand Down
58 changes: 58 additions & 0 deletions fastchat/model/model_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,62 @@ 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"""

use_fast_tokenizer = False

def match(self, model_path: str):
return "vigogne" in model_path.lower() and "instruct" 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("alpaca")


class VigogneChatAdapter(BaseModelAdapter):
"""The model adapter for Vigogne-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")


# Note: the registration order matters.
# The one registered earlier has a higher matching priority.
register_model_adapter(PeftModelAdapter)
Expand Down Expand Up @@ -1458,6 +1514,8 @@ def get_default_conv_template(self, model_path: str) -> Conversation:
register_model_adapter(AquilaChatAdapter)
register_model_adapter(BGEAdapter)
register_model_adapter(Lamma2ChineseAdapter)
register_model_adapter(VigogneInstructAdapter)
register_model_adapter(VigogneChatAdapter)

# After all adapters, try the default base adapter.
register_model_adapter(BaseModelAdapter)
12 changes: 12 additions & 0 deletions fastchat/model/model_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,15 @@ def get_model_info(name: str) -> ModelInfo:
"https://huggingface.co/FlagAlpha/Llama2-Chinese-13b-Chat",
"Llama2-Chinese is a multi-language large-scale language model (LLM), developed by FlagAlpha.",
)
register_model_info(
["Vigogne-2-7B-Instruct", "Vigogne-2-13B-Instruct"],
"Vigogne-Instruct",
"https://huggingface.co/bofenghuang/vigogne-2-7b-instruct",
"Vigogne-Instruct is a French large language model (LLM) optimized for instruction-following, developed by Bofeng Huang",
)
register_model_info(
["Vigogne-2-7B-Chat", "Vigogne-2-13B-Chat"],
"Vigogne-Chat",
"https://huggingface.co/bofenghuang/vigogne-2-7b-chat",
"Vigogne-Chat is a French large language model (LLM) optimized for instruction-following and multi-turn dialogues, developed by Bofeng Huang",
)

0 comments on commit d9c3970

Please sign in to comment.