| 376 | } |
| 377 | |
| 378 | llama_memory_context_ptr llama_memory_recurrent::init_batch(llama_batch_allocr & balloc, uint32_t n_ubatch, bool embd_all) { |
| 379 | do { |
| 380 | balloc.split_reset(); |
| 381 | |
| 382 | std::vector<llama_ubatch> ubatches; |
| 383 | while (true) { |
| 384 | llama_ubatch ubatch; |
| 385 | |
| 386 | if (embd_all) { |
| 387 | // if all tokens are output, split by sequence |
| 388 | ubatch = balloc.split_seq(n_ubatch); |
| 389 | } else { |
| 390 | // TODO: non-sequential equal split can be done if using unified KV cache |
| 391 | // for simplicity, we always use sequential equal split for now |
| 392 | ubatch = balloc.split_equal(n_ubatch, true); |
| 393 | } |
| 394 | |
| 395 | if (ubatch.n_tokens == 0) { |
| 396 | break; |
| 397 | } |
| 398 | |
| 399 | ubatches.push_back(std::move(ubatch)); // NOLINT |
| 400 | } |
| 401 | |
| 402 | if (balloc.get_n_used() < balloc.get_n_tokens()) { |
| 403 | // failed to find a suitable split |
| 404 | break; |
| 405 | } |
| 406 | |
| 407 | if (!prepare(ubatches)) { |
| 408 | break; |
| 409 | } |
| 410 | |
| 411 | return std::make_unique<llama_memory_recurrent_context>(this, std::move(ubatches)); |
| 412 | } while (false); |
| 413 | |
| 414 | return std::make_unique<llama_memory_recurrent_context>(LLAMA_MEMORY_STATUS_FAILED_PREPARE); |
| 415 | } |
| 416 | |
| 417 | llama_memory_context_ptr llama_memory_recurrent::init_full() { |
| 418 | return std::make_unique<llama_memory_recurrent_context>(this); |
nothing calls this directly
no test coverage detected