Skip to content

Commit 179cbad

Browse files
committed
apply similar error bounds to test_cpy
1 parent be7b2ca commit 179cbad

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/test-backend-ops.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,6 +2451,30 @@ struct test_cpy : public test_case {
24512451
}
24522452

24532453
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+
}
24542478
return 1e-6;
24552479
}
24562480

0 commit comments

Comments
 (0)