Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system role to deepseek chat template #3031

Merged
merged 8 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lmdeploy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,13 +1396,17 @@ 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: ',
eoa='<|end▁of▁sentence|>',
**kwargs):
super().__init__(user=user,
eoh=eoh,
meta_instruction=meta_instruction,
eosys=eosys,
assistant=assistant,
eoa=eoa,
**kwargs)
Expand Down
23 changes: 23 additions & 0 deletions tests/test_lmdeploy/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,29 @@ def test_codellama_others():
assert model is None


def test_deepseek():
model = MODELS.get('deepseek')()
messages = [{
'role': 'system',
'content': 'you are a helpful assistant'
}, {
'role': 'user',
'content': 'who are you'
}, {
'role': 'assistant',
'content': 'I am an AI'
}, {
'role': 'user',
'content': 'hi'
}]
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('deepseek-ai/DeepSeek-V2-Lite',
trust_remote_code=True)
ref = tokenizer.apply_chat_template(messages, tokenize=False)
res = '<|begin▁of▁sentence|>' + model.messages2prompt(messages)
assert res.startswith(ref)


def test_deepseek_coder():
model = MODELS.get('deepseek-coder')()
messages = [{
Expand Down