MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / main

Function main

subprojects/llama.cpp/tests/test-tokenizer-1-spm.cpp:17–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15#include <atomic>
16
17int main(int argc, char ** argv) {
18 if (argc < 2) {
19 fprintf(stderr, "Usage: %s <vocab-file>\n", argv[0]);
20 return 1;
21 }
22
23 const std::string fname = argv[1];
24
25 fprintf(stderr, "%s : reading vocab from: '%s'\n", __func__, fname.c_str());
26
27 llama_model * model;
28 llama_context * ctx;
29
30 llama_backend_init();
31
32 // load the vocab
33 {
34 auto mparams = llama_model_default_params();
35
36 mparams.vocab_only = true;
37
38 model = llama_model_load_from_file(fname.c_str(), mparams);
39
40 if (model == NULL) {
41 fprintf(stderr, "%s: error: failed to load vocab '%s'\n", __func__, fname.c_str());
42 return 1;
43 }
44
45 auto cparams = llama_context_default_params();
46
47 ctx = llama_init_from_model(model, cparams);
48
49 if (ctx == NULL) {
50 fprintf(stderr, "%s: error: failed to load vocab '%s'\n", __func__, fname.c_str());
51 llama_model_free(model);
52 return 1;
53 }
54 }
55
56 const llama_vocab * vocab = llama_model_get_vocab(model);
57
58 //GGML_ASSERT(llama_vocab_type(model) == LLAMA_VOCAB_TYPE_SPM);
59 if (llama_vocab_type(vocab) != LLAMA_VOCAB_TYPE_SPM) {
60 return 99;
61 }
62
63#ifdef _WIN32
64 // We need this for unicode console support
65 console::init(false, false);
66 atexit([]() { console::cleanup(); });
67#endif
68
69 const int n_vocab = llama_vocab_n_tokens(vocab);
70
71 for (int i = 0; i < n_vocab; ++i) {
72 std::string str = common_detokenize(ctx, std::vector<int>(1, i), true);
73 std::vector<llama_token> tokens = common_tokenize(ctx, str, false, true);
74 std::string check = common_detokenize(ctx, tokens);

Callers

nothing calls this directly

Calls 15

llama_backend_initFunction · 0.85
llama_init_from_modelFunction · 0.85
llama_model_freeFunction · 0.85
llama_model_get_vocabFunction · 0.85
cleanupFunction · 0.85
llama_vocab_n_tokensFunction · 0.85
common_detokenizeFunction · 0.85
common_tokenizeFunction · 0.85
unicode_cpt_to_utf8Function · 0.85

Tested by

no test coverage detected