From 2dd464760de752476e76bbe145afa2fd109b07f6 Mon Sep 17 00:00:00 2001 From: leejet Date: Sat, 12 Sep 2026 01:02:28 +0800 Subject: [PATCH] fix: reuse graph plans when scale parameters change --- src/core/ggml_graph_cut.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/ggml_graph_cut.cpp b/src/core/ggml_graph_cut.cpp index 797100587..a6e2d99e9 100644 --- a/src/core/ggml_graph_cut.cpp +++ b/src/core/ggml_graph_cut.cpp @@ -482,6 +482,16 @@ namespace sd::ggml_graph_cut { return ggml_nbytes(cache_src); } + static bool can_ignore_op_params(ggml_op op) { + // Exempt only parameters that cannot affect graph layout or backend allocation size. + switch (op) { + case GGML_OP_SCALE: + return true; + default: + return false; + } + } + std::vector graph_layout(ggml_cgraph* graph, bool include_bindings) { std::vector tensors; std::unordered_map indices; @@ -530,8 +540,10 @@ namespace sd::ggml_graph_cut { for (auto source : tensor->src) { signature.push_back(source == nullptr ? 0 : indices.at(source)); } - for (int value : tensor->op_params) { - signature.push_back(static_cast(value)); + if (!can_ignore_op_params(tensor->op)) { + for (int value : tensor->op_params) { + signature.push_back(static_cast(value)); + } } } return signature;