Skip to content

Commit 91e67b8

Browse files
committed
imatrix : fix 3d tensor counts
1 parent 05beb07 commit 91e67b8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tools/imatrix/imatrix.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor * t, bool ask, void *
337337
const int64_t n_mat = src0->ne[2] * src0->ne[3];
338338

339339
// use a single count per dense tensor
340-
if ((int64_t) e.counts.size() == n_mat) {
340+
// (necessary when merging older GGUF-imatrix files with 3d tensors)
341+
if (e.counts.size() > 1) {
341342
bool all_equal = true;
342343
for (size_t i = 1; i < e.counts.size(); ++i) {
343344
if (e.counts[0] != e.counts[i]) {
@@ -379,7 +380,7 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor * t, bool ask, void *
379380
}
380381
// only 1 count in practice, except when a tensor is used for both MUL_MAT_ID and MUL_MAT
381382
for (size_t i = 0; i < e.counts.size(); ++i) {
382-
e.counts[i] += ggml_nrows(src1);
383+
e.counts[i] += ggml_nrows(src1) / n_mat;
383384
const int32_t n_chunk = e.counts[i] / chunk_size;
384385
if (n_chunk > m_last_chunk) {
385386
const int32_t chunk_step = n_chunk - m_last_chunk;

0 commit comments

Comments
 (0)