-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Add deepseek chat #2760
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 deepseek chat #2760
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ class SeparatorStyle(IntEnum): | |
| ROBIN = auto() | ||
| FALCON_CHAT = auto() | ||
| CHATGLM3 = auto() | ||
| DEEPSEEK_CHAT = auto() | ||
|
|
||
|
|
||
| @dataclasses.dataclass | ||
|
|
@@ -224,6 +225,15 @@ def get_prompt(self) -> str: | |
| ret += role + ":" | ||
|
|
||
| return ret | ||
| elif self.sep_style == SeparatorStyle.DEEPSEEK_CHAT: | ||
| seps = [self.sep, self.sep2] | ||
| ret = system_prompt | ||
| for i, (role, message) in enumerate(self.messages): | ||
| if message: | ||
| ret += role + ": " + message + seps[i % 2] | ||
| else: | ||
| ret += role + ":" | ||
| return ret | ||
| else: | ||
| raise ValueError(f"Invalid style: {self.sep_style}") | ||
|
|
||
|
|
@@ -530,7 +540,7 @@ def get_conv_template(name: str) -> Conversation: | |
| # Deepseek code default template | ||
| register_conv_template( | ||
| Conversation( | ||
| name="deepseek", | ||
| name="deepseek-coder", | ||
| system_template="You are an AI programming assistant, utilizing the DeepSeek Coder model, developed by DeepSeek Company, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer.", | ||
| roles=("### Instruction:", "### Response:"), | ||
| sep="\n", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so deepseek-coder's sep_style is different from deepseek?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, it's style is different according to this: https://huggingface.co/deepseek-ai/deepseek-coder-33b-instruct/blob/main/tokenizer_config.json Deepseek-coder, seems to do So, there's an extra |
||
|
|
@@ -1265,6 +1275,20 @@ def get_conv_template(name: str) -> Conversation: | |
| ) | ||
| ) | ||
|
|
||
| # Deepseek-chat template | ||
| # reference: https://huggingface.co/deepseek-ai/deepseek-llm-67b-chat/blob/main/tokenizer_config.json | ||
| register_conv_template( | ||
| Conversation( | ||
| name="deepseek-chat", | ||
| system_message="<|begin▁of▁sentence|>", # must add a bos token before first message | ||
| roles=("User", "Assistant"), | ||
| sep_style=SeparatorStyle.DEEPSEEK_CHAT, | ||
| sep="\n\n", | ||
| sep2="<|end▁of▁sentence|>", | ||
| stop_str="<|end▁of▁sentence|>", | ||
| ) | ||
| ) | ||
|
|
||
| if __name__ == "__main__": | ||
| from fastchat.conversation import get_conv_template | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to confirm, there's no existing template suitable for deepseek?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The closest I could find is
SeparatorStyle.ADD_COLON_TWO, the only issue is that it has an extrasystem_prompt + seps[0]instead of justsystem_prompt, which leads to an extra\n\nif we use that conversation style.The difficulty comes from:
<|begin_of_sentence|>token before the user response which I think the easiest location to put that is the system_message.<|end_of_sentence|>after the Assistant's message, which requires us to have two sepsTLDR: I couldn't find another suitable template
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, thanks! moving forwrad, we should consider migrating to HF's chat template so we can leave this responsibility to model developers.
https://huggingface.co/deepseek-ai/deepseek-llm-67b-chat/blob/79648bef7658bb824e4630740f6e1484c1b0620b/tokenizer_config.json#L34