Skip to content

Commit be7b2ca

Browse files
committed
tests: override test_set_rows::max_nmse_err to allow for occasional rounding differences
1 parent 3f81b4e commit be7b2ca

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/test-backend-ops.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,6 +2140,27 @@ struct test_set_rows : public test_case {
21402140
}
21412141
}
21422142
}
2143+
2144+
double max_nmse_err() override {
2145+
if (type == GGML_TYPE_Q4_0 || type == GGML_TYPE_Q4_1 || type == GGML_TYPE_IQ4_NL ||
2146+
type == GGML_TYPE_Q5_0 || type == GGML_TYPE_Q5_1 || type == GGML_TYPE_Q8_0) {
2147+
// estimate what the max nmse error would be if one quantized value is
2148+
// off by one. The test values are distributed in [-1,1], so it'll be
2149+
// roughly (2.0 / 2^bits)^2, divided by the mean square value of the reference,
2150+
// which is roughly 0.25 times the number of elements.
2151+
double err_estimate = 1.0f/8.0f;
2152+
if (type == GGML_TYPE_Q5_0 || type == GGML_TYPE_Q5_1) {
2153+
err_estimate /= 2.0f;
2154+
}
2155+
if (type == GGML_TYPE_Q8_0) {
2156+
err_estimate /= 8.0f;
2157+
}
2158+
err_estimate *= err_estimate;
2159+
err_estimate /= 0.25f*float(ne[0] * r * ne[2]*nr23[0] * ne[3]*nr23[1]);
2160+
return err_estimate;
2161+
}
2162+
return 1e-7;
2163+
}
21432164
};
21442165

21452166
// GGML_OP_ARGMAX

0 commit comments

Comments
 (0)