| 23 | } |
| 24 | |
| 25 | bool 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); |
nothing calls this directly
no test coverage detected