MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / ubatch_add

Method ubatch_add

src/llama-batch.cpp:681–776  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

679}
680
681llama_ubatch llama_batch_allocr::ubatch_add(const std::vector<int32_t> & idxs, uint32_t n_seqs, bool equal_seqs) {
682 const uint32_t n_tokens = idxs.size();
683
684 assert(n_tokens%n_seqs == 0);
685
686 auto udata = std::make_shared<llama_ubatch::data_t>();
687
688 const int64_t n_embd_all = batch.embd ? (int64_t) n_tokens*n_embd : 0;
689 const int64_t n_pos_all = (int64_t) n_tokens*n_pos_per_embd;
690
691 udata->token .resize(n_tokens);
692 udata->embd .resize(n_embd_all);
693 udata->pos .resize(n_pos_all);
694 udata->n_seq_id .resize(n_tokens);
695 udata->seq_id .resize(n_tokens);
696 udata->seq_id_unq.resize(0);
697 udata->seq_idx .resize(LLAMA_MAX_SEQ, -1);
698 udata->output .resize(n_tokens);
699
700 udata->seq_id_data.reserve(n_tokens);
701
702 seq_set_t seq_set_unq;
703
704 for (size_t i = 0; i < idxs.size(); ++i) {
705 if (batch.token) {
706 udata->token[i] = batch.token[idxs[i]];
707 }
708
709 if (batch.embd) {
710 memcpy(udata->embd.data() + i*n_embd, batch.embd + (int64_t) idxs[i]*n_embd, n_embd*sizeof(float));
711 }
712
713 for (size_t j = 0; j < (size_t)n_pos_per_embd; ++j) {
714 // if we are using M-RoPE
715 // if the current batch is text, we need to broadcast the same position across all RoPE sections
716 // otherwise, the input batch is image embeddings, we copy the positions as-is
717 // if we are not using M-RoPE, there is only one position per token (this loop runs only once)
718 size_t src_off = batch.token ? 0 : j*batch.n_tokens;
719 udata->pos[j*n_tokens + i] = batch.pos[src_off + idxs[i]];
720 }
721
722 udata->n_seq_id[i] = batch.n_seq_id[idxs[i]];
723 udata->output[i] = batch.logits[idxs[i]];
724
725 for (int s = 0; s < udata->n_seq_id[i]; ++s) {
726 const llama_seq_id seq_id = batch.seq_id[idxs[i]][s];
727
728 udata->seq_id_data.push_back(seq_id);
729 seq_set_unq.set(seq_id);
730 }
731
732 if (udata->output[i]) {
733 out_ids.push_back(idxs[i]);
734 }
735 }
736
737 llama_seq_id * seq_id_ptr = udata->seq_id_data.data();
738 for (size_t i = 0; i < idxs.size(); ++i) {

Callers

nothing calls this directly

Calls 6

sizeMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45
push_backMethod · 0.45
setMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected