Skip to content

Commit f1607bf

Browse files
committed
quantize-stats : fix test + add it to Makefile default
1 parent 226b2d0 commit f1607bf

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ $(info I CC: $(CCV))
133133
$(info I CXX: $(CXXV))
134134
$(info )
135135

136-
default: main quantize perplexity embedding
136+
default: main quantize quantize-stats perplexity embedding
137137

138138
#
139139
# Build library

examples/quantize-stats/quantize-stats.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include <unordered_map>
1717
#include <vector>
1818

19+
static const char * type_strs[] = { "f32", "f16", "q4_0", "q4_1", "q8_0", "i8", "i16", "i32", };
20+
static_assert(sizeof(type_strs) == GGML_TYPE_COUNT * sizeof(char *), "Incomplete type list");
21+
1922
struct quantize_stats_params {
2023
std::string model = "models/7B/ggml-model-f16.bin";
2124
bool verbose = false;

ggml.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7142,14 +7142,16 @@ static void ggml_compute_forward_mul_mat_f16_f32(
71427142
static const quantize_fns_t quantize_fns[GGML_TYPE_COUNT] = {
71437143
[GGML_TYPE_Q4_0] = {
71447144
.dequantize_row_q = dequantize_row_q4_0,
7145-
.quantize_row_q = quantize_row_q8_0,
7145+
.quantize_row_q = quantize_row_q4_0,
71467146
.quantize_row_q_reference = (quantize_row_q_t) quantize_row_q4_0_reference,
7147+
.quantize_row_q_dot = quantize_row_q8_0,
71477148
.vec_dot_q = ggml_vec_dot_q4_0_q8_0,
71487149
},
71497150
[GGML_TYPE_Q4_1] = {
71507151
.dequantize_row_q = dequantize_row_q4_1,
71517152
.quantize_row_q = quantize_row_q4_1,
71527153
.quantize_row_q_reference = (quantize_row_q_t) quantize_row_q4_1_reference,
7154+
.quantize_row_q_dot = quantize_row_q8_0,
71537155
.vec_dot_q = ggml_vec_dot_q4_1,
71547156
},
71557157
// TODO: GGML_TYPE_Q8_0
@@ -7208,8 +7210,8 @@ static void ggml_compute_forward_mul_mat_q_f32(
72087210
GGML_ASSERT(ne3 == ne13);
72097211

72107212
const enum ggml_type type = src0->type;
7211-
quantize_row_q_t const quantize_row_q = quantize_fns[type].quantize_row_q;
7212-
vec_dot_q_t const vec_dot_q = quantize_fns[type].vec_dot_q;
7213+
quantize_row_q_t const quantize_row_q_dot = quantize_fns[type].quantize_row_q_dot;
7214+
vec_dot_q_t const vec_dot_q = quantize_fns[type].vec_dot_q;
72137215

72147216
// we don't support permuted src0 or src1
72157217
GGML_ASSERT(nb00 == (int) GGML_TYPE_SIZE[type]);
@@ -7283,7 +7285,7 @@ static void ggml_compute_forward_mul_mat_q_f32(
72837285
for (int64_t i13 = 0; i13 < ne13; ++i13) {
72847286
for (int64_t i12 = 0; i12 < ne12; ++i12) {
72857287
for (int64_t i11 = 0; i11 < ne11; ++i11) {
7286-
quantize_row_q((float *)((char *) src1->data + i13*nb13 + i12*nb12 + i11*nb11), (void *) wdata, ne10);
7288+
quantize_row_q_dot((float *)((char *) src1->data + i13*nb13 + i12*nb12 + i11*nb11), (void *) wdata, ne10);
72877289
wdata += row_size;
72887290
}
72897291
}

ggml.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ typedef struct {
837837
dequantize_row_q_t dequantize_row_q;
838838
quantize_row_q_t quantize_row_q;
839839
quantize_row_q_t quantize_row_q_reference;
840+
quantize_row_q_t quantize_row_q_dot;
840841
vec_dot_q_t vec_dot_q;
841842
} quantize_fns_t;
842843

0 commit comments

Comments
 (0)