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 chatglm3 template #820

Merged
merged 1 commit into from
May 10, 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
25 changes: 25 additions & 0 deletions docs/source/examples/supported_conversation_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,37 @@

This template is not preseted in LMFlow currently. We are working on it and will update it soon.
```
**With a system message**
```
[gMASK]sop<|system|>\n {{system_message}}<|user|>\n {{user_message_0}}
```

**Without a system message**
```
[gMASK]sop<|user|>\n {{user_message_0}}
```

**A complete conversation**
```
[gMASK]sop<|system|>\n {{system_message}}<|user|>\n {{user_message_0}}<|assistant|>\n {{assistant_reply_0}}
```

**Multiple rounds**
```
[gMASK]sop<|system|>\n {{system_message}}<|user|>\n {{user_message_0}}<|assistant|>\n {{assistant_reply_0}}<|user|>\n {{user_message_1}}<|assistant|>\n {{assistant_reply_1}}
```

**jinja template**
[[Reference](https://huggingface.co/THUDM/chatglm3-6b/blob/103caa40027ebfd8450289ca2f278eac4ff26405/tokenizer_config.json#L42)]
```
{% for message in messages %}{% if loop.first %}[gMASK]sop<|{{ message['role'] }}|>\n {{ message['content'] }}{% else %}<|{{ message['role'] }}|>\n {{ message['content'] }}{% endif %}{% endfor %}{% if add_generation_prompt %}<|assistant|>{% endif %}
```

**Filled Example**
```
[gMASK]sop<|system|>\n You are a chatbot developed by LMFlow team.<|user|>\n Who are you?<|assistant|>\n I am a chatbot developed by LMFlow team.<|user|>\n How old are you?<|assistant|>\n 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.
```


## ChatML
**With a system message**
Expand Down
25 changes: 25 additions & 0 deletions src/lmflow/utils/conversation_template/chatglm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
# coding=utf-8
# Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved.
from .base import StringFormatter, TemplateComponent, ConversationTemplate


CHATGLM3_TEMPLATE = ConversationTemplate(
template_name='chatglm3',
user_formatter=StringFormatter(
template=[
TemplateComponent(type='string', content='<|user|>\n {{content}}')
]
),
assistant_formatter=StringFormatter(
template=[
TemplateComponent(type='string', content='<|assistant|>\n {{content}}')
]
),
system_formatter=StringFormatter(
template=[
TemplateComponent(type='string', content='<|system|>\n {{content}}')
]
),
special_starter=TemplateComponent(type='string', content='[gMASK]sop')
)
Loading