Skip to content

Commit a06e82b

Browse files
committed
Restrict bpe tokenizer tests to unicode planes
1 parent 226f0a8 commit a06e82b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tests/test-tokenizer-1-bpe.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,17 @@ int main(int argc, char **argv) {
9393
}
9494
// TODO: why doesn't this work for the full range of Unicodes?
9595
// for (uint32_t cp = 0x10000; cp < 0x0010ffff; ++cp) {
96-
for (uint32_t cp = 0x10000; cp < 0x00080000; ++cp) {
96+
for (uint32_t cp = 0x10000; cp < 0x00040000; ++cp) {
97+
std::string str = codepoint_to_utf8(cp);
98+
std::vector<llama_token> tokens = llama_tokenize(ctx, str, false);
99+
std::string check = llama_detokenize_bpe(ctx, tokens);
100+
if (str != check) {
101+
fprintf(stderr, "%s : error: codepoint %x detokenizes to '%s'(%zu) instead of '%s'(%zu)\n",
102+
__func__, cp, check.c_str(), check.length(), str.c_str(), str.length());
103+
return 4;
104+
}
105+
}
106+
for (uint32_t cp = 0x000e0000; cp < 0x0010ffff; ++cp) {
97107
std::string str = codepoint_to_utf8(cp);
98108
std::vector<llama_token> tokens = llama_tokenize(ctx, str, false);
99109
std::string check = llama_detokenize_bpe(ctx, tokens);
@@ -103,7 +113,6 @@ int main(int argc, char **argv) {
103113
return 4;
104114
}
105115
}
106-
107116
llama_free_model(model);
108117
llama_free(ctx);
109118

0 commit comments

Comments
 (0)