MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / init

Method init

subprojects/llama.cpp/src/llama-batch.cpp:25–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25bool llama_batch_allocr::init(
26 const llama_batch & batch_inp,
27 const llama_vocab & vocab,
28 const llama_memory_i * memory,
29 uint32_t n_embd,
30 uint32_t n_seq_max,
31 bool output_all) {
32 clear();
33
34 batch = batch_inp;
35
36 this->vocab = &vocab;
37
38 GGML_ASSERT(batch.n_tokens > 0);
39
40 //
41 // validate input batch
42 //
43
44 if (n_seq_max > LLAMA_MAX_SEQ) {
45 LLAMA_LOG_ERROR("%s: n_seq_max = %d > %d\n", __func__, n_seq_max, LLAMA_MAX_SEQ);
46 return false;
47 }
48
49 if (batch.token) {
50 for (int32_t i = 0; i < batch.n_tokens; ++i) {
51 if (batch.token[i] < 0 || (uint32_t) batch.token[i] >= vocab.n_tokens()) {
52 LLAMA_LOG_ERROR("%s: invalid token[%d] = %d\n", __func__, i, batch.token[i]);
53 return false;
54 }
55 }
56 }
57
58 if (batch.seq_id) {
59 for (int32_t i = 0; i < batch.n_tokens; ++i) {
60 for (int32_t s = 0; s < batch.n_seq_id[i]; ++s) {
61 if (batch.seq_id && (batch.seq_id[i][s] < 0 || batch.seq_id[i][s] >= (llama_seq_id) n_seq_max)) {
62 LLAMA_LOG_ERROR("%s: invalid seq_id[%d][%d] = %d >= %d\n", __func__, i, s, batch.seq_id[i][s], (llama_seq_id) n_seq_max);
63 return false;
64 }
65 }
66 }
67 }
68
69 //
70 // auto-generate missing fields
71 //
72
73 if (!batch.n_seq_id) {
74 n_seq_id.resize(batch.n_tokens);
75 for (int32_t i = 0; i < batch.n_tokens; i++) {
76 n_seq_id[i] = seq_id_0.size();
77 }
78 batch.n_seq_id = n_seq_id.data();
79 }
80
81 if (!batch.seq_id) {
82 seq_id.resize(batch.n_tokens + 1);

Callers

nothing calls this directly

Calls 12

sizeMethod · 0.65
setMethod · 0.65
testMethod · 0.65
emptyMethod · 0.65
n_tokensMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45
seq_pos_maxMethod · 0.45
insertMethod · 0.45
push_backMethod · 0.45
strMethod · 0.45
seq_pos_minMethod · 0.45

Tested by

no test coverage detected