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

Method update

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

Source from the content-addressed store, hash-verified

626}
627
628bool llama_kv_cache::update(llama_context * lctx, bool do_shift, const stream_copy_info & sc_info) {
629 bool updated = false;
630
631 auto * sched = lctx->get_sched();
632
633 if (!sc_info.empty()) {
634 assert(n_stream > 1 && "stream copy should never happen with a single stream");
635
636 llama_synchronize(lctx);
637
638 const size_t n_copy = sc_info.ssrc.size();
639
640 for (size_t i = 0; i < n_copy; ++i) {
641 const auto ssrc = sc_info.ssrc[i];
642 const auto sdst = sc_info.sdst[i];
643
644 assert(ssrc < n_stream);
645 assert(sdst < n_stream);
646
647 LLAMA_LOG_DEBUG("%s: copying KV buffer: stream %d to stream %d\n", __func__, ssrc, sdst);
648
649 assert(ssrc != sdst);
650
651 for (uint32_t il = 0; il < layers.size(); ++il) {
652 const auto & layer = layers[il];
653
654 ggml_backend_tensor_copy(layer.k_stream[ssrc], layer.k_stream[sdst]);
655
656 if (layer.v_stream[ssrc]) {
657 ggml_backend_tensor_copy(layer.v_stream[ssrc], layer.v_stream[sdst]);
658 }
659 }
660 }
661 }
662
663 if (do_shift) {
664 if (!get_can_shift()) {
665 GGML_ABORT("The current KV cache / model configuration does not support K-shift");
666 }
667
668 LLAMA_LOG_DEBUG("%s: applying K-shift\n", __func__);
669
670 // apply K-shift if needed
671 if (hparams.rope_type != LLAMA_ROPE_TYPE_NONE) {
672 ggml_backend_sched_reset(sched);
673
674 auto * res = lctx->get_gf_res_reserve();
675
676 res->reset();
677
678 auto * gf = build_graph_shift(res, lctx);
679 if (!ggml_backend_sched_alloc_graph(sched, gf)) {
680 LLAMA_LOG_ERROR("%s: failed to allocate compute graph for K-shift\n", __func__);
681 return updated;
682 }
683
684 res->set_inputs(nullptr);
685

Callers

nothing calls this directly

Calls 12

llama_synchronizeFunction · 0.85
ggml_backend_tensor_copyFunction · 0.85
ggml_backend_sched_resetFunction · 0.85
get_schedMethod · 0.80
get_gf_res_reserveMethod · 0.80
set_inputsMethod · 0.80
reset_shiftMethod · 0.80
emptyMethod · 0.65
sizeMethod · 0.65
resetMethod · 0.65
graph_computeMethod · 0.45

Tested by

no test coverage detected