Skip to content

Commit 1f21efb

Browse files
authored
Add Yi support (#2723)
1 parent 6ac7d76 commit 1f21efb

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

fastchat/conversation.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,23 @@ def get_conv_template(name: str) -> Conversation:
10211021
)
10221022
)
10231023

1024+
# source: https://huggingface.co/01-ai/Yi-34B-Chat/blob/main/tokenizer_config.json#L60
1025+
register_conv_template(
1026+
Conversation(
1027+
name="Yi-34b-chat",
1028+
roles=("<|im_start|>user", "<|im_start|>assistant"),
1029+
sep_style=SeparatorStyle.CHATML,
1030+
sep="<|im_end|>",
1031+
stop_token_ids=[
1032+
2,
1033+
6,
1034+
7,
1035+
8,
1036+
], # "<|endoftext|>", "<|im_start|>", "<|im_end|>", "<|im_sep|>"
1037+
stop_str="<|endoftext|>",
1038+
)
1039+
)
1040+
10241041

10251042
# AquilaChat default template
10261043
# source: https://github.com/FlagAI-Open/FlagAI/blob/master/examples/Aquila/Aquila-chat/cyg_conversation.py

fastchat/model/model_adapter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,16 @@ def get_default_conv_template(self, model_path: str) -> Conversation:
18851885
return get_conv_template("orca-2")
18861886

18871887

1888+
class YiAdapter(BaseModelAdapter):
1889+
"""The model adapter for Yi models"""
1890+
1891+
def match(self, model_path: str):
1892+
return "yi-34b-chat" in model_path.lower()
1893+
1894+
def get_default_conv_template(self, model_path: str) -> Conversation:
1895+
return get_conv_template("Yi-34b-chat")
1896+
1897+
18881898
# Note: the registration order matters.
18891899
# The one registered earlier has a higher matching priority.
18901900
register_model_adapter(PeftModelAdapter)
@@ -1954,6 +1964,7 @@ def get_default_conv_template(self, model_path: str) -> Conversation:
19541964
register_model_adapter(LemurAdapter)
19551965
register_model_adapter(PygmalionAdapter)
19561966
register_model_adapter(MicrosoftOrcaAdapter)
1967+
register_model_adapter(YiAdapter)
19571968

19581969
# After all adapters, try the default base adapter.
19591970
register_model_adapter(BaseModelAdapter)

fastchat/model/model_registry.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,10 @@ def get_model_info(name: str) -> ModelInfo:
397397
"https://huggingface.co/BAAI/AquilaChat2-34B",
398398
"Chat models developed by BAAI team",
399399
)
400+
401+
register_model_info(
402+
["Yi-34B-Chat"],
403+
"Yi-Chat",
404+
"https://huggingface.co/01-ai",
405+
"A large language model by 01.AI.",
406+
)

fastchat/serve/vllm_worker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ async def generate_stream(self, params):
101101
top_p=top_p,
102102
use_beam_search=use_beam_search,
103103
stop=list(stop),
104+
stop_token_ids=stop_token_ids,
104105
max_tokens=max_new_tokens,
105106
top_k=top_k,
106107
presence_penalty=presence_penalty,

0 commit comments

Comments
 (0)