Skip to content
New issue

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

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

Already on GitHub? # to your account

Add chatglm3 template #822

Merged
merged 1 commit into from
May 11, 2024
Merged
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/source/examples/DATASETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Conversations should be formatted before feeding into the model. As of now, we'v

| Template Name | Filled Example | Detailed Template |
| ------------- | -------------- | ----------------- |
| `chatglm3` | `[gMASK]sop<\|system\|>`<br>` You are a chatbot developed by LMFlow team.<\|user\|>`<br>` Who are you?<\|assistant\|>`<br>` I am a chatbot developed by LMFlow team.<\|user\|>`<br>` How old are you?<\|assistant\|>`<br>` I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.` | [Link](./supported_conversation_template.md#chatglm3) |
| `chatml` | `<\|im_start\|>system`<br>`You are a chatbot developed by LMFlow team.<\|im_end\|>`<br>`<\|im_start\|>user`<br>`Who are you?<\|im_end\|>`<br>`<\|im_start\|>assistant`<br>`I am a chatbot developed by LMFlow team.<\|im_end\|>`<br>`<\|im_start\|>user`<br>`How old are you?<\|im_end\|>`<br>`<\|im_start\|>assistant`<br>`I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<\|im_end\|>`<br> | [Link](./supported_conversation_template.md#chatml) |
| `deepseek` | `<|begin▁of▁sentence|>You are a chatbot developed by LMFlow team.`<br><br>`User: Who are you?`<br><br>`Assistant: I am a chatbot developed by LMFlow team.<|end▁of▁sentence|>User: How old are you?`<br><br>`Assistant: I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<|end▁of▁sentence|>` | [Link](./supported_conversation_template.md#deepseek) |
| `internlm2` | `<s><\|im_start\|>system`<br>`You are a chatbot developed by LMFlow team.<\|im_end\|>`<br>`<\|im_start\|>user`<br>`Who are you?<\|im_end\|>`<br>`<\|im_start\|>assistant`<br>`I am a chatbot developed by LMFlow team.<\|im_end\|>`<br>`<\|im_start\|>user`<br>`How old are you?<\|im_end\|>`<br>`<\|im_start\|>assistant`<br>`I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<\|im_end\|>`<br> | [Link](./supported_conversation_template.md#internlm2) |
Expand Down
2 changes: 2 additions & 0 deletions src/lmflow/utils/conversation_template/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# coding=utf-8
# Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved.
from .base import EMPTY_TEMPLATE, EMPTY_NO_SPECIAL_TOKENS_TEMPLATE, ConversationTemplate
from .chatglm import CHATGLM3_TEMPLATE
from .chatml import CHATML_TEMPLATE
from .deepseek import DEEPSEEK_TEMPLATE
from .internlm import INTERNLM2_TEMPLATE
Expand All @@ -11,6 +12,7 @@


PRESET_TEMPLATES = {
'chatglm3': CHATGLM3_TEMPLATE,
'chatml': CHATML_TEMPLATE,
'deepseek': DEEPSEEK_TEMPLATE,
'empty': EMPTY_TEMPLATE,
Expand Down
34 changes: 34 additions & 0 deletions tests/models/test_hf_decoder_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@
]
}

CONVERSATION_SINGLETURN_CHATGLM3_IDS = [
(
[64790, 64792, 906, 31007, 13361, 31007, 30994, 13, 15184, 6607, 64795, 30910, 13, 13755, ],
[64796, 30910, 13, 8686, 30992,]
)
]

CONVERSATION_SINGLETURN_DEEPSEEK_IDS = [
(
[100000, 10183, 4904, 185, 185, 5726, 25, 37727, 185, 185],
Expand Down Expand Up @@ -158,6 +165,17 @@
)
]

CONVERSATION_MULTITURN_CHATGLM3_IDS = [
(
[64790, 64792, 906, 31007, 13361, 31007, 30994, 13, 15184, 6607, 64795, 30910, 13, 13755, ],
[64796, 30910, 13, 8686, 30992,]
),
(
[64795, 30910, 13, 1072, 383, 344, 30987, ],
[64796, 30910, 13, 307, 30953, 30924, 878, 30932, 4772, 30992]
)
]

CONVERSATION_MULTITURN_INTERNLM2_IDS = [
(
[1, 333, 352, 449, 5064, 352, 330, 9081, 364, 7930, 2896, 333, 352, 449, 6368, 352, 527,
Expand Down Expand Up @@ -404,6 +422,14 @@ def test_tokenize_conversation(self):
trust_remote_code=True
)

self._test_tokenize(
model_name='THUDM/chatglm3-6b',
groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_SINGLETURN]},
groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_SINGLETURN_CHATGLM3_IDS]),
conversation_template=PRESET_TEMPLATES['chatglm3'],
trust_remote_code=True
)


def test_tokenize_conversation_multiple(self):
conversation_dataset = {
Expand Down Expand Up @@ -491,6 +517,14 @@ def test_tokenize_conversation_multiple(self):
conversation_template=PRESET_TEMPLATES['internlm2'],
trust_remote_code=True
)

self._test_tokenize(
model_name='THUDM/chatglm3-6b',
groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_MULTITURN]},
groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_MULTITURN_CHATGLM3_IDS]),
conversation_template=PRESET_TEMPLATES['chatglm3'],
trust_remote_code=True
)


def test_encode(self):
Expand Down
Loading