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

Method process_ubatch

smallthinker/src/llama-context.cpp:654–702  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

652}
653
654llm_graph_result_ptr llama_context::process_ubatch(const llama_ubatch & ubatch, llm_graph_type gtype, llama_memory_state_i * mstate, ggml_status & ret) {
655 if (mstate && !mstate->apply()) {
656 LLAMA_LOG_ERROR("%s: failed to apply memory state\n", __func__);
657 ret = GGML_STATUS_FAILED;
658 return nullptr;
659 }
660
661 auto * gf = graph_init();
662 if (!gf) {
663 LLAMA_LOG_ERROR("%s: failed to initialize graph\n", __func__);
664 ret = GGML_STATUS_FAILED;
665 return nullptr;
666 }
667
668 auto res = graph_build(ctx_compute.get(), gf, ubatch, gtype, mstate);
669 if (!res) {
670 LLAMA_LOG_ERROR("%s: failed to build graph\n", __func__);
671 ret = GGML_STATUS_FAILED;
672 return nullptr;
673 }
674
675 // LLAMA_LOG_INFO("graph build time: %.3f ms (%d nodes, %d leafs)\n", (ggml_time_us() - t_start_us)/1000.0, gf->n_nodes, gf->n_leafs);
676
677 if (!ggml_backend_sched_alloc_graph(sched.get(), gf)) {
678 LLAMA_LOG_ERROR("%s: failed to allocate graph\n", __func__);
679 ret = GGML_STATUS_ALLOC_FAILED;
680 return nullptr;
681 }
682
683 res->set_inputs(&ubatch);
684
685 const int n_threads = ubatch.n_tokens > 1 ? cparams.n_threads_batch : cparams.n_threads;
686 if (powerinfer_has_global_expert_cache()) {
687 powerinfer_init_moe_pipeline(n_threads, model.hparams.n_layer, model.hparams.n_embd, model.hparams.n_ff_exp,
688 ubatch.n_tokens, model.hparams.n_expert, model.hparams.n_expert_used, true);
689 }
690 az::global_spin_barrier.init(n_threads);
691
692 const auto status = graph_compute(gf, ubatch.n_tokens > 1);
693 if (status != GGML_STATUS_SUCCESS) {
694 LLAMA_LOG_ERROR("%s: failed to compute graph, compute status: %d\n", __func__, status);
695 ret = status;
696 return nullptr;
697 }
698
699 ret = GGML_STATUS_SUCCESS;
700
701 return res;
702}
703
704int llama_context::encode(llama_batch & inp_batch) {
705 if (inp_batch.n_tokens == 0) {

Callers

nothing calls this directly

Calls 7

set_inputsMethod · 0.80
applyMethod · 0.45
getMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected