@@ -63,14 +63,24 @@ static const char * const LLM_KV_QUANTIZE_IMATRIX_DATASET = "quantize.imatrix
63
63
static const char * const LLM_KV_QUANTIZE_IMATRIX_N_ENTRIES = " quantize.imatrix.entries_count" ;
64
64
static const char * const LLM_KV_QUANTIZE_IMATRIX_N_CHUNKS = " quantize.imatrix.chunks_count" ;
65
65
66
+ static bool striequals (const char * a, const char * b) {
67
+ while (*a && *b) {
68
+ if (std::tolower (*a) != std::tolower (*b)) {
69
+ return false ;
70
+ }
71
+ a++; b++;
72
+ }
73
+ return *a == *b;
74
+ }
75
+
66
76
static bool try_parse_ftype (const std::string & ftype_str_in, llama_ftype & ftype, std::string & ftype_str_out) {
67
77
std::string ftype_str;
68
78
69
79
for (auto ch : ftype_str_in) {
70
80
ftype_str.push_back (std::toupper (ch));
71
81
}
72
82
for (auto & it : QUANT_OPTIONS) {
73
- if (it.name == ftype_str) {
83
+ if (striequals ( it.name . c_str (), ftype_str. c_str ()) ) {
74
84
ftype = it.ftype ;
75
85
ftype_str_out = it.name ;
76
86
return true ;
@@ -225,15 +235,15 @@ static int prepare_imatrix(const std::string & imatrix_file,
225
235
}
226
236
227
237
static ggml_type parse_ggml_type (const char * arg) {
228
- ggml_type result = GGML_TYPE_COUNT;
229
- for (int j = 0 ; j < GGML_TYPE_COUNT; ++j) {
230
- auto type = ggml_type (j);
238
+ for (int i = 0 ; i < GGML_TYPE_COUNT; ++i) {
239
+ auto type = (ggml_type)i;
231
240
const auto * name = ggml_type_name (type);
232
- if (name && strcmp (arg, name) == 0 ) {
233
- result = type; break ;
241
+ if (name && striequals (name, arg) ) {
242
+ return type;
234
243
}
235
244
}
236
- return result;
245
+ fprintf (stderr, " %s: invalid ggml_type '%s'\n " , __func__, arg);
246
+ return GGML_TYPE_COUNT;
237
247
}
238
248
239
249
int main (int argc, char ** argv) {
@@ -254,12 +264,18 @@ int main(int argc, char ** argv) {
254
264
} else if (strcmp (argv[arg_idx], " --output-tensor-type" ) == 0 ) {
255
265
if (arg_idx < argc-1 ) {
256
266
params.output_tensor_type = parse_ggml_type (argv[++arg_idx]);
267
+ if (params.output_tensor_type == GGML_TYPE_COUNT) {
268
+ usage (argv[0 ]);
269
+ }
257
270
} else {
258
271
usage (argv[0 ]);
259
272
}
260
273
} else if (strcmp (argv[arg_idx], " --token-embedding-type" ) == 0 ) {
261
274
if (arg_idx < argc-1 ) {
262
275
params.token_embedding_type = parse_ggml_type (argv[++arg_idx]);
276
+ if (params.token_embedding_type == GGML_TYPE_COUNT) {
277
+ usage (argv[0 ]);
278
+ }
263
279
} else {
264
280
usage (argv[0 ]);
265
281
}
0 commit comments