summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalunid <karolek1231456@gmail.com>2023-10-24 09:17:17 +0200
committerGitHub <noreply@github.com>2023-10-24 09:17:17 +0200
commitdaab3d7f45832e10773c99f3484b0d5b14d86c0c (patch)
tree432092c5aec7c775ab6e33b968564bd0a1e4a187
parent469c9addef75893e6be12edda852d12e840bf064 (diff)
Add more tokenizer tests (#3742)
* Add more tokenizer tests * Add starcoder * Update test vocab files * Restrict bpe tokenizer tests to unicode planes * Update comment * Comment cosmetics * Remove bloom vocab/test
-rw-r--r--models/ggml-vocab-baichuan.ggufbin0 -> 1340998 bytes
-rw-r--r--models/ggml-vocab-gpt-neox.ggufbin0 -> 1771431 bytes
-rw-r--r--models/ggml-vocab-refact.ggufbin0 -> 1720666 bytes
-rw-r--r--models/ggml-vocab-starcoder.ggufbin0 -> 1719281 bytes
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/test-tokenizer-1-bpe.cpp15
6 files changed, 16 insertions, 3 deletions
diff --git a/models/ggml-vocab-baichuan.gguf b/models/ggml-vocab-baichuan.gguf
new file mode 100644
index 00000000..7caaf823
--- /dev/null
+++ b/models/ggml-vocab-baichuan.gguf
Binary files differ
diff --git a/models/ggml-vocab-gpt-neox.gguf b/models/ggml-vocab-gpt-neox.gguf
new file mode 100644
index 00000000..b9af1684
--- /dev/null
+++ b/models/ggml-vocab-gpt-neox.gguf
Binary files differ
diff --git a/models/ggml-vocab-refact.gguf b/models/ggml-vocab-refact.gguf
new file mode 100644
index 00000000..8f26cfb7
--- /dev/null
+++ b/models/ggml-vocab-refact.gguf
Binary files differ
diff --git a/models/ggml-vocab-starcoder.gguf b/models/ggml-vocab-starcoder.gguf
new file mode 100644
index 00000000..a52983fd
--- /dev/null
+++ b/models/ggml-vocab-starcoder.gguf
Binary files differ
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 1c73de0a..6757ad1c 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -28,10 +28,14 @@ llama_build_executable(test-tokenizer-0-falcon.cpp)
llama_test_executable (test-tokenizer-0-falcon test-tokenizer-0-falcon.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-falcon.gguf)
llama_build_executable(test-tokenizer-1-llama.cpp)
llama_test_executable (test-tokenizer-1-llama test-tokenizer-1-llama.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-llama.gguf)
+llama_test_executable(test-tokenizer-1-baichuan test-tokenizer-1-llama.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-baichuan.gguf)
llama_build_executable(test-tokenizer-1-bpe.cpp)
llama_test_executable (test-tokenizer-1-falcon test-tokenizer-1-bpe.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-falcon.gguf)
llama_test_executable(test-tokenizer-1-aquila test-tokenizer-1-bpe.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-aquila.gguf)
llama_test_executable(test-tokenizer-1-mpt test-tokenizer-1-bpe.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-mpt.gguf)
+llama_test_executable(test-tokenizer-1-gpt-neox test-tokenizer-1-bpe.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-gpt-neox.gguf)
+llama_test_executable(test-tokenizer-1-refact test-tokenizer-1-bpe.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-refact.gguf)
+llama_test_executable(test-tokenizer-1-starcoder test-tokenizer-1-bpe.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-starcoder.gguf)
llama_build_and_test_executable(test-grammar-parser.cpp)
llama_build_and_test_executable(test-llama-grammar.cpp)
llama_build_and_test_executable(test-grad0.cpp) # SLOW
diff --git a/tests/test-tokenizer-1-bpe.cpp b/tests/test-tokenizer-1-bpe.cpp
index 85a59a14..386530f2 100644
--- a/tests/test-tokenizer-1-bpe.cpp
+++ b/tests/test-tokenizer-1-bpe.cpp
@@ -91,9 +91,19 @@ int main(int argc, char **argv) {
}
}
}
- // TODO: why doesn't this work for the full range of Unicodes?
+ // Restrict to assigned unicode planes
// for (uint32_t cp = 0x10000; cp < 0x0010ffff; ++cp) {
- for (uint32_t cp = 0x10000; cp < 0x00080000; ++cp) {
+ for (uint32_t cp = 0x10000; cp < 0x00040000; ++cp) {
+ std::string str = codepoint_to_utf8(cp);
+ std::vector<llama_token> tokens = llama_tokenize(ctx, str, false);
+ std::string check = llama_detokenize_bpe(ctx, tokens);
+ if (str != check) {
+ fprintf(stderr, "%s : error: codepoint %x detokenizes to '%s'(%zu) instead of '%s'(%zu)\n",
+ __func__, cp, check.c_str(), check.length(), str.c_str(), str.length());
+ return 4;
+ }
+ }
+ for (uint32_t cp = 0x000e0000; cp < 0x0010ffff; ++cp) {
std::string str = codepoint_to_utf8(cp);
std::vector<llama_token> tokens = llama_tokenize(ctx, str, false);
std::string check = llama_detokenize_bpe(ctx, tokens);
@@ -103,7 +113,6 @@ int main(int argc, char **argv) {
return 4;
}
}
-
llama_free_model(model);
llama_free(ctx);