aboutsummaryrefslogtreecommitdiff
path: root/examples/quantize
diff options
context:
space:
mode:
authorKawrakow <48489457+ikawrakow@users.noreply.github.com>2023-04-20 19:42:27 +0200
committerGitHub <noreply@github.com>2023-04-20 20:42:27 +0300
commit38de86a7114c97ecf3644e3a60159f1ed893e1b0 (patch)
treefc6b90dd99825ce4e745304aab484b85903949c0 /examples/quantize
parente0305ead3a072db9c08b35c9600c49273b38a4b5 (diff)
llama : multi-threaded quantization (#1075)
* Multi-threading quantization. Not much gain for simple quantizations, bit it will be important for quantizations that require more CPU cycles. * Multi-threading for quantize-stats It now does the job in ~14 seconds on my Mac for Q4_0, Q4_1 and Q4_2. Single-threaded it was taking more than 2 minutes after adding the more elaborate version of Q4_2. * Reviewer comments * Avoiding compiler confusion After changing chunk_size to const int as suggested by @ggerganov, clang and GCC starting to warn me that I don't need to capture it in the lambda. So, I removed it from the capture list. But that makes the MSVC build fail. So, making it a constexpr to make every compiler happy. * Still fighting with lambda captures in MSVC --------- Co-authored-by: Iwan Kawrakow <iwan.kawrakow@gmail.com> Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Diffstat (limited to 'examples/quantize')
-rw-r--r--examples/quantize/quantize.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/examples/quantize/quantize.cpp b/examples/quantize/quantize.cpp
index 49a33a8..5b4812c 100644
--- a/examples/quantize/quantize.cpp
+++ b/examples/quantize/quantize.cpp
@@ -10,8 +10,8 @@
int main(int argc, char ** argv) {
ggml_time_init();
- if (argc != 4) {
- fprintf(stderr, "usage: %s model-f32.bin model-quant.bin type\n", argv[0]);
+ 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);
@@ -30,6 +30,7 @@ int main(int argc, char ** argv) {
const std::string fname_out = argv[2];
const enum llama_ftype 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();
@@ -39,7 +40,7 @@ int main(int argc, char ** argv) {
{
const int64_t t_start_us = ggml_time_us();
- if (llama_model_quantize(fname_inp.c_str(), fname_out.c_str(), ftype)) {
+ if (llama_model_quantize(fname_inp.c_str(), fname_out.c_str(), ftype, nthread)) {
fprintf(stderr, "%s: failed to quantize model from '%s'\n", __func__, fname_inp.c_str());
return 1;
}