Skip to content

Conversation

@ngxson
Copy link
Collaborator

@ngxson ngxson commented Jun 27, 2024

Replaces #6236

This PR replaces the tmpl.find(haystack) != std::string::npos pattern with a lambda function tmpl_contains(haystack)

Also add MiniCPM chat template

You are a helpful assistant<用户>Hello<AI>Hi there<用户>Who are you<AI>I am an assistant<用户>Another question<AI>

@ngxson ngxson added the Review Complexity : Low Trivial changes to code that most beginner devs (or those who want a break) can tackle. e.g. UI fix label Jun 27, 2024
@ngxson ngxson requested a review from ggerganov June 27, 2024 16:49
@ngxson ngxson changed the title Add MiniCPM chat template + clean up llama_chat_apply_template_internal Add MiniCPM, Deepseek LITE chat template + clean up llama_chat_apply_template_internal Jun 27, 2024
@ngxson ngxson requested a review from fairydreaming June 27, 2024 17:19
@ngxson
Copy link
Collaborator Author

ngxson commented Jun 27, 2024

@fairydreaming I added deepseek lite chat template to this PR. Without chat template, it speaks somewhat english, but now it only speaks chinese:

> hi, who are you
我是DeepSeek Coder,一个由深度求索公司开发的智能助手。我可以帮助您回答问题和提供信息。请问有什么可以帮助您的吗?

> nice
很高兴您觉得还可以!如果您有任何问题或需要帮助的地方,请随时告诉我。

>

Copy link
Collaborator

@fairydreaming fairydreaming left a 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:

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: ";
Copy link
Collaborator

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.

Copy link
Collaborator Author

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")) {
Copy link
Collaborator

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"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed in 736c494

"{% 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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Replace with DeepSeek-V2

Copy link
Collaborator

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.

@github-actions github-actions bot added the testing Everything test related label Jun 27, 2024
@ngxson
Copy link
Collaborator Author

ngxson commented Jun 27, 2024

@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:

> who are you
 I am DeepSeek Coder, an intelligent assistant developed by DeepSeek, a company in China.

> how do you say "happy new year" in chinese
 In Chinese, "happy new year" can be expressed in several ways. Here are some options:

1. 新年快乐 (Xīnnián kuàilè) - This phrase literally means "new year happy." It's the most common way to say "happy new year" in Chinese.

@ngxson ngxson changed the title Add MiniCPM, Deepseek LITE chat template + clean up llama_chat_apply_template_internal Add MiniCPM, Deepseek V2 chat template + clean up llama_chat_apply_template_internal Jun 27, 2024
Copy link
Collaborator

@fairydreaming fairydreaming left a 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.

"{% 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
Copy link
Collaborator

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.

@ngxson ngxson merged commit 26a39bb into ggml-org:master Jun 28, 2024
Nexesenex pushed a commit to Nexesenex/croco.cpp that referenced this pull request Jun 29, 2024
…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
Nexesenex pushed a commit to Nexesenex/croco.cpp that referenced this pull request Jun 30, 2024
…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
Nexesenex pushed a commit to Nexesenex/croco.cpp that referenced this pull request Jun 30, 2024
…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
MagnusS0 pushed a commit to MagnusS0/llama.cpp-normistral-tokenizer that referenced this pull request Jul 1, 2024
…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
Nexesenex pushed a commit to Nexesenex/croco.cpp that referenced this pull request Jul 1, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review Complexity : Low Trivial changes to code that most beginner devs (or those who want a break) can tackle. e.g. UI fix testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants