| 2142 | } |
| 2143 | |
| 2144 | llm_graph_cb llama_context::graph_get_cb() const { |
| 2145 | return [&](const llama_ubatch & ubatch, ggml_tensor * cur, const char * name, int il) { |
| 2146 | if (il >= 0) { |
| 2147 | ggml_format_name(cur, "%s-%d", name, il); |
| 2148 | } else { |
| 2149 | ggml_set_name(cur, name); |
| 2150 | } |
| 2151 | |
| 2152 | // norm may be automatically assigned to the backend of the previous layer, increasing data transfer between backends |
| 2153 | // FIXME: fix in ggml_backend_sched |
| 2154 | const bool full_offload = model.n_gpu_layers() > model.hparams.n_layer; |
| 2155 | if (ubatch.n_tokens < 32 || full_offload) { |
| 2156 | if (il != -1 && strcmp(name, "norm") == 0) { |
| 2157 | const auto & dev_layer = model.dev_layer(il); |
| 2158 | for (const auto & backend : backends) { |
| 2159 | if (ggml_backend_get_device(backend.get()) == dev_layer) { |
| 2160 | if (ggml_backend_supports_op(backend.get(), cur)) { |
| 2161 | ggml_backend_sched_set_tensor_backend(sched.get(), cur, backend.get()); |
| 2162 | } |
| 2163 | } |
| 2164 | } |
| 2165 | } |
| 2166 | } |
| 2167 | }; |
| 2168 | } |
| 2169 | |
| 2170 | // |
| 2171 | // state save/load |
nothing calls this directly
no test coverage detected