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

feat(glm3): adapt to glm3 prompt #2620

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions docs/model_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- [StabilityAI/stablelm-tuned-alpha-7b](https://huggingface.co/stabilityai/stablelm-tuned-alpha-7b)
- [THUDM/chatglm-6b](https://huggingface.co/THUDM/chatglm-6b)
- [THUDM/chatglm2-6b](https://huggingface.co/THUDM/chatglm2-6b)
- [THUDM/chatglm3-6b](https://huggingface.co/THUDM/chatglm3-6b)
- [tiiuae/falcon-40b](https://huggingface.co/tiiuae/falcon-40b)
- [tiiuae/falcon-180B-chat](https://huggingface.co/tiiuae/falcon-180B-chat)
- [timdettmers/guanaco-33b-merged](https://huggingface.co/timdettmers/guanaco-33b-merged)
Expand Down
23 changes: 23 additions & 0 deletions fastchat/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ def get_prompt(self) -> str:
elif self.sep_style == SeparatorStyle.CHATGLM:
# source: https://huggingface.co/THUDM/chatglm-6b/blob/1d240ba371910e9282298d4592532d7f0f3e9f3e/modeling_chatglm.py#L1302-L1308
# source2: https://huggingface.co/THUDM/chatglm2-6b/blob/e186c891cf64310ac66ef10a87e6635fa6c2a579/modeling_chatglm.py#L926
if self.name == "chatglm3":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put a link to the source here?

Copy link
Contributor

@ZeyuTeng96 ZeyuTeng96 Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there,

since chatglm3 uses differenet chat format, I do not think we still need to use the 'CHATGLM' separator style and put a if condition to choice the chat format. But putting the chatglm3 chat format into 'CHATGLM' separator style make sense. I suggest an main contributer to dicide do we have to make an new separator style for it @merrymercy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@silk55 could you add a source?

if self.system_message and system_prompt:
ret = system_prompt + "\n"
else:
ret = ""
for i, (role, message) in enumerate(self.messages):
if message:
ret += role + "\n" + message + "\n"
else:
ret += role + "\n"
return ret
round_add_n = 1 if self.name == "chatglm2" else 0
if system_prompt:
ret = system_prompt + self.sep
Expand Down Expand Up @@ -448,6 +459,18 @@ def get_conv_template(name: str) -> Conversation:
)
)

# ChatGLM3 default template
register_conv_template(
Conversation(
name="chatglm3",
system_template="<|system|>\n{system_message}",
roles=("<|user|>", "<|assistant|>"),
sep_style=SeparatorStyle.CHATGLM,
sep=None,
stop_token_ids=[2, 64795, 64797],
)
)

# Dolly V2 default template
register_conv_template(
Conversation(
Expand Down
2 changes: 2 additions & 0 deletions fastchat/model/model_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ def get_default_conv_template(self, model_path: str) -> Conversation:
model_path = model_path.lower()
if "chatglm2" in model_path.lower():
return get_conv_template("chatglm2")
if "chatglm3" in model_path.lower():
return get_conv_template("chatglm3")
return get_conv_template("chatglm")


Expand Down
2 changes: 1 addition & 1 deletion fastchat/model/model_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def get_model_info(name: str) -> ModelInfo:
"an RNN with transformer-level LLM performance",
)
register_model_info(
["chatglm-6b", "chatglm2-6b"],
["chatglm-6b", "chatglm2-6b", "chatglm3-6b"],
"ChatGLM",
"https://chatglm.cn/blog",
"an open bilingual dialogue language model by Tsinghua University",
Expand Down
1 change: 1 addition & 0 deletions fastchat/serve/gradio_block_arena_anony.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def share_click(state0, state1, model_selector0, model_selector1, request: gr.Re
"vicuna-7b": 1.0,
"llama-2-7b-chat": 1.0,
"chatglm2-6b": 1.0,
"chatglm3-6b": 1.0,
"mistral-7b-instruct": 1.0,
# deprecated
"codellama-13b-instruct": 1.0,
Expand Down