| 1115 | } |
| 1116 | |
| 1117 | llm_graph_result * llama_context::process_ubatch(const llama_ubatch & ubatch, llm_graph_type gtype, llama_memory_context_i * mctx, ggml_status & ret) { |
| 1118 | if (mctx && !mctx->apply()) { |
| 1119 | LLAMA_LOG_ERROR("%s: failed to apply memory context\n", __func__); |
| 1120 | ret = GGML_STATUS_FAILED; |
| 1121 | return nullptr; |
| 1122 | } |
| 1123 | |
| 1124 | auto * res = gf_res_prev.get(); |
| 1125 | auto * gf = res->get_gf(); |
| 1126 | |
| 1127 | // the new graph parameters |
| 1128 | // in order to correctly reuse a graph, it's full topology has to be uniquely determined by these parameters |
| 1129 | const auto gparams = graph_params(res, ubatch, mctx, gtype); |
| 1130 | |
| 1131 | if (!graph_reuse_disable && res->can_reuse(gparams)) { |
| 1132 | //LLAMA_LOG_DEBUG("%s: reusing previous graph\n", __func__); |
| 1133 | |
| 1134 | n_reused++; |
| 1135 | } else { |
| 1136 | res->reset(); |
| 1137 | |
| 1138 | ggml_backend_sched_reset(sched.get()); |
| 1139 | ggml_backend_sched_set_eval_callback(sched.get(), cparams.cb_eval, cparams.cb_eval_user_data); |
| 1140 | |
| 1141 | //const auto t_start_us = ggml_time_us(); |
| 1142 | |
| 1143 | gf = model.build_graph(gparams); |
| 1144 | |
| 1145 | //LLAMA_LOG_INFO("graph build time: %.3f ms\n", (ggml_time_us() - t_start_us)/1000.0); |
| 1146 | |
| 1147 | if (!gf) { |
| 1148 | LLAMA_LOG_ERROR("%s: failed to initialize graph\n", __func__); |
| 1149 | ret = GGML_STATUS_FAILED; |
| 1150 | return nullptr; |
| 1151 | } |
| 1152 | |
| 1153 | if (!ggml_backend_sched_alloc_graph(sched.get(), gf)) { |
| 1154 | LLAMA_LOG_ERROR("%s: failed to allocate graph\n", __func__); |
| 1155 | ret = GGML_STATUS_ALLOC_FAILED; |
| 1156 | return nullptr; |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | // set the input data for the input tensors |
| 1161 | { |
| 1162 | //const auto t_start_us = ggml_time_us(); |
| 1163 | |
| 1164 | res->set_inputs(&ubatch); |
| 1165 | |
| 1166 | //LLAMA_LOG_INFO("graph set inputs time: %.3f ms\n", (ggml_time_us() - t_start_us)/1000.0); |
| 1167 | } |
| 1168 | |
| 1169 | const auto status = graph_compute(res->get_gf(), ubatch.n_tokens > 1); |
| 1170 | if (status != GGML_STATUS_SUCCESS) { |
| 1171 | LLAMA_LOG_ERROR("%s: failed to compute graph, compute status: %d\n", __func__, status); |
| 1172 | ret = status; |
| 1173 | return nullptr; |
| 1174 | } |
nothing calls this directly
no test coverage detected