tests : accept either accumulator precision in the DT3 GEMM bit-identity gate
The Vulkan backend now forces fp32 accumulators for the DT3 dequant fallback, so the DT3 GEMM is no longer bit-identical to the backend's default-precision F16 GEMM (fp16 accumulators on fp16-capable Vulkan devices). Run the F16 control at both the default and the F32-forced precision and require bit-identity with either one. CUDA still matches the default-precision control; Vulkan matches the F32 one - both with 0 mismatches.
This commit is contained in:
+22
-5
@@ -379,8 +379,16 @@ static int test_mul_mat(ggml_backend_t backend, ggml_type type, const std::vecto
|
||||
// tensor holding fp16(dequant(block))": running the same GEMM with an
|
||||
// F16 src0 built from the fp16-rounded reference weights must give a
|
||||
// bit-identical result. This isolates our (already bit-validated)
|
||||
// dequantization from cuBLAS numerics.
|
||||
// dequantization from cuBLAS numerics. The backend may run the DT3
|
||||
// fallback at a different accumulator precision than its default F16
|
||||
// GEMM (Vulkan forces fp32 accumulators for DT3), so the F16 control is
|
||||
// run at both the default and the F32-forced precision and bit-identity
|
||||
// with either one passes.
|
||||
if (strict) {
|
||||
int n_mismatch_best = -1;
|
||||
double max_diff_best = 0.0;
|
||||
|
||||
for (int force_f32_prec = 0; force_f32_prec < 2; ++force_f32_prec) {
|
||||
ggml_init_params params = {
|
||||
/*.mem_size =*/ ggml_tensor_overhead()*8 + ggml_graph_overhead(),
|
||||
/*.mem_buffer =*/ nullptr,
|
||||
@@ -391,6 +399,9 @@ static int test_mul_mat(ggml_backend_t backend, ggml_type type, const std::vecto
|
||||
ggml_tensor * a16 = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, NCOLS, NROWS);
|
||||
ggml_tensor * b = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, NCOLS, 16);
|
||||
ggml_tensor * out = ggml_mul_mat(ctx, a16, b);
|
||||
if (force_f32_prec) {
|
||||
ggml_mul_mat_set_prec(out, GGML_PREC_F32);
|
||||
}
|
||||
|
||||
ggml_backend_buffer_t buf = ggml_backend_alloc_ctx_tensors(ctx, backend);
|
||||
GGML_ASSERT(buf != nullptr);
|
||||
@@ -415,16 +426,22 @@ static int test_mul_mat(ggml_backend_t backend, ggml_type type, const std::vecto
|
||||
n_mismatch++;
|
||||
}
|
||||
}
|
||||
printf("%s: %s GEMM path vs F16 GEMM on fp16-rounded weights: %d mismatches, max |diff| = %g\n",
|
||||
n_mismatch == 0 ? "OK" : "FAILED", ggml_type_name(type), n_mismatch, max_diff);
|
||||
if (n_mismatch != 0) {
|
||||
num_failed++;
|
||||
if (n_mismatch_best < 0 || n_mismatch < n_mismatch_best) {
|
||||
n_mismatch_best = n_mismatch;
|
||||
max_diff_best = max_diff;
|
||||
}
|
||||
|
||||
ggml_backend_buffer_free(buf);
|
||||
ggml_free(ctx);
|
||||
}
|
||||
|
||||
printf("%s: %s GEMM path vs F16 GEMM on fp16-rounded weights (best of default/F32 prec): %d mismatches, max |diff| = %g\n",
|
||||
n_mismatch_best == 0 ? "OK" : "FAILED", ggml_type_name(type), n_mismatch_best, max_diff_best);
|
||||
if (n_mismatch_best != 0) {
|
||||
num_failed++;
|
||||
}
|
||||
}
|
||||
|
||||
// manual sum over the trits stored by the test for row 0, column 0 —
|
||||
// computed from the trits themselves, not from any dequantization, with
|
||||
// non-trivial qh trits in every block of the row
|
||||
|
||||
Reference in New Issue
Block a user