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

Function llama_batch_init

smallthinker/src/llama-batch.cpp:339–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337}
338
339struct llama_batch llama_batch_init(int32_t n_tokens_alloc, int32_t embd, int32_t n_seq_max) {
340 llama_batch batch = {
341 /*n_tokens =*/ 0,
342 /*tokens =*/ nullptr,
343 /*embd =*/ nullptr,
344 /*pos =*/ nullptr,
345 /*n_seq_id =*/ nullptr,
346 /*seq_id =*/ nullptr,
347 /*logits =*/ nullptr,
348 };
349
350 if (embd) {
351 batch.embd = (float *) malloc(sizeof(float) * n_tokens_alloc * embd);
352 } else {
353 batch.token = (llama_token *) malloc(sizeof(llama_token) * n_tokens_alloc);
354 }
355
356 batch.pos = (llama_pos *) malloc(sizeof(llama_pos) * n_tokens_alloc);
357 batch.n_seq_id = (int32_t *) malloc(sizeof(int32_t) * n_tokens_alloc);
358 batch.seq_id = (llama_seq_id **) malloc(sizeof(llama_seq_id *) * (n_tokens_alloc + 1));
359 for (int i = 0; i < n_tokens_alloc; ++i) {
360 batch.seq_id[i] = (llama_seq_id *) malloc(sizeof(llama_seq_id) * n_seq_max);
361 }
362 batch.seq_id[n_tokens_alloc] = nullptr;
363
364 batch.logits = (int8_t *) malloc(sizeof(int8_t) * n_tokens_alloc);
365
366 return batch;
367}
368
369void llama_batch_free(struct llama_batch batch) {
370 if (batch.token) free(batch.token);

Callers 15

opt_epochMethod · 0.70
mainFunction · 0.50
mtmd_cli_contextMethod · 0.50
mainFunction · 0.50
perplexity_v2Function · 0.50
perplexityFunction · 0.50
hellaswag_scoreFunction · 0.50
winogrande_scoreFunction · 0.50
multiple_choice_scoreFunction · 0.50
kl_divergenceFunction · 0.50
initMethod · 0.50

Calls

no outgoing calls

Tested by 3

common_speculative_initFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40