aboutsummaryrefslogtreecommitdiff
path: root/examples/quantize/quantize.cpp
diff options
context:
space:
mode:
authorPavol Rusnak <pavol@rusnak.io>2023-04-26 18:43:27 +0200
committerGitHub <noreply@github.com>2023-04-26 18:43:27 +0200
commit859fee6dfb00fab7ce6bc215b4adae78d82f4759 (patch)
tree6f324d31645fe980ab2a3e0745870dd0592bff36 /examples/quantize/quantize.cpp
parent4afcc378698e057fcde64e23eb664e5af8dd6956 (diff)
quantize : use `map` to assign quantization type from `string` (#1191)
instead of `int` (while `int` option still being supported) This allows the following usage: `./quantize ggml-model-f16.bin ggml-model-q4_0.bin q4_0` instead of: `./quantize ggml-model-f16.bin ggml-model-q4_0.bin 2`
Diffstat (limited to 'examples/quantize/quantize.cpp')
-rw-r--r--examples/quantize/quantize.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/examples/quantize/quantize.cpp b/examples/quantize/quantize.cpp
index ad39a80..ec7f91a 100644
--- a/examples/quantize/quantize.cpp
+++ b/examples/quantize/quantize.cpp
@@ -2,8 +2,17 @@
#include "llama.h"
#include <cstdio>
+#include <map>
#include <string>
+static const std::map<std::string, enum llama_ftype> LLAMA_FTYPE_MAP = {
+ {"q4_0", LLAMA_FTYPE_MOSTLY_Q4_0},
+ {"q4_1", LLAMA_FTYPE_MOSTLY_Q4_1},
+ {"q4_2", LLAMA_FTYPE_MOSTLY_Q4_2},
+ {"q4_3", LLAMA_FTYPE_MOSTLY_Q4_3},
+ {"q8_0", LLAMA_FTYPE_MOSTLY_Q8_0},
+};
+
// usage:
// ./quantize models/llama/ggml-model.bin models/llama/ggml-model-quant.bin type
//
@@ -12,11 +21,9 @@ int main(int argc, char ** argv) {
if (argc < 4) {
fprintf(stderr, "usage: %s model-f32.bin model-quant.bin type [nthread]\n", argv[0]);
- fprintf(stderr, " type = %d - q4_0\n", LLAMA_FTYPE_MOSTLY_Q4_0);
- fprintf(stderr, " type = %d - q4_1\n", LLAMA_FTYPE_MOSTLY_Q4_1);
- fprintf(stderr, " type = %d - q4_2\n", LLAMA_FTYPE_MOSTLY_Q4_2);
- fprintf(stderr, " type = %d - q4_3\n", LLAMA_FTYPE_MOSTLY_Q4_3);
- fprintf(stderr, " type = %d - q8_0\n", LLAMA_FTYPE_MOSTLY_Q8_0);
+ for (auto it = LLAMA_FTYPE_MAP.begin(); it != LLAMA_FTYPE_MAP.end(); it++) {
+ fprintf(stderr, " type = \"%s\" or %d\n", it->first.c_str(), it->second);
+ }
return 1;
}
@@ -30,7 +37,18 @@ int main(int argc, char ** argv) {
const std::string fname_inp = argv[1];
const std::string fname_out = argv[2];
- const enum llama_ftype ftype = (enum llama_ftype)atoi(argv[3]);
+ enum llama_ftype ftype;
+ if (argv[3][0] == 'q') {
+ auto it = LLAMA_FTYPE_MAP.find(argv[3]);
+ if (it == LLAMA_FTYPE_MAP.end()) {
+ fprintf(stderr, "%s: unknown ftype '%s'\n", __func__, argv[3]);
+ return 1;
+ }
+ ftype = it->second;
+ } else {
+ ftype = (enum llama_ftype)atoi(argv[3]);
+ }
+
int nthread = argc > 4 ? atoi(argv[4]) : 0;
const int64_t t_main_start_us = ggml_time_us();