MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / main

Function main

smallthinker/examples/passkey/passkey.cpp:18–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18int main(int argc, char ** argv) {
19 common_params params;
20
21 params.n_junk = 250;
22 params.n_keep = 32;
23 params.i_pos = -1;
24
25 if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_PASSKEY, print_usage)) {
26 return 1;
27 }
28
29 common_init();
30
31 int n_junk = params.n_junk;
32 int n_keep = params.n_keep;
33 int n_grp = params.grp_attn_n;
34 int i_pos = params.i_pos;
35
36 if (i_pos == -1) {
37 i_pos = rand() % n_junk;
38 }
39
40 const std::string prompt_prefix = "There is an important info hidden inside a lot of irrelevant text. Find it and memorize them. I will quiz you about the important information there.";
41 const std::string prompt_suffix = " What is the pass key? The pass key is";
42
43 // generate junk text
44 params.prompt = prompt_prefix;
45
46 const int passkey = rand() % 50000 + 1;
47
48 for (int i = 0; i < n_junk; i++) {
49 if (i % n_junk == i_pos) {
50 params.prompt += " The pass key is " + std::to_string(passkey) + ". Remember it. " + std::to_string(passkey) + " is the pass key.";
51 }
52
53 params.prompt += " The grass is green. The sky is blue. The sun is yellow. Here we go. There and back again.";
54 }
55
56 params.prompt += prompt_suffix;
57
58 // init LLM
59
60 llama_backend_init();
61 llama_numa_init(params.numa);
62
63 // initialize the model
64
65 llama_model_params model_params = common_model_params_to_llama(params);
66
67 llama_model * model = llama_model_load_from_file(params.model.path.c_str(), model_params);
68
69 if (model == NULL) {
70 LOG_ERR("%s: unable to load model\n" , __func__);
71 return 1;
72 }
73
74 const llama_vocab * vocab = llama_model_get_vocab(model);
75

Callers

nothing calls this directly

Calls 15

common_params_parseFunction · 0.85
common_initFunction · 0.85
llama_numa_initFunction · 0.85
llama_model_get_vocabFunction · 0.85
llama_model_n_ctx_trainFunction · 0.85
llama_init_from_modelFunction · 0.85
llama_sampler_chain_initFunction · 0.85
llama_sampler_chain_addFunction · 0.85

Tested by

no test coverage detected