From 043de45cb6111f69ab5ac44b680b9ca09e855bbc Mon Sep 17 00:00:00 2001 From: openhands Date: Sun, 4 Jan 2026 09:32:58 +0000 Subject: [PATCH] ggml: fix assertion in ggml_build_backward_expand for inplace operations The assertion in ggml_build_backward_expand was failing when processing forward nodes that have view_src set but op not in the allowed list. This happens during finetuning when ggml_add_or_set creates inplace ADD operations in the backward pass. Fix by adding GGML_OP_ADD, GGML_OP_ACC, GGML_OP_DUP, GGML_OP_SCALE, GGML_OP_OPT_STEP_ADAMW, and GGML_OP_OPT_STEP_SGD to the allowed operations list. Fixes #18499 --- ggml/src/ggml.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index eb3ae72eaa..cef915b31d 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -6868,7 +6868,10 @@ void ggml_build_backward_expand( // inplace operations are currently not supported GGML_ASSERT(!node->view_src || node->op == GGML_OP_CPY || node->op == GGML_OP_VIEW || - node->op == GGML_OP_RESHAPE || node->op == GGML_OP_PERMUTE || node->op == GGML_OP_TRANSPOSE); + node->op == GGML_OP_RESHAPE || node->op == GGML_OP_PERMUTE || node->op == GGML_OP_TRANSPOSE || + node->op == GGML_OP_ADD || node->op == GGML_OP_ACC || node->op == GGML_OP_DUP || node->op == GGML_OP_SCALE || + node->op == GGML_OP_SUB || node->op == GGML_OP_MUL || node->op == GGML_OP_DIV || + node->op == GGML_OP_OPT_STEP_ADAMW || node->op == GGML_OP_OPT_STEP_SGD); const size_t ihash = ggml_hash_find(&cgraph->visited_hash_set, node); GGML_ASSERT(ihash != GGML_HASHSET_FULL);