Skip to content

Commit ce68673

Browse files
committed
tests : fix build + warnings (test-tokenizer-1 still fails)
1 parent ca630d9 commit ce68673

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

tests/test-tokenizer-0.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88

99
static std::string unescape_whitespace(llama_context* ctx, const std::vector<llama_token>& tokens) {
1010
std::string result;
11-
for (int i = 0; i < tokens.size(); ++i) {
11+
for (size_t i = 0; i < tokens.size(); ++i) {
1212
result += llama_token_to_str(ctx, tokens[i]);
1313
}
1414
return result;
1515
}
1616

17-
static const std::map<std::string, std::vector<llama_token>> & k_tests()
18-
{
17+
static const std::map<std::string, std::vector<llama_token>> & k_tests() {
1918
static std::map<std::string, std::vector<llama_token>> _k_tests = {
2019
{ " ", {1, 259, }, },
2120
{ "\t", { 1, 29871, 12, }, },
@@ -29,17 +28,18 @@ static const std::map<std::string, std::vector<llama_token>> & k_tests()
2928
{ " this is 🦙.cpp", { 1, 29871, 445, 338, 29871, 243, 162, 169, 156, 29889, 8223, }, },
3029
{ "w048 7tuijk dsdfhu", { 1, 281, 29900, 29946, 29947, 29871, 29955, 9161, 13535, 18031, 2176, 6905, }, },
3130
{ "нещо на Български", { 1, 1538, 4851, 665, 1386, 29713, 1305, }, },
32-
{ "កាន់តែពិសេសអាចខលចេញ", { 1, 29871, 31849, 31324, 31934, 228, 162, 142, 228, 161,
33-
146, 228, 162, 133, 228, 161, 153, 228, 161, 186,
34-
31708, 228, 162, 132, 31708, 228, 161, 165, 31324, 228,
35-
161, 136, 228, 161, 132, 228, 161, 158, 228, 161,
36-
136, 228, 162, 132, 228, 161, 140, }, },
31+
{ "កាន់តែពិសេសអាចខលចេញ", { 1, 29871, 31849, 31324, 31934, 228, 162, 142, 228, 161,
32+
146, 228, 162, 133, 228, 161, 153, 228, 161, 186,
33+
31708, 228, 162, 132, 31708, 228, 161, 165, 31324, 228,
34+
161, 136, 228, 161, 132, 228, 161, 158, 228, 161,
35+
136, 228, 162, 132, 228, 161, 140, }, },
3736
{ "🚀 (normal) 😶‍🌫️ (multiple emojis concatenated) ✅ (only emoji that has its own token)",
38-
{ 1, 29871, 243, 162, 157, 131, 313, 8945, 29897, 29871,
39-
243, 162, 155, 185, 30722, 243, 162, 143, 174, 30598,
40-
313, 20787, 953, 3848, 275, 16125, 630, 29897, 29871, 31681,
41-
313, 6194, 953, 29877, 2397, 393, 756, 967, 1914, 5993, 29897, }, },
42-
};
37+
{ 1, 29871, 243, 162, 157, 131, 313, 8945, 29897, 29871,
38+
243, 162, 155, 185, 30722, 243, 162, 143, 174, 30598,
39+
313, 20787, 953, 3848, 275, 16125, 630, 29897, 29871, 31681,
40+
313, 6194, 953, 29877, 2397, 393, 756, 967, 1914, 5993, 29897, }, },
41+
};
42+
4343
return _k_tests;
4444
};
4545

@@ -90,8 +90,8 @@ int main(int argc, char **argv) {
9090
}
9191

9292
for (const auto & test_kv : k_tests()) {
93-
std::vector<llama_token> res = llama_tokenize(ctx, test_kv.first.c_str(), true);
94-
fprintf(stderr, "%s : '%s' tokenized to '%s'\n",
93+
std::vector<llama_token> res = llama_tokenize(ctx, test_kv.first, true);
94+
fprintf(stderr, "%s : '%s' tokenized to '%s'\n",
9595
__func__, test_kv.first.c_str(), unescape_whitespace(ctx, res).c_str());
9696

9797
bool correct = res.size() == test_kv.second.size();

tests/test-tokenizer-1.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <codecvt>
99
#include <map>
1010
#include <vector>
11+
#include <locale>
1112

1213
static std::string vocab_type(llama_context* ctx) {
1314
return llama_n_vocab(ctx) == 32000 ? "spm": "bpe";
@@ -85,17 +86,17 @@ int main(int argc, char **argv) {
8586
if (tokens.size() == 1) {
8687
if (i != tokens[0]) {
8788
std::string backward = llama_token_to_str(ctx, tokens[0]);
88-
fprintf(stderr, "%s : error: token %d is string %s but bpe returns token %d %s\n",
89+
fprintf(stderr, "%s : error: token %d is string %s but bpe returns token %d %s\n",
8990
__func__, i, llama_token_to_str(ctx, i).c_str(), tokens[0], backward.c_str());
9091
return 2;
9192
}
9293
} else {
93-
if ((vocab_type(ctx) == "spm" && i <= 258) ||
94+
if ((vocab_type(ctx) == "spm" && i <= 258) ||
9495
(vocab_type(ctx) == "bpe" && (i == 0 || i >= 100000))) {
95-
fprintf(stderr, "%s : info: token %d is string %s and bpe returns tokens %s\n",
96+
fprintf(stderr, "%s : info: token %d is string %s and bpe returns tokens %s\n",
9697
__func__, i, llama_token_to_str(ctx, i).c_str(), unescape_whitespace(ctx, tokens).c_str());
9798
} else {
98-
fprintf(stderr, "%s : error: token %d is string %s but bpe returns tokens %s\n",
99+
fprintf(stderr, "%s : error: token %d is string %s but bpe returns tokens %s\n",
99100
__func__, i, llama_token_to_str(ctx, i).c_str(), unescape_whitespace(ctx, tokens).c_str());
100101
return 2;
101102
}
@@ -108,7 +109,7 @@ int main(int argc, char **argv) {
108109
std::string str = converter.to_bytes(wstr);
109110
std::vector<llama_token> tokens = llama_tokenize(ctx, escape_whitespace(str).c_str(), false);
110111
if (tokens.size() == 1) {
111-
fprintf(stderr, "%s : info: %s tokenized to %d \n",
112+
fprintf(stderr, "%s : info: %s tokenized to %d \n",
112113
__func__, str.c_str(), tokens[0]);
113114
}
114115
}

0 commit comments

Comments
 (0)