Skip to content

Commit d59bd97

Browse files
ikawrakowKawrakow
andauthored
Guard against all weights in a super-block being zero (#3010)
* Guard against all weights in a super-block being zero * Also guard against extremely small weights Closes #2982 --------- Co-authored-by: Iwan Kawrakow <[email protected]>
1 parent 35938ee commit d59bd97

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

k_quants.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static float make_qx_quants(int n, int nmax, const float * restrict x, int8_t *
8383
float ax = fabsf(x[i]);
8484
if (ax > amax) { amax = ax; max = x[i]; }
8585
}
86-
if (!amax) { // all zero
86+
if (amax < 1e-30f) { // all zero
8787
for (int i = 0; i < n; ++i) {
8888
L[i] = 0;
8989
}
@@ -1086,6 +1086,12 @@ void quantize_row_q6_K_reference(const float * restrict x, block_q6_K * restrict
10861086

10871087
}
10881088

1089+
if (!max_abs_scale) {
1090+
memset(&y[i], 0, sizeof(block_q6_K));
1091+
y[i].d = ggml_fp32_to_fp16(0.f);
1092+
continue;
1093+
}
1094+
10891095
float iscale = -128.f/max_scale;
10901096
y[i].d = ggml_fp32_to_fp16(1/iscale);
10911097
for (int ib = 0; ib < QK_K/16; ++ib) {

0 commit comments

Comments
 (0)