From: Pascal Date: Wed, 5 Aug 2026 22:47:59 +0000 (+0200) Subject: mtmd/ggml: add ggml_build_forward_order (llama/26649) X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=60894f1e3766ef0224b57ad8840a83a66e05cb6f;p=pkg%2Fggml%2Fsources%2Fwhisper.cpp mtmd/ggml: add ggml_build_forward_order (llama/26649) * ggml: add ggml_build_forward_order ggml_build_forward_expand marks the tensor and all its ancestors for compute, so using it as a pure ordering hint (keeping q, k and v together) defeats ggml_build_forward_select: the unselected branch is forced to run with inputs that were never uploaded. In the mtmd audio graph this makes GEN_WAV calls execute the GEN_CODE branch with a stale inp_code0, hitting the get_rows bound assert on CPU. Add ggml_build_forward_order, which inserts nodes without the compute flag; the flag is restored when the branch is actually selected. Switch the q/k/v hints in clip_graph::build_attn to it. * nit: reduce comments (AGENTS.md) --- diff --git a/ggml/include/ggml.h b/ggml/include/ggml.h index 35f0c44e..5cb49d0e 100644 --- a/ggml/include/ggml.h +++ b/ggml/include/ggml.h @@ -2788,6 +2788,12 @@ extern "C" { struct ggml_cgraph * cgraph, struct ggml_tensor * tensor); + // add the tensor and its parents to the graph without marking them for compute + // the flag is set later, when the tensor is reached from a node that computes + GGML_API void ggml_build_forward_order( + struct ggml_cgraph * cgraph, + struct ggml_tensor * tensor); + GGML_API void ggml_build_backward_expand( struct ggml_context * ctx, // context for gradient computation struct ggml_cgraph * cgraph, diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index 59191c66..da7f3a5f 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -7200,6 +7200,10 @@ void ggml_build_forward_expand(struct ggml_cgraph * cgraph, struct ggml_tensor * ggml_build_forward_impl(cgraph, tensor, true, true); } +void ggml_build_forward_order(struct ggml_cgraph * cgraph, struct ggml_tensor * tensor) { + ggml_build_forward_impl(cgraph, tensor, true, false); +} + void ggml_build_backward_expand( struct ggml_context * ctx, struct ggml_cgraph * cgraph,