-
Notifications
You must be signed in to change notification settings - Fork 4.8k
add chatglm3 conv template support in conversation.py #2622
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
Changes from 1 commit
8642f38
2183bc4
84e885f
c92675f
dcd5324
efd1501
99087e7
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 |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ class SeparatorStyle(IntEnum): | |
| PHOENIX = auto() | ||
| ROBIN = auto() | ||
| FALCON_CHAT = auto() | ||
| CHATGLM3 = auto() | ||
|
|
||
|
|
||
| @dataclasses.dataclass | ||
|
|
@@ -163,6 +164,14 @@ def get_prompt(self) -> str: | |
| else: | ||
| ret += role + "\n" | ||
| return ret | ||
| elif self.sep_style == SeparatorStyle.CHATGLM3: | ||
| ret = "" if system_prompt == "" else system_prompt | ||
|
||
| for role, message in self.messages: | ||
| if message: | ||
| ret += role + "\n" + message | ||
|
||
| else: | ||
| ret += role | ||
| return ret | ||
| elif self.sep_style == SeparatorStyle.CHATINTERN: | ||
| # source: https://huggingface.co/internlm/internlm-chat-7b-8k/blob/bd546fa984b4b0b86958f56bf37f94aa75ab8831/modeling_internlm.py#L771 | ||
| seps = [self.sep, self.sep2] | ||
|
|
@@ -448,6 +457,23 @@ def get_conv_template(name: str) -> Conversation: | |
| ) | ||
| ) | ||
|
|
||
| # ChatGLM3 default template | ||
| register_conv_template( | ||
| Conversation( | ||
| name="chatglm3", | ||
| system_template="<|system|>\n{system_message}", | ||
| system_message="You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown.", | ||
| roles=("<|user|>", "<|assistant|>"), | ||
| sep_style=SeparatorStyle.CHATGLM3, | ||
| sep="", | ||
| stop_token_ids=[ | ||
| 64795, | ||
| 64797, | ||
| 2, | ||
| ], # "<|user|>", "<|observation|>", "</s>" | ||
| ) | ||
| ) | ||
|
|
||
| # Dolly V2 default template | ||
| register_conv_template( | ||
| Conversation( | ||
|
|
||
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.
Can you add reference?
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.
How about adding this ref (https://huggingface.co/THUDM/chatglm3-6b/blob/fc3235f807ef5527af598c05f04f2ffd17f48bab/tokenization_chatglm.py#L184) ?
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.
@ZeyuTeng96 Like this conversation.py#L167 :)