| 15 | } |
| 16 | |
| 17 | int main(int argc, char ** argv) { |
| 18 | common_params params; |
| 19 | |
| 20 | params.prompt = "Hello my name is"; |
| 21 | params.n_predict = 32; |
| 22 | |
| 23 | if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_COMMON, print_usage)) { |
| 24 | return 1; |
| 25 | } |
| 26 | |
| 27 | common_init(); |
| 28 | |
| 29 | // number of parallel batches |
| 30 | int n_parallel = params.n_parallel; |
| 31 | |
| 32 | // total length of the sequences including the prompt |
| 33 | int n_predict = params.n_predict; |
| 34 | |
| 35 | // init LLM |
| 36 | |
| 37 | llama_backend_init(); |
| 38 | llama_numa_init(params.numa); |
| 39 | |
| 40 | // initialize the model |
| 41 | |
| 42 | llama_model_params model_params = common_model_params_to_llama(params); |
| 43 | |
| 44 | llama_model * model = llama_model_load_from_file(params.model.path.c_str(), model_params); |
| 45 | |
| 46 | if (model == NULL) { |
| 47 | LOG_ERR("%s: error: unable to load model\n" , __func__); |
| 48 | return 1; |
| 49 | } |
| 50 | |
| 51 | const llama_vocab * vocab = llama_model_get_vocab(model); |
| 52 | |
| 53 | // tokenize the prompt |
| 54 | |
| 55 | std::vector<llama_token> tokens_list; |
| 56 | tokens_list = common_tokenize(vocab, params.prompt, true); |
| 57 | |
| 58 | const int n_kv_req = tokens_list.size() + (n_predict - tokens_list.size())*n_parallel; |
| 59 | |
| 60 | // initialize the context |
| 61 | |
| 62 | llama_context_params ctx_params = common_context_params_to_llama(params); |
| 63 | |
| 64 | ctx_params.n_ctx = n_kv_req; |
| 65 | ctx_params.n_batch = std::max(n_predict, n_parallel); |
| 66 | |
| 67 | llama_context * ctx = llama_init_from_model(model, ctx_params); |
| 68 | |
| 69 | auto sparams = llama_sampler_chain_default_params(); |
| 70 | sparams.no_perf = false; |
| 71 | |
| 72 | llama_sampler * smpl = llama_sampler_chain_init(sparams); |
| 73 | |
| 74 | llama_sampler_chain_add(smpl, llama_sampler_init_top_k(params.sampling.top_k)); |
nothing calls this directly
no test coverage detected