MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / main

Function main

tests/test_tokenizer.cpp:31–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29static const int N_CASES = sizeof(CASES) / sizeof(CASES[0]);
30
31int main(int argc, char ** argv) {
32 if (argc < 2) {
33 fprintf(stderr, "Usage: %s <model.ggml>\n", argv[0]);
34 return 1;
35 }
36
37 if (!sam3_test_load_tokenizer(argv[1])) {
38 fprintf(stderr, "FAIL: could not load tokenizer from '%s'\n", argv[1]);
39 return 1;
40 }
41
42 int n_pass = 0;
43 for (int i = 0; i < N_CASES; ++i) {
44 auto tokens = sam3_test_tokenize(CASES[i].text);
45 const auto & exp = CASES[i].expected;
46 bool pass = true;
47
48 // Must be exactly 32 tokens (context length)
49 if ((int)tokens.size() != 32) {
50 fprintf(stderr, "FAIL [%d]: expected 32 tokens, got %d\n", i, (int)tokens.size());
51 pass = false;
52 }
53
54 // Check non-padding prefix matches expected exactly
55 for (size_t j = 0; j < exp.size() && j < tokens.size(); ++j) {
56 if (tokens[j] != exp[j]) {
57 fprintf(stderr, "FAIL [%d]: token[%zu] = %d, expected %d\n",
58 i, j, tokens[j], exp[j]);
59 pass = false;
60 }
61 }
62
63 // Check remaining positions are zero-padded
64 for (size_t j = exp.size(); j < tokens.size(); ++j) {
65 if (tokens[j] != 0) {
66 fprintf(stderr, "FAIL [%d]: expected 0 at position %zu, got %d\n",
67 i, j, tokens[j]);
68 pass = false;
69 break;
70 }
71 }
72
73 // Print result
74 fprintf(stderr, "%s [%d] \"%s\" → [", pass ? "PASS" : "FAIL", i, CASES[i].text);
75 for (size_t j = 0; j < tokens.size(); ++j) {
76 if (j > 0) fprintf(stderr, ", ");
77 fprintf(stderr, "%d", tokens[j]);
78 if (tokens[j] == 0 && j > 1) { fprintf(stderr, ", ..."); break; }
79 }
80 fprintf(stderr, "]\n");
81
82 if (pass) n_pass++;
83 }
84
85 fprintf(stderr, "\n%d/%d tests passed\n", n_pass, N_CASES);
86 return (n_pass == N_CASES) ? 0 : 1;
87}

Callers

nothing calls this directly

Calls 2

sam3_test_load_tokenizerFunction · 0.85
sam3_test_tokenizeFunction · 0.85

Tested by

no test coverage detected