-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Add MiniCPM, Deepseek V2 chat template + clean up llama_chat_apply_template_internal
#8172
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
Conversation
llama_chat_apply_template_internalllama_chat_apply_template_internal
|
@fairydreaming I added deepseek lite chat template to this PR. Without chat template, it speaks somewhat english, but now it only speaks chinese: |
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.
@ngxson I'm not sure if it's a good idea to call it deepseek-lite chat template. From what I see the following models:
- https://huggingface.co/deepseek-ai/DeepSeek-V2
- https://huggingface.co/deepseek-ai/DeepSeek-V2-Chat
- https://huggingface.co/deepseek-ai/DeepSeek-V2-Lite
- https://huggingface.co/deepseek-ai/DeepSeek-V2-Lite-Chat
- https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Instruct
- https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct
all use the same chat template in tokenizer_config.json, so it's better to call it deepseek2. DeepSeek-V2 was first to use it, so I think it's best to refer in comments to simply DeepSeek-V2 instead of DeepSeek-Coder-V2-Lite-Instruct-GGUF like you did.
src/llama.cpp
Outdated
| } | ||
| } | ||
| if (add_ass) { | ||
| ss << "Assistant: "; |
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.
I think you have extra space after "Assistant:" here, this causes the model to speak Chinese.
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.
Extra space removed in 736c494
src/llama.cpp
Outdated
| ss << trim(message->content); | ||
| } | ||
| } | ||
| } else if (tmpl == "deepseek-lite" || tmpl_contains("'Assistant: ' + message['content'] + eos_token")) { |
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.
Change "deepseek-lite" to "deepseek2"
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.
Changed in 736c494
tests/test-chat-template.cpp
Outdated
| "{% for message in messages %}{{'<|' + message['role'] + '|>' + '\n' + message['content'] + '<|end|>\n' }}{% endfor %}{% if add_generation_prompt and messages[-1]['role'] != 'assistant' %}{{- '<|assistant|>\n' -}}{% endif %}", | ||
| // MiniCPM-3B-OpenHermes-2.5-v2-GGUF | ||
| u8"{% for message in messages %}{% if message['role'] == 'user' %}{{'<用户>' + message['content'].strip() + '<AI>'}}{% else %}{{message['content'].strip()}}{% endif %}{% endfor %}", | ||
| // DeepSeek-Coder-V2-Lite-Instruct-GGUF |
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.
Replace with DeepSeek-V2
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.
I think you forgot to change this one.
|
@fairydreaming Thanks for the info. I was confused between deepseek (v1), deepseek-V2 and lite-V2. With the extra space removed, it's now speaking correct language: |
llama_chat_apply_template_internalllama_chat_apply_template_internal
fairydreaming
left a comment
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.
There's still one "DeepSeek-Coder-V2-Lite-Instruct-GGUF" in the comments, correct it and should be good to go.
tests/test-chat-template.cpp
Outdated
| "{% for message in messages %}{{'<|' + message['role'] + '|>' + '\n' + message['content'] + '<|end|>\n' }}{% endfor %}{% if add_generation_prompt and messages[-1]['role'] != 'assistant' %}{{- '<|assistant|>\n' -}}{% endif %}", | ||
| // MiniCPM-3B-OpenHermes-2.5-v2-GGUF | ||
| u8"{% for message in messages %}{% if message['role'] == 'user' %}{{'<用户>' + message['content'].strip() + '<AI>'}}{% else %}{{message['content'].strip()}}{% endif %}{% endfor %}", | ||
| // DeepSeek-Coder-V2-Lite-Instruct-GGUF |
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.
I think you forgot to change this one.
…emplate_internal` (ggml-org#8172) * tmp_contains * minicpm chat template * add DeepSeek Lite template * change deepseek-lite to deepseek2 * correct code comment * correct code from master branch
…emplate_internal` (ggml-org#8172) * tmp_contains * minicpm chat template * add DeepSeek Lite template * change deepseek-lite to deepseek2 * correct code comment * correct code from master branch
…emplate_internal` (ggml-org#8172) * tmp_contains * minicpm chat template * add DeepSeek Lite template * change deepseek-lite to deepseek2 * correct code comment * correct code from master branch
…emplate_internal` (ggml-org#8172) * tmp_contains * minicpm chat template * add DeepSeek Lite template * change deepseek-lite to deepseek2 * correct code comment * correct code from master branch
…emplate_internal` (ggml-org#8172) * tmp_contains * minicpm chat template * add DeepSeek Lite template * change deepseek-lite to deepseek2 * correct code comment * correct code from master branch
Replaces #6236
This PR replaces the
tmpl.find(haystack) != std::string::npospattern with a lambda functiontmpl_contains(haystack)Also add MiniCPM chat template