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

Function main

examples/embedding/embedding.cpp:10–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#endif
9
10int main(int argc, char ** argv) {
11 gpt_params params;
12
13 if (!gpt_params_parse(argc, argv, params)) {
14 return 1;
15 }
16
17 params.embedding = true;
18
19 print_build_info();
20
21 if (params.seed == LLAMA_DEFAULT_SEED) {
22 params.seed = time(NULL);
23 }
24
25 fprintf(stderr, "%s: seed = %u\n", __func__, params.seed);
26
27 std::mt19937 rng(params.seed);
28 if (params.random_prompt) {
29 params.prompt = gpt_random_prompt(rng);
30 }
31
32 llama_backend_init(params.numa);
33
34 llama_model * model;
35 llama_context * ctx;
36
37 // load the model
38 std::tie(model, ctx) = llama_init_from_gpt_params(params);
39 if (model == NULL) {
40 fprintf(stderr, "%s: error: unable to load model\n", __func__);
41 return 1;
42 }
43
44 const int n_ctx_train = llama_n_ctx_train(model);
45 const int n_ctx = llama_n_ctx(ctx);
46
47 if (n_ctx > n_ctx_train) {
48 fprintf(stderr, "%s: warning: model was trained on only %d context tokens (%d specified)\n",
49 __func__, n_ctx_train, n_ctx);
50 }
51
52 // print system information
53 {
54 fprintf(stderr, "\n");
55 fprintf(stderr, "%s\n", get_system_info(params).c_str());
56 }
57
58 int n_past = 0;
59
60 // tokenize the prompt
61 auto embd_inp = ::llama_tokenize(ctx, params.prompt, true);
62
63 if (params.verbose_prompt) {
64 fprintf(stderr, "\n");
65 fprintf(stderr, "%s: prompt: '%s'\n", __func__, params.prompt.c_str());
66 fprintf(stderr, "%s: number of tokens in prompt = %zu\n", __func__, embd_inp.size());
67 for (int i = 0; i < (int) embd_inp.size(); i++) {

Callers

nothing calls this directly

Calls 15

gpt_params_parseFunction · 0.85
fprintfFunction · 0.85
gpt_random_promptFunction · 0.85
get_system_infoFunction · 0.85
minFunction · 0.85
printfFunction · 0.85
llama_print_timingsFunction · 0.85
llama_backend_initFunction · 0.50
llama_n_ctx_trainFunction · 0.50
llama_n_ctxFunction · 0.50
llama_tokenizeFunction · 0.50

Tested by

no test coverage detected