From 0225cfbfb3e1fa9932f11ef7456b23f59ffcbc5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigbj=C3=B8rn=20Skj=C3=A6ret?= Date: Fri, 7 Jun 2024 23:57:04 +0200 Subject: [PATCH] Avoid division-by-zero on 0-weights --- ggml-quants.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ggml-quants.c b/ggml-quants.c index 9f864e5c4..e7c80edbb 100644 --- a/ggml-quants.c +++ b/ggml-quants.c @@ -1754,7 +1754,7 @@ static float make_q3_quants(int n, int nmax, const float * restrict x, int8_t * for (int i = 0; i < n; ++i) { L[i] += nmax; } - return sumlx / suml2; + return suml2 ? sumlx / suml2 : 0.0f; } for (int i = 0; i < n; ++i) { int l = nearest_int(iscale * x[i]); @@ -2158,7 +2158,7 @@ static float make_qp_quants(int n, int nmax, const float * restrict x, uint8_t * break; } } - return sumlx/suml2; + return suml2 ? sumlx/suml2 : 0.0f; } static void quantize_row_q2_K_impl(const float * restrict x, block_q2_K * restrict y, int k, const float * restrict quant_weights) {