Skip to content

Commit 56df1fc

Browse files
committed
llama : fix detection of control-like user-defined tokens
1 parent 6b961e3 commit 56df1fc

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/llama.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5513,7 +5513,8 @@ static void llm_load_vocab(
55135513
}
55145514
}
55155515

5516-
if ((token_data.attr & LLAMA_TOKEN_ATTR_USER_DEFINED) && token_data.text.find('<') && token_data.text.rfind('>')) {
5516+
if ((token_data.attr & LLAMA_TOKEN_ATTR_USER_DEFINED) && !token_data.text.empty() &&
5517+
token_data.text.front() == '<' && token_data.text.back() == '>') {
55175518
// Some models mark some added tokens which ought to be control tokens as not special.
55185519
// (e.g. command-r, command-r-plus, deepseek-coder)
55195520
// TODO: should this be fixed in the convert script instead?

tests/test-tokenizer-0.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ int main(int argc, char **argv) {
195195
const bool add_special = false;
196196

197197
for (const auto & test_kv : k_tests) {
198-
const std::vector<llama_token> res = llama_tokenize(ctx, test_kv.first, add_special);
198+
const std::vector<llama_token> res = llama_tokenize(ctx, test_kv.first, add_special, false);
199199

200200
printf("\n");
201201
printf("src: '%s'\n", test_kv.first.c_str());
@@ -253,7 +253,7 @@ int main(int argc, char **argv) {
253253
{
254254
const auto t_start = ggml_time_us();
255255

256-
res = llama_tokenize(ctx, text, add_special);
256+
res = llama_tokenize(ctx, text, add_special, false);
257257

258258
const auto t_end = ggml_time_us();
259259

0 commit comments

Comments
 (0)