| 10636 | } |
| 10637 | |
| 10638 | struct llama_batch llama_batch_init(int32_t n_tokens, int32_t embd, int32_t n_seq_max) { |
| 10639 | llama_batch batch = { 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, 0, 0, 0, }; |
| 10640 | |
| 10641 | if (embd) { |
| 10642 | batch.embd = (float *) malloc(sizeof(float) * n_tokens * embd); |
| 10643 | } else { |
| 10644 | batch.token = (llama_token *) malloc(sizeof(llama_token) * n_tokens); |
| 10645 | } |
| 10646 | |
| 10647 | batch.pos = (llama_pos *) malloc(sizeof(llama_pos) * n_tokens); |
| 10648 | batch.n_seq_id = (int32_t *) malloc(sizeof(int32_t) * n_tokens); |
| 10649 | batch.seq_id = (llama_seq_id **) malloc(sizeof(llama_seq_id *) * n_tokens); |
| 10650 | for (int i = 0; i < n_tokens; ++i) { |
| 10651 | batch.seq_id[i] = (llama_seq_id *) malloc(sizeof(llama_seq_id) * n_seq_max); |
| 10652 | } |
| 10653 | batch.logits = (int8_t *) malloc(sizeof(int8_t) * n_tokens); |
| 10654 | |
| 10655 | return batch; |
| 10656 | } |
| 10657 | |
| 10658 | void llama_batch_free(struct llama_batch batch) { |
| 10659 | if (batch.token) free(batch.token); |