File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -503,3 +503,49 @@ void llama_batch_ext_free(struct llama_batch_ext * batch) {
503503 }
504504 delete batch;
505505}
506+
507+ // deprecated
508+ struct llama_batch llama_batch_init (int32_t n_tokens_alloc, int32_t embd, int32_t n_seq_max) {
509+ llama_batch batch = {
510+ /* n_tokens =*/ 0 ,
511+ /* tokens =*/ nullptr ,
512+ /* embd =*/ nullptr ,
513+ /* pos =*/ nullptr ,
514+ /* n_seq_id =*/ nullptr ,
515+ /* seq_id =*/ nullptr ,
516+ /* logits =*/ nullptr ,
517+ };
518+
519+ if (embd) {
520+ batch.embd = (float *) malloc (sizeof (float ) * n_tokens_alloc * embd);
521+ } else {
522+ batch.token = (llama_token *) malloc (sizeof (llama_token) * n_tokens_alloc);
523+ }
524+
525+ batch.pos = (llama_pos *) malloc (sizeof (llama_pos) * n_tokens_alloc);
526+ batch.n_seq_id = (int32_t *) malloc (sizeof (int32_t ) * n_tokens_alloc);
527+ batch.seq_id = (llama_seq_id **) malloc (sizeof (llama_seq_id *) * (n_tokens_alloc + 1 ));
528+ for (int i = 0 ; i < n_tokens_alloc; ++i) {
529+ batch.seq_id [i] = (llama_seq_id *) malloc (sizeof (llama_seq_id) * n_seq_max);
530+ }
531+ batch.seq_id [n_tokens_alloc] = nullptr ;
532+
533+ batch.logits = (int8_t *) malloc (sizeof (int8_t ) * n_tokens_alloc);
534+
535+ return batch;
536+ }
537+
538+ // deprecated
539+ void llama_batch_free (struct llama_batch batch) {
540+ if (batch.token ) free (batch.token );
541+ if (batch.embd ) free (batch.embd );
542+ if (batch.pos ) free (batch.pos );
543+ if (batch.n_seq_id ) free (batch.n_seq_id );
544+ if (batch.seq_id ) {
545+ for (int i = 0 ; batch.seq_id [i] != nullptr ; ++i) {
546+ free (batch.seq_id [i]);
547+ }
548+ free (batch.seq_id );
549+ }
550+ if (batch.logits ) free (batch.logits );
551+ }
You can’t perform that action at this time.
0 commit comments