Skip to content

Commit

Permalink
whisper : fix quantize bug (ggerganov#842)
Browse files Browse the repository at this point in the history
* whisper : debug

* whisper : fix bug during quantization
  • Loading branch information
ggerganov committed Apr 30, 2023
1 parent 0733cfb commit 6fbd267
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions examples/common-ggml.cpp
Expand Up @@ -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<char *>(&ne[i]), sizeof(ne[i]));
nelements *= ne[i];
Expand All @@ -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;

Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion whisper.cpp
Expand Up @@ -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];
Expand All @@ -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;
}

Expand Down

0 comments on commit 6fbd267

Please sign in to comment.