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

Method graph_get_cb

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

Source from the content-addressed store, hash-verified

1398}
1399
1400llm_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

Callers

nothing calls this directly

Calls 7

ggml_backend_get_deviceFunction · 0.85
dev_layerMethod · 0.80
ggml_format_nameFunction · 0.50
ggml_set_nameFunction · 0.50
ggml_backend_supports_opFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected