for multiple images processing
| 1289 | |
| 1290 | // for multiple images processing |
| 1291 | bool ingest_images(llama_client_slot &slot, int n_batch) |
| 1292 | { |
| 1293 | int image_idx = 0; |
| 1294 | |
| 1295 | while (image_idx < (int) slot.images.size()) |
| 1296 | { |
| 1297 | slot_image &img = slot.images[image_idx]; |
| 1298 | |
| 1299 | // process prefix prompt |
| 1300 | for (int32_t i = 0; i < (int32_t) batch.n_tokens; i += n_batch) |
| 1301 | { |
| 1302 | const int32_t n_tokens = std::min(n_batch, (int32_t) (batch.n_tokens - i)); |
| 1303 | llama_batch batch_view = { |
| 1304 | n_tokens, |
| 1305 | batch.token + i, |
| 1306 | nullptr, |
| 1307 | batch.pos + i, |
| 1308 | batch.n_seq_id + i, |
| 1309 | batch.seq_id + i, |
| 1310 | batch.logits + i, |
| 1311 | 0, 0, 0, // unused |
| 1312 | }; |
| 1313 | if (llama_decode(ctx, batch_view)) |
| 1314 | { |
| 1315 | LOG_TEE("%s : failed to eval\n", __func__); |
| 1316 | return false; |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | // process image with llm |
| 1321 | for (int i = 0; i < img.image_tokens; i += n_batch) |
| 1322 | { |
| 1323 | int n_eval = img.image_tokens - i; |
| 1324 | if (n_eval > n_batch) |
| 1325 | { |
| 1326 | n_eval = n_batch; |
| 1327 | } |
| 1328 | |
| 1329 | const int n_embd = llama_n_embd(model); |
| 1330 | llama_batch batch_img = { n_eval, nullptr, (img.image_embedding + i * n_embd), nullptr, nullptr, nullptr, nullptr, slot.n_past, 1, 0, }; |
| 1331 | if (llama_decode(ctx, batch_img)) |
| 1332 | { |
| 1333 | LOG_TEE("%s : failed to eval image\n", __func__); |
| 1334 | return false; |
| 1335 | } |
| 1336 | slot.n_past += n_eval; |
| 1337 | } |
| 1338 | image_idx++; |
| 1339 | |
| 1340 | llama_batch_clear(batch); |
| 1341 | |
| 1342 | // append prefix of next image |
| 1343 | const auto json_prompt = (image_idx >= (int) slot.images.size()) ? |
| 1344 | slot.params.input_suffix : // no more images, then process suffix prompt |
| 1345 | (json)(slot.images[image_idx].prefix_prompt); |
| 1346 | |
| 1347 | std::vector<llama_token> append_tokens = tokenize(json_prompt, false); // has next image |
| 1348 | for (int i = 0; i < (int) append_tokens.size(); ++i) |
nothing calls this directly
no test coverage detected