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

Function batch_process

examples/retrieval/retrieval.cpp:85–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85static void batch_process(llama_context * ctx, llama_batch & batch, float * output, int n_seq, int n_embd) {
86 // clear previous kv_cache values (irrelevant for embeddings)
87 llama_memory_clear(llama_get_memory(ctx), false);
88
89 // run model
90 LOG_INF("%s: n_tokens = %d, n_seq = %d\n", __func__, batch.n_tokens, n_seq);
91 if (llama_decode(ctx, batch) < 0) {
92 LOG_ERR("%s : failed to process\n", __func__);
93 }
94
95 for (int i = 0; i < batch.n_tokens; i++) {
96 if (!batch.logits[i]) {
97 continue;
98 }
99
100 // try to get sequence embeddings - supported only when pooling_type is not NONE
101 const float * embd = llama_get_embeddings_seq(ctx, batch.seq_id[i][0]);
102 if (embd == NULL) {
103 embd = llama_get_embeddings_ith(ctx, i);
104 if (embd == NULL) {
105 LOG_ERR("%s: failed to get embeddings for token %d\n", __func__, i);
106 continue;
107 }
108 }
109
110 float * out = output + batch.seq_id[i][0] * n_embd;
111 common_embd_normalize(embd, out, n_embd, 2);
112 }
113}
114
115int main(int argc, char ** argv) {
116 std::setlocale(LC_NUMERIC, "C");

Callers 1

mainFunction · 0.85

Calls 6

llama_memory_clearFunction · 0.85
llama_get_memoryFunction · 0.85
llama_decodeFunction · 0.85
llama_get_embeddings_seqFunction · 0.85
llama_get_embeddings_ithFunction · 0.85
common_embd_normalizeFunction · 0.85

Tested by

no test coverage detected