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

Function main

smallthinker/examples/parallel/parallel.cpp:155–502  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153}
154
155int main(int argc, char ** argv) {
156 srand(1234);
157
158 common_params params;
159
160 params.n_predict = 128;
161 params.n_junk = 1;
162
163 if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_PARALLEL)) {
164 return 1;
165 }
166
167 common_init();
168
169 // number of simultaneous "clients" to simulate
170 const int32_t n_clients = params.n_parallel;
171
172 // dedicate one sequence to the system prompt
173 params.n_parallel += 1;
174
175 // requests to simulate
176 const int32_t n_seq = params.n_sequences;
177
178 // insert new requests as soon as the previous one is done
179 const bool cont_batching = params.cont_batching;
180
181 // is the system prompt shared in the cache
182 const bool is_sp_shared = params.is_pp_shared;
183
184 // extra text to insert in each client's prompt in order to make it larger
185 const int32_t n_junk = std::max(1, params.n_junk);
186
187 // init llama.cpp
188 llama_backend_init();
189 llama_numa_init(params.numa);
190
191 // load the target model
192 common_init_result llama_init = common_init_from_params(params);
193
194 llama_model * model = llama_init.model.get();
195 llama_context * ctx = llama_init.context.get();
196
197 const llama_vocab * vocab = llama_model_get_vocab(model);
198
199 // load the prompts from an external file if there are any
200 if (params.prompt.empty()) {
201 LOG_INF("\033[32mNo new questions so proceed with build-in defaults.\033[0m\n");
202 } else {
203 // Output each line of the input params.prompts vector and copy to k_prompts
204 int index = 0;
205 LOG_INF("\033[32mNow printing the external prompt file %s\033[0m\n\n", params.prompt_file.c_str());
206
207 std::vector<std::string> prompts = split_string(params.prompt, '\n');
208 for (const auto& prompt : prompts) {
209 k_prompts.resize(index + 1);
210 k_prompts[index] = prompt;
211 index++;
212 LOG_INF("%3d prompt: %s\n", index, prompt.c_str());

Callers

nothing calls this directly

Calls 15

common_params_parseFunction · 0.85
common_initFunction · 0.85
maxFunction · 0.85
llama_numa_initFunction · 0.85
common_init_from_paramsFunction · 0.85
llama_model_get_vocabFunction · 0.85
common_sampler_initFunction · 0.85
common_tokenizeFunction · 0.85
common_batch_addFunction · 0.85
llama_kv_self_seq_cpFunction · 0.85
common_batch_clearFunction · 0.85
llama_kv_self_seq_rmFunction · 0.85

Tested by

no test coverage detected