feat(model): Support Yi-1.5 models (#1516)

This commit is contained in:
Fangyin Cheng 2024-05-13 13:50:21 +08:00 committed by GitHub
parent c21cc8f583
commit 81fb56a67c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 50 additions and 2 deletions

View File

@ -158,6 +158,9 @@ At present, we have introduced several key features to showcase our current capa
We offer extensive model support, including dozens of large language models (LLMs) from both open-source and API agents, such as LLaMA/LLaMA2, Baichuan, ChatGLM, Wenxin, Tongyi, Zhipu, and many more.
- News
- 🔥🔥🔥 [Yi-1.5-34B-Chat](https://huggingface.co/01-ai/Yi-1.5-34B-Chat)
- 🔥🔥🔥 [Yi-1.5-9B-Chat](https://huggingface.co/01-ai/Yi-1.5-9B-Chat)
- 🔥🔥🔥 [Yi-1.5-6B-Chat](https://huggingface.co/01-ai/Yi-1.5-6B-Chat)
- 🔥🔥🔥 [Qwen1.5-110B-Chat](https://huggingface.co/Qwen/Qwen1.5-110B-Chat)
- 🔥🔥🔥 [Qwen1.5-MoE-A2.7B-Chat](https://huggingface.co/Qwen/Qwen1.5-MoE-A2.7B-Chat)
- 🔥🔥🔥 [Meta-Llama-3-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-70B-Instruct)

View File

@ -152,6 +152,9 @@
海量模型支持包括开源、API代理等几十种大语言模型。如LLaMA/LLaMA2、Baichuan、ChatGLM、文心、通义、智谱等。当前已支持如下模型:
- 新增支持模型
- 🔥🔥🔥 [Yi-1.5-34B-Chat](https://huggingface.co/01-ai/Yi-1.5-34B-Chat)
- 🔥🔥🔥 [Yi-1.5-9B-Chat](https://huggingface.co/01-ai/Yi-1.5-9B-Chat)
- 🔥🔥🔥 [Yi-1.5-6B-Chat](https://huggingface.co/01-ai/Yi-1.5-6B-Chat)
- 🔥🔥🔥 [Qwen1.5-110B-Chat](https://huggingface.co/Qwen/Qwen1.5-110B-Chat)
- 🔥🔥🔥 [Qwen1.5-MoE-A2.7B-Chat](https://huggingface.co/Qwen/Qwen1.5-MoE-A2.7B-Chat)
- 🔥🔥🔥 [Meta-Llama-3-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-70B-Instruct)

View File

@ -174,6 +174,10 @@ LLM_MODEL_CONFIG = {
# https://huggingface.co/01-ai/Yi-34B-Chat-4bits
"yi-34b-chat-4bits": os.path.join(MODEL_PATH, "Yi-34B-Chat-4bits"),
"yi-6b-chat": os.path.join(MODEL_PATH, "Yi-6B-Chat"),
# https://huggingface.co/01-ai/Yi-1.5-6B-Chat
"yi-1.5-6b-chat": os.path.join(MODEL_PATH, "Yi-1.5-6B-Chat"),
"yi-1.5-9b-chat": os.path.join(MODEL_PATH, "Yi-1.5-9B-Chat"),
"yi-1.5-34b-chat": os.path.join(MODEL_PATH, "Yi-1.5-34B-Chat"),
# https://huggingface.co/google/gemma-7b-it
"gemma-7b-it": os.path.join(MODEL_PATH, "gemma-7b-it"),
# https://huggingface.co/google/gemma-2b-it

View File

@ -524,11 +524,11 @@ def get_model_adapter(
"""
adapter = None
# First find adapter by model_name
for adapter_entry in model_adapters:
for adapter_entry in model_adapters[::-1]:
if adapter_entry.model_adapter.match(model_type, model_name, None):
adapter = adapter_entry.model_adapter
break
for adapter_entry in model_adapters:
for adapter_entry in model_adapters[::-1]:
if adapter_entry.model_adapter.match(model_type, None, model_path):
adapter = adapter_entry.model_adapter
break

View File

@ -135,6 +135,41 @@ class YiAdapter(NewHFChatModelAdapter):
)
class Yi15Adapter(YiAdapter):
"""Yi 1.5 model adapter."""
def do_match(self, lower_model_name_or_path: Optional[str] = None):
return (
lower_model_name_or_path
and "yi-" in lower_model_name_or_path
and "1.5" in lower_model_name_or_path
and "chat" in lower_model_name_or_path
)
def get_str_prompt(
self,
params: Dict,
messages: List[ModelMessage],
tokenizer: Any,
prompt_template: str = None,
convert_to_compatible_format: bool = False,
) -> Optional[str]:
str_prompt = super().get_str_prompt(
params,
messages,
tokenizer,
prompt_template,
convert_to_compatible_format,
)
terminators = [
tokenizer.eos_token_id,
]
exist_token_ids = params.get("stop_token_ids", [])
terminators.extend(exist_token_ids)
params["stop_token_ids"] = terminators
return str_prompt
class Mixtral8x7BAdapter(NewHFChatModelAdapter):
"""
https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1
@ -335,7 +370,10 @@ class Llama3Adapter(NewHFChatModelAdapter):
return str_prompt
# The following code is used to register the model adapter
# The last registered model adapter is matched first
register_model_adapter(YiAdapter)
register_model_adapter(Yi15Adapter)
register_model_adapter(Mixtral8x7BAdapter)
register_model_adapter(SOLARAdapter)
register_model_adapter(GemmaAdapter)