From 0522dd930e2bbca4fbface4d40e79b62b9fcf780 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sun, 18 Jan 2026 13:44:06 +0200 Subject: [PATCH] ggml : add comment --- ggml/include/ggml.h | 26 ++++++++++++++++++++++++-- ggml/src/ggml.c | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ggml/include/ggml.h b/ggml/include/ggml.h index f2e8605c5b..1988d16dc4 100644 --- a/ggml/include/ggml.h +++ b/ggml/include/ggml.h @@ -2578,10 +2578,32 @@ extern "C" { struct ggml_tensor * grad, struct ggml_tensor * sgd_params); // alpha, weight decay + // build forward mutiple tensors and select one of them for computing + // this is useful for creating graphs that have constant topology but compute different things based on the input + // ref: https://github.com/ggml-org/llama.cpp/pull/18550 // - // automatic differentiation + // nodes: + // | - build forward into the graph but do not compute + // c - build forward into the graph and compute + // + // | | ... c ... | + // | | ... c ... | + // | | ... c ... | + // [0 1 ... idx ... n-1] <-- ggml_build_forward_select(..., n, idx) + // c + // c + // + // example: + // struct ggml_tensor * curs[3]; + // + // curs[0] = compute0(...); + // curs[1] = compute1(...); + // curs[2] = compute2(...); + // + // int idx = select_branch(some_input); + // + // struct ggml_tensor * out = ggml_build_forward_select(cgraph, curs, 3, idx); // - GGML_API struct ggml_tensor * ggml_build_forward_select( struct ggml_cgraph * cgraph, struct ggml_tensor ** tensors, diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index 1e4b7d7680..1725ad1654 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -6741,7 +6741,7 @@ static size_t ggml_visit_parents_graph(struct ggml_cgraph * cgraph, struct ggml_ // update the compute flag regardless for (int i = 0; i < GGML_MAX_SRC; ++i) { struct ggml_tensor * src = node->src[i]; - if (src && (src->flags & GGML_TENSOR_FLAG_COMPUTE) == 0) { + if (src && ((src->flags & GGML_TENSOR_FLAG_COMPUTE) == 0)) { ggml_visit_parents_graph(cgraph, src, true); } }