MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / init_batch

Method init_batch

smallthinker/src/llama-kv-cache-recurrent.cpp:358–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

356}
357
358llama_memory_state_ptr llama_kv_cache_recurrent::init_batch(const llama_batch & batch, uint32_t n_ubatch, bool embd_pooled, bool logits_all) {
359 GGML_UNUSED(embd_pooled);
360
361 auto sbatch = llama_sbatch(batch, hparams.n_embd, false, logits_all);
362
363 std::vector<llama_ubatch> ubatches;
364
365 while (sbatch.n_tokens > 0) {
366 llama_ubatch ubatch;
367
368 if (embd_pooled) {
369 // Pooled embeddings cannot be split across ubatches (yet)
370 ubatch = sbatch.split_seq(n_ubatch);
371 } else {
372 ubatch = sbatch.split_equal(n_ubatch);
373 }
374
375 ubatches.push_back(ubatch);
376 }
377
378 if (!prepare(ubatches)) {
379 return std::make_unique<llama_kv_cache_recurrent_state>(LLAMA_MEMORY_STATUS_FAILED_PREPARE);
380 }
381
382 return std::make_unique<llama_kv_cache_recurrent_state>(LLAMA_MEMORY_STATUS_SUCCESS, this, std::move(sbatch), std::move(ubatches));
383}
384
385llama_memory_state_ptr llama_kv_cache_recurrent::init_full() {
386 return std::make_unique<llama_kv_cache_recurrent_state>(LLAMA_MEMORY_STATUS_SUCCESS, this);

Callers

nothing calls this directly

Calls 4

llama_sbatchClass · 0.85
split_seqMethod · 0.80
split_equalMethod · 0.80
push_backMethod · 0.45

Tested by

no test coverage detected