From 850320be8b66eacb3ee3c205335c06586f142d3d Mon Sep 17 00:00:00 2001 From: Riccardo Chiumiento <29974786+steadfastgaze@users.noreply.github.com> Date: Wed, 26 Aug 2026 17:15:46 +0200 Subject: [PATCH] metal: initialize encode_async in ggml_backend_metal_init (#2334) ggml_metal_init leaves ctx->encode_async nil, but ggml_backend_metal_graph_compute invokes it unconditionally, so a Metal backend created without a prior set_n_cb call segfaults on its first graph. This affects rpc-server and ggml_backend_reg_metal_init; the llama.cpp path is unaffected, since llama_graph_compute sets n_cb before every compute. Upstream added the same call in cad341d88 (#9698), the commit that introduced encode_async. ik_llama.cpp carries the block but not the initialization. --- ggml/src/ggml-metal.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ggml/src/ggml-metal.m b/ggml/src/ggml-metal.m index 323d4e45..ef8db66b 100644 --- a/ggml/src/ggml-metal.m +++ b/ggml/src/ggml-metal.m @@ -4509,6 +4509,8 @@ ggml_backend_t ggml_backend_metal_init(void) { /* .context = */ ctx, }; + ggml_backend_metal_set_n_cb(metal_backend, 1); + return metal_backend; }