Skip to content

Commit 0225cfb

Browse files
authored
Avoid division-by-zero on 0-weights
1 parent da799b4 commit 0225cfb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ggml-quants.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,7 @@ static float make_q3_quants(int n, int nmax, const float * restrict x, int8_t *
17541754
for (int i = 0; i < n; ++i) {
17551755
L[i] += nmax;
17561756
}
1757-
return sumlx / suml2;
1757+
return suml2 ? sumlx / suml2 : 0.0f;
17581758
}
17591759
for (int i = 0; i < n; ++i) {
17601760
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 *
21582158
break;
21592159
}
21602160
}
2161-
return sumlx/suml2;
2161+
return suml2 ? sumlx/suml2 : 0.0f;
21622162
}
21632163

21642164
static void quantize_row_q2_K_impl(const float * restrict x, block_q2_K * restrict y, int k, const float * restrict quant_weights) {

0 commit comments

Comments
 (0)