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

Method init_batch

subprojects/llama.cpp/src/llama-kv-cache.cpp:513–548  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

511}
512
513llama_memory_context_ptr llama_kv_cache::init_batch(
514 llama_batch_allocr & balloc,
515 uint32_t n_ubatch,
516 bool embd_all) {
517 GGML_UNUSED(embd_all);
518
519 do {
520 balloc.split_reset();
521
522 std::vector<llama_ubatch> ubatches;
523 while (true) {
524 auto ubatch = n_stream == 1 ? balloc.split_simple(n_ubatch) : balloc.split_equal(n_ubatch, true);
525
526 if (ubatch.n_tokens == 0) {
527 break;
528 }
529
530 ubatches.push_back(std::move(ubatch)); // NOLINT
531 }
532
533 if (balloc.get_n_used() < balloc.get_n_tokens()) {
534 // failed to find a suitable split
535 break;
536 }
537
538 auto sinfos = prepare(ubatches);
539 if (sinfos.empty()) {
540 break;
541 }
542
543 return std::make_unique<llama_kv_cache_context>(
544 this, std::move(sinfos), std::move(ubatches));
545 } while (false);
546
547 return std::make_unique<llama_kv_cache_context>(LLAMA_MEMORY_STATUS_FAILED_PREPARE);
548}
549
550llama_memory_context_ptr llama_kv_cache::init_full() {
551 return std::make_unique<llama_kv_cache_context>(this);

Callers 2

decodeMethod · 0.45
opt_epoch_iterMethod · 0.45

Calls 7

split_resetMethod · 0.80
split_simpleMethod · 0.80
split_equalMethod · 0.80
get_n_usedMethod · 0.80
get_n_tokensMethod · 0.80
emptyMethod · 0.65
push_backMethod · 0.45

Tested by

no test coverage detected