| 1398 | } |
| 1399 | |
| 1400 | llm_graph_cb llama_context::graph_get_cb() const { |
| 1401 | return [&](const llama_ubatch & ubatch, ggml_tensor * cur, const char * name, int il) { |
| 1402 | if (il >= 0) { |
| 1403 | ggml_format_name(cur, "%s-%d", name, il); |
| 1404 | } else { |
| 1405 | ggml_set_name(cur, name); |
| 1406 | } |
| 1407 | |
| 1408 | if (!cparams.offload_kqv) { |
| 1409 | if (strcmp(name, "kqv_merged_cont") == 0) { |
| 1410 | // all nodes between the KV store and the attention output are run on the CPU |
| 1411 | ggml_backend_sched_set_tensor_backend(sched.get(), cur, backend_cpu); |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | // norm may be automatically assigned to the backend of the previous layer, increasing data transfer between backends |
| 1416 | // FIXME: fix in ggml_backend_sched |
| 1417 | const bool full_offload = model.params.n_gpu_layers > (int) model.hparams.n_layer; |
| 1418 | if (ubatch.n_tokens < 32 || full_offload) { |
| 1419 | if (il != -1 && strcmp(name, "norm") == 0) { |
| 1420 | const auto & dev_layer = model.dev_layer(il); |
| 1421 | for (const auto & backend : backends) { |
| 1422 | if (ggml_backend_get_device(backend.get()) == dev_layer) { |
| 1423 | if (ggml_backend_supports_op(backend.get(), cur)) { |
| 1424 | ggml_backend_sched_set_tensor_backend(sched.get(), cur, backend.get()); |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | } |
| 1429 | } |
| 1430 | }; |
| 1431 | } |
| 1432 | |
| 1433 | // |
| 1434 | // state save/load |
nothing calls this directly
no test coverage detected