From 5f939498d517b4dddbe904f202e895a3ecfb9dc4 Mon Sep 17 00:00:00 2001 From: unbounded Date: Sat, 22 Apr 2023 11:10:39 +0200 Subject: ggml : unit test for quantization functions (#953) * Unit test for quantization functions Use the ggml_internal_get_quantize_fn function to loop through all quantization formats and run a sanity check on the result. Also add a microbenchmark that times these functions directly without running the rest of the GGML graph. * test-quantize-fns: CI fixes Fix issues uncovered in CI - need to use sizes divisible by 32*8 for loop unrolling - use intrinsic header that should work on Mac * test-quantize: remove Per PR comment, subsumed by test-quantize-fns * test-quantize: fix for q8_0 intermediates --- tests/test-quantize.c | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 tests/test-quantize.c (limited to 'tests/test-quantize.c') diff --git a/tests/test-quantize.c b/tests/test-quantize.c deleted file mode 100644 index 993e9dcc..00000000 --- a/tests/test-quantize.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "ggml.h" -#undef NDEBUG -#include -#include - -int main(void) { - #define QK 32 - float src[QK]; - uint8_t dst[24]; - int64_t hist[16]; - - for (int i = 0; i < QK; i++) { - src[i] = (float)(i + 1); - } - - size_t size = ggml_quantize_q4_0(src, dst, QK, QK, hist); - assert(size == 20); - float max_result = ((float *)dst)[0]; - float max_expected = src[31] / ((1 << 3) - 1); - assert(max_result == max_expected); - for (int i = 0; i < QK; i++) { - uint8_t q4_result = (i % 2) ? (dst[sizeof(float) + i/2] >> 4) : (dst[sizeof(float) + i/2] & 0xF); - uint8_t q4_expected = roundf(src[i] / max_expected) + 8; - assert(q4_result == q4_expected); - } - - size = ggml_quantize_q4_1(src, dst, QK, QK, hist); - assert(size == 24); - float delta_result = ((float *)dst)[0]; - float delta_expected = (src[31] - src[0]) / ((1 << 4) - 1); - assert(delta_result == delta_expected); - float min_result = ((float *)dst)[1]; - float min_expected = src[0]; - assert(min_result == min_expected); - for (int i = 0; i < QK; i++) { - uint8_t q4_result = (i % 2) ? (dst[sizeof(float)*2 + i/2] >> 4) : (dst[sizeof(float)*2 + i/2] & 0xF); - uint8_t q4_expected = roundf((src[i] - min_expected) / delta_expected); - assert(q4_result == q4_expected); - } - - return 0; -} -- cgit v1.2.3