From 6fbd267550b1364c3392572e51c1c60b3bf519d4 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sun, 30 Apr 2023 22:50:04 +0300 Subject: [PATCH] whisper : fix quantize bug (#842) * whisper : debug * whisper : fix bug during quantization --- examples/common-ggml.cpp | 12 ++++++------ whisper.cpp | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/common-ggml.cpp b/examples/common-ggml.cpp index 226f2b144bc..141c6a2c997 100644 --- a/examples/common-ggml.cpp +++ b/examples/common-ggml.cpp @@ -90,7 +90,7 @@ bool ggml_common_quantize_0( } int32_t nelements = 1; - int32_t ne[2] = { 1, 1 }; + int32_t ne[4] = { 1, 1, 1, 1 }; for (int i = 0; i < n_dims; ++i) { finp.read (reinterpret_cast(&ne[i]), sizeof(ne[i])); nelements *= ne[i]; @@ -99,7 +99,7 @@ bool ggml_common_quantize_0( std::string name(length, 0); finp.read (&name[0], length); - printf("%64s - [%5d, %5d], type = %6s ", name.data(), ne[0], ne[1], ggml_type_name((ggml_type) ttype)); + printf("%64s - [%5d, %5d, %5d], type = %6s ", name.data(), ne[0], ne[1], ne[2], ggml_type_name((ggml_type) ttype)); bool quantize = false; @@ -204,11 +204,11 @@ bool ggml_common_quantize_0( total_size_new += cur_size; printf("size = %8.2f MB -> %8.2f MB | hist: ", nelements * sizeof(float)/1024.0/1024.0, cur_size/1024.0/1024.0); - for (int i = 0; i < hist_cur.size(); ++i) { + for (int i = 0; i < (int) hist_cur.size(); ++i) { hist_all[i] += hist_cur[i]; } - for (int i = 0; i < hist_cur.size(); ++i) { + for (int i = 0; i < (int) hist_cur.size(); ++i) { printf("%5.3f ", hist_cur[i] / (float)nelements); } printf("\n"); @@ -226,12 +226,12 @@ bool ggml_common_quantize_0( { int64_t sum_all = 0; - for (int i = 0; i < hist_all.size(); ++i) { + for (int i = 0; i < (int) hist_all.size(); ++i) { sum_all += hist_all[i]; } printf("%s: hist: ", __func__); - for (int i = 0; i < hist_all.size(); ++i) { + for (int i = 0; i < (int) hist_all.size(); ++i) { printf("%5.3f ", hist_all[i] / (float)sum_all); } printf("\n"); diff --git a/whisper.cpp b/whisper.cpp index 4f83dcd8df5..b08bf0faa58 100644 --- a/whisper.cpp +++ b/whisper.cpp @@ -1333,7 +1333,7 @@ static bool whisper_model_load(struct whisper_model_loader * loader, whisper_con } int32_t nelements = 1; - int32_t ne[3] = { 1, 1, 1 }; + int32_t ne[4] = { 1, 1, 1, 1 }; for (int i = 0; i < n_dims; ++i) { read_safe(loader, ne[i]); nelements *= ne[i]; @@ -1352,6 +1352,8 @@ static bool whisper_model_load(struct whisper_model_loader * loader, whisper_con auto tensor = model.tensors[name.data()]; if (ggml_nelements(tensor) != nelements) { fprintf(stderr, "%s: tensor '%s' has wrong size in model file\n", __func__, name.data()); + fprintf(stderr, "%s: shape: [%d, %d, %d], expected: [%d, %d, %d]\n", + __func__, ne[0], ne[1], ne[2], (int) tensor->ne[0], (int) tensor->ne[1], (int) tensor->ne[2]); return false; }