From 3e44d3787651ea4ab79ffef5218cbb38dd9696e3 Mon Sep 17 00:00:00 2001 From: AllentDan Date: Wed, 15 Jan 2025 11:55:52 +0800 Subject: [PATCH] add deepseek system role and keep the same with HF --- lmdeploy/model.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lmdeploy/model.py b/lmdeploy/model.py index ba9f36048..3ee01017d 100644 --- a/lmdeploy/model.py +++ b/lmdeploy/model.py @@ -320,7 +320,7 @@ def __init__( eosys=' ', user='USER: ', eoh=' ', - assistant='Assistant:', + assistant='ASSISTANT: ', eoa='', stop_words=[''], **kwargs): @@ -358,10 +358,10 @@ def __init__( super().__init__(meta_instruction=meta_instruction, **kwargs) def get_prompt(self, prompt, sequence_start=True): - return super().get_prompt(prompt, sequence_start) + return super().get_prompt(prompt, sequence_start)[:-1] def messages2prompt(self, messages, sequence_start=True, **kwargs): - return super().messages2prompt(messages, sequence_start, **kwargs) + return super().messages2prompt(messages, sequence_start, **kwargs)[:-1] @classmethod def match(cls, model_path: str) -> Optional[str]: @@ -386,10 +386,10 @@ def __init__(self, **kwargs): super().__init__(**kwargs) def get_prompt(self, prompt, sequence_start=True): - return super().get_prompt(prompt, sequence_start) + return super().get_prompt(prompt, sequence_start)[:-1] def messages2prompt(self, messages, sequence_start=True, **kwargs): - return super().messages2prompt(messages, sequence_start, **kwargs) + return super().messages2prompt(messages, sequence_start, **kwargs)[:-1] @classmethod def match(cls, model_path: str) -> Optional[str]: @@ -1267,7 +1267,7 @@ def __init__( eosys='\n', user='User: ', eoh='\n', - assistant='Assistant:', + assistant='Assistant: ', eoa='', separator='\n', stop_words=[''], @@ -1396,22 +1396,26 @@ def match(cls, model_path: str) -> Optional[str]: class Deepseek(BaseChatTemplate): def __init__(self, + meta_instruction=None, + eosys='\n\n', user='User: ', eoh='\n\n', - assistant='Assistant:', + assistant='Assistant: ', eoa='<|end▁of▁sentence|>', **kwargs): super().__init__(user=user, eoh=eoh, + meta_instruction=meta_instruction, + eosys=eosys, assistant=assistant, eoa=eoa, **kwargs) def get_prompt(self, prompt, sequence_start=True): - return super().get_prompt(prompt, sequence_start) + return super().get_prompt(prompt, sequence_start)[:-1] def messages2prompt(self, messages, sequence_start=True, **kwargs): - return super().messages2prompt(messages, sequence_start, **kwargs) + return super().messages2prompt(messages, sequence_start, **kwargs)[:-1] @classmethod def match(cls, model_path: str) -> Optional[str]: @@ -1431,7 +1435,7 @@ class InternVLZH(BaseChatTemplate): def __init__(self, user=': ', eoh=' ', - assistant=':', + assistant=': ', eoa='', **kwargs): super().__init__(user=user, @@ -1441,10 +1445,10 @@ def __init__(self, **kwargs) def get_prompt(self, prompt, sequence_start=True): - return super().get_prompt(prompt, sequence_start) + return super().get_prompt(prompt, sequence_start)[:-1] def messages2prompt(self, messages, sequence_start=True, **kwargs): - return super().messages2prompt(messages, sequence_start, **kwargs) + return super().messages2prompt(messages, sequence_start, **kwargs)[:-1] @classmethod def match(cls, model_path: str) -> Optional[str]: @@ -1467,7 +1471,7 @@ def __init__( eosys='\n\n', user='User: ', eoh='\n\n', - assistant='Assistant:', + assistant='Assistant: ', eoa='<|end▁of▁sentence|>', **kwargs): super().__init__(meta_instruction=meta_instruction, @@ -1479,10 +1483,10 @@ def __init__( **kwargs) def get_prompt(self, prompt, sequence_start=True): - return super().get_prompt(prompt, sequence_start) + return super().get_prompt(prompt, sequence_start)[:-1] def messages2prompt(self, messages, sequence_start=True, **kwargs): - return super().messages2prompt(messages, sequence_start, **kwargs) + return super().messages2prompt(messages, sequence_start, **kwargs)[:-1] @classmethod def match(cls, model_path: str) -> Optional[str]: