From a6ecc679a267bef30d0a5ed8ef9e5e7c3e4a4a55 Mon Sep 17 00:00:00 2001 From: Iwan Kawrakow Date: Wed, 27 Aug 2025 13:58:54 +0300 Subject: [PATCH] sanitize imatrix: iq4_ks --- ggml/src/iqk/iqk_quantize.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/ggml/src/iqk/iqk_quantize.cpp b/ggml/src/iqk/iqk_quantize.cpp index 141be65d..57225c85 100644 --- a/ggml/src/iqk/iqk_quantize.cpp +++ b/ggml/src/iqk/iqk_quantize.cpp @@ -4047,18 +4047,16 @@ void quantize_row_iq4_ks(const float * x, void * y, int64_t k) { } size_t quantize_iq4_ks(const float * src, void * dst, int64_t nrows, int64_t n_per_row, const float * imatrix) { - //printf("============ %s(%d, %d)\n", __func__, int(nrows), int(n_per_row)); - constexpr int kBlockSize = 32; //128; + constexpr int kBlockSize = 32; GGML_ASSERT(n_per_row%QK_K == 0); auto row_size = ggml_row_size(GGML_TYPE_IQ4_KS, n_per_row); - char * qrow = (char *)dst; float weight[kBlockSize]; std::vector all_scales(n_per_row/kBlockSize); - for (int64_t row = 0; row < nrows; ++row) { - quantize_row_iq4_k_impl_bs128(QK_K, kBlockSize, n_per_row, src, qrow, all_scales.data(), weight, iq4k_values, imatrix, 7); - src += n_per_row; - qrow += row_size; - } + QHelper helper(imatrix, n_per_row, kBlockSize); + auto q_func = [&all_scales, &weight, block_size = kBlockSize] (const float * x, void * vy, int n_per_row, const float * imatrix) { + quantize_row_iq4_k_impl_bs128(QK_K, block_size, n_per_row, x, (char *)vy, all_scales.data(), weight, iq4k_values, imatrix, 7); + }; + helper.quantize(nrows, src, dst, row_size, q_func); return nrows * row_size; }