From ab3c60126985c8ac4cb4318dc72cda5f8e4449f9 Mon Sep 17 00:00:00 2001 From: Kawrakow Date: Wed, 25 Feb 2026 14:20:22 +0000 Subject: [PATCH] Fix KT quantization yet again --- ggml/src/iqk/iqk_quantize.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ggml/src/iqk/iqk_quantize.cpp b/ggml/src/iqk/iqk_quantize.cpp index 038cb4fe..ecdf6c24 100644 --- a/ggml/src/iqk/iqk_quantize.cpp +++ b/ggml/src/iqk/iqk_quantize.cpp @@ -8733,6 +8733,11 @@ void quantize_row_iq1_kt_impl(const float * x, void * vy, int n_per_row, const f float ax = std::abs(xb[j]); amax = std::max(amax, ax); } + if (amax < 1e-16f) { + scales[ib] = 0.0f; + for (int ig = 0; ig < Q::kNg; ++ig) all_idx[(ibl*Q::kSuperBlockSize + ib*Q::kBlockSize)/Q::kGroupSize + ig] = 0; + continue; + } float scale_0 = std::max(90.f, 124.f*amax/amax_row); quantizer.find_best_match( amax/scale_0, xb, weight, best_idx); auto [dp, score_p] = quantizer.find_best_scale(xb, weight, best_idx); @@ -8998,6 +9003,11 @@ void quantize_row_iq2_kt_impl(const float * x, void * vy, int n_per_row, const f float ax = std::abs(xb[j]); amax = std::max(amax, ax); } + if (amax < 1e-16f) { + scales[ib] = 0.0f; + for (int ig = 0; ig < Q::kNg; ++ig) all_idx[(ibl*Q::kSuperBlockSize + ib*Q::kBlockSize)/Q::kGroupSize + ig] = 0; + continue; + } float scale_0 = std::max(90.f, 124.f*amax/amax_row); quantizer.find_best_match( amax/scale_0, xb, weight, best_idx); auto [dp, score_p] = quantizer.find_best_scale(xb, weight, best_idx); @@ -9289,8 +9299,10 @@ void quantize_row_iq3_kt_impl(const float * x, void * vy, int n_per_row, const f xaux[j] = ax; amax = std::max(amax, ax); } - scales[ib] = 0; - if (!amax) continue; + if (amax < 1e-16f) { + scales[ib] = 0.0f; + continue; + } //quantizer.find_best_match(amax/96.f, xaux, weight, best_idx+Q::kNg); //scales[ib] = quantizer.find_best_scale(xaux, weight, best_idx+Q::kNg).first; @@ -9577,7 +9589,7 @@ void quantize_row_iq4_kt_impl(const float * x, void * vy, int n_per_row, const f float ax = std::abs(xaux[j]); amax = std::max(amax, ax); } - if (!amax) { + if (amax < 1e-16f) { scales[ib] = 0; continue; }