Spaces:
Running
Running
ggml-quants : rename best_mad to best_error (ggml/1283)
Browse filesThis commit renames the variable `best_mad` to `best_error` in the
`make_qkx2_quants` function.
The motivation for this is that the name `best_mad` can be somewhat
confusing if mean absolute deviation (MAD) is not in use.
- ggml/src/ggml-quants.c +6 -6
ggml/src/ggml-quants.c
CHANGED
|
@@ -568,14 +568,14 @@ static float make_qkx2_quants(int n, int nmax, const float * GGML_RESTRICT x, co
|
|
| 568 |
}
|
| 569 |
float iscale = nmax/(max - min);
|
| 570 |
float scale = 1/iscale;
|
| 571 |
-
float
|
| 572 |
for (int i = 0; i < n; ++i) {
|
| 573 |
int l = nearest_int(iscale*(x[i] - min));
|
| 574 |
L[i] = MAX(0, MIN(nmax, l));
|
| 575 |
float diff = scale * L[i] + min - x[i];
|
| 576 |
diff = use_mad ? fabsf(diff) : diff * diff;
|
| 577 |
float w = weights[i];
|
| 578 |
-
|
| 579 |
}
|
| 580 |
if (nstep < 1) {
|
| 581 |
*the_min = -min;
|
|
@@ -601,18 +601,18 @@ static float make_qkx2_quants(int n, int nmax, const float * GGML_RESTRICT x, co
|
|
| 601 |
this_min = 0;
|
| 602 |
this_scale = sum_xl / sum_l2;
|
| 603 |
}
|
| 604 |
-
float
|
| 605 |
for (int i = 0; i < n; ++i) {
|
| 606 |
float diff = this_scale * Laux[i] + this_min - x[i];
|
| 607 |
diff = use_mad ? fabsf(diff) : diff * diff;
|
| 608 |
float w = weights[i];
|
| 609 |
-
|
| 610 |
}
|
| 611 |
-
if (
|
| 612 |
for (int i = 0; i < n; ++i) {
|
| 613 |
L[i] = Laux[i];
|
| 614 |
}
|
| 615 |
-
|
| 616 |
scale = this_scale;
|
| 617 |
min = this_min;
|
| 618 |
}
|
|
|
|
| 568 |
}
|
| 569 |
float iscale = nmax/(max - min);
|
| 570 |
float scale = 1/iscale;
|
| 571 |
+
float best_error = 0;
|
| 572 |
for (int i = 0; i < n; ++i) {
|
| 573 |
int l = nearest_int(iscale*(x[i] - min));
|
| 574 |
L[i] = MAX(0, MIN(nmax, l));
|
| 575 |
float diff = scale * L[i] + min - x[i];
|
| 576 |
diff = use_mad ? fabsf(diff) : diff * diff;
|
| 577 |
float w = weights[i];
|
| 578 |
+
best_error += w * diff;
|
| 579 |
}
|
| 580 |
if (nstep < 1) {
|
| 581 |
*the_min = -min;
|
|
|
|
| 601 |
this_min = 0;
|
| 602 |
this_scale = sum_xl / sum_l2;
|
| 603 |
}
|
| 604 |
+
float cur_error = 0;
|
| 605 |
for (int i = 0; i < n; ++i) {
|
| 606 |
float diff = this_scale * Laux[i] + this_min - x[i];
|
| 607 |
diff = use_mad ? fabsf(diff) : diff * diff;
|
| 608 |
float w = weights[i];
|
| 609 |
+
cur_error += w * diff;
|
| 610 |
}
|
| 611 |
+
if (cur_error < best_error) {
|
| 612 |
for (int i = 0; i < n; ++i) {
|
| 613 |
L[i] = Laux[i];
|
| 614 |
}
|
| 615 |
+
best_error = cur_error;
|
| 616 |
scale = this_scale;
|
| 617 |
min = this_min;
|
| 618 |
}
|