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

Method init_batch

subprojects/llama.cpp/src/llama-memory-recurrent.cpp:378–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

376}
377
378llama_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
417llama_memory_context_ptr llama_memory_recurrent::init_full() {
418 return std::make_unique<llama_memory_recurrent_context>(this);

Callers

nothing calls this directly

Calls 6

split_resetMethod · 0.80
split_seqMethod · 0.80
split_equalMethod · 0.80
get_n_usedMethod · 0.80
get_n_tokensMethod · 0.80
push_backMethod · 0.45

Tested by

no test coverage detected