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

Function main

examples/simple/simple.cpp:9–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#include <vector>
8
9int main(int argc, char ** argv) {
10 gpt_params params;
11
12 if (argc == 1 || argv[1][0] == '-') {
13 printf("usage: %s MODEL_PATH [PROMPT]\n" , argv[0]);
14 return 1 ;
15 }
16
17 if (argc >= 2) {
18 params.model = argv[1];
19 }
20
21 if (argc >= 3) {
22 params.prompt = argv[2];
23 }
24
25 if (params.prompt.empty()) {
26 params.prompt = "Hello my name is";
27 }
28
29 // total length of the sequence including the prompt
30 const int n_len = 32;
31
32 // init LLM
33
34 llama_backend_init(params.numa);
35
36 // initialize the model
37
38 llama_model_params model_params = llama_model_default_params();
39
40 // model_params.n_gpu_layers = 99; // offload all layers to the GPU
41
42 llama_model * model = llama_load_model_from_file(params.model.c_str(), model_params);
43
44 if (model == NULL) {
45 fprintf(stderr , "%s: error: unable to load model\n" , __func__);
46 return 1;
47 }
48
49 // initialize the context
50
51 llama_context_params ctx_params = llama_context_default_params();
52
53 ctx_params.seed = 1234;
54 ctx_params.n_ctx = 2048;
55 ctx_params.n_threads = params.n_threads;
56 ctx_params.n_threads_batch = params.n_threads_batch == -1 ? params.n_threads : params.n_threads_batch;
57
58 llama_context * ctx = llama_new_context_with_model(model, ctx_params);
59
60 if (ctx == NULL) {
61 fprintf(stderr , "%s: error: failed to create the llama_context\n" , __func__);
62 return 1;
63 }
64
65 // tokenize the prompt
66

Callers

nothing calls this directly

Calls 15

printfFunction · 0.85
fprintfFunction · 0.85
llama_batch_addFunction · 0.85
llama_batch_clearFunction · 0.85
llama_print_timingsFunction · 0.85
reserveMethod · 0.80
llama_backend_initFunction · 0.50

Tested by

no test coverage detected