From 658c6a830326a5a5a39d5054deafd1c6b6aa2863 Mon Sep 17 00:00:00 2001 From: Ed Addario Date: Mon, 17 Nov 2025 14:46:21 +0000 Subject: [PATCH] Enforce tensor structure when aggregating multiple imatrix files --- tools/imatrix/imatrix.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/imatrix/imatrix.cpp b/tools/imatrix/imatrix.cpp index ecde8cdb2b..ce9fa3592d 100644 --- a/tools/imatrix/imatrix.cpp +++ b/tools/imatrix/imatrix.cpp @@ -1043,15 +1043,22 @@ bool IMatrixCollector::load_imatrix(const char * file_name) { int64_t nval = ggml_nelements(in_sum2); if (e.values.empty()) { e.values.resize(nval, 0.0f); - if (in_sum != nullptr) { - e.activations.resize(nval, 0.0f); - } } else if ((size_t) nval != e.values.size()) { LOG_ERR("%s: mismatched sums size for %s: %zu != %zu\n", __func__, name.c_str(), (size_t) nval, e.values.size()); gguf_free(ctx_gguf); ggml_free(ctx); return false; } + if (in_sum != nullptr) { + if (e.activations.empty()) { + e.activations.resize(nval, 0.0f); + } else if ((size_t) nval != e.activations.size()) { + LOG_ERR("%s: mismatched activations size for %s: %zu != %zu\n", __func__, name.c_str(), (size_t) nval, e.activations.size()); + gguf_free(ctx_gguf); + ggml_free(ctx); + return false; + } + } int64_t ncounts = ggml_nelements(counts); if (e.counts.empty()) {