Skip to content

Commit a74a0d6

Browse files
authored
tests: override test_set_rows::max_nmse_err to allow for occasional rounding differences (#16295)
* tests: override test_set_rows::max_nmse_err to allow for occasional rounding differences * apply similar error bounds to test_cpy
1 parent 5f7e166 commit a74a0d6

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/test-backend-ops.cpp

Lines changed: 45 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
@@ -2430,6 +2451,30 @@ struct test_cpy : public test_case {
24302451
}
24312452

24322453
double max_nmse_err() override {
2454+
if (type_src == type_dst) {
2455+
return 0.0;
2456+
}
2457+
if (type_dst == GGML_TYPE_Q4_0 || type_dst == GGML_TYPE_Q4_1 || type_dst == GGML_TYPE_IQ4_NL ||
2458+
type_dst == GGML_TYPE_Q5_0 || type_dst == GGML_TYPE_Q5_1 || type_dst == GGML_TYPE_Q8_0) {
2459+
// estimate what the max nmse error would be if one quantized value is
2460+
// off by one. The test values are distributed in [-150,150], so it'll be
2461+
// roughly (150*2.0 / 2^bits)^2, divided by the mean square value of the reference,
2462+
// which is roughly 0.25*150^2 times the number of elements.
2463+
double err_estimate = 1.0f/8.0f * 150.0f;
2464+
if (type_dst == GGML_TYPE_IQ4_NL) {
2465+
// iq4_nl values are a bit more spread out
2466+
err_estimate *= 2.0f;
2467+
}
2468+
if (type_dst == GGML_TYPE_Q5_0 || type_dst == GGML_TYPE_Q5_1) {
2469+
err_estimate /= 2.0f;
2470+
}
2471+
if (type_dst == GGML_TYPE_Q8_0) {
2472+
err_estimate /= 8.0f;
2473+
}
2474+
err_estimate *= err_estimate;
2475+
err_estimate /= (150.0f*150.0f*0.25f)*float(ne[0] * ne[1] * ne[2] * ne[3]);
2476+
return err_estimate;
2477+
}
24332478
return 1e-6;
24342479
}
24352480

0 commit comments

Comments
 (0)