MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / main

Function main

examples/quantize.cpp:333–374  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331}
332
333int main(int argc, char ** argv) {
334 if (argc != 4) {
335 fprintf(stderr, "usage: %s model.ggml model-quant.ggml type\n", argv[0]);
336 fprintf(stderr, " supported types: q4_0, q4_1, q8_0\n");
337 return 1;
338 }
339
340 // Init ggml (needed for fp16 lookup tables)
341 {
342 struct ggml_init_params params = { 0, NULL, false };
343 struct ggml_context * ctx = ggml_init(params);
344 ggml_free(ctx);
345 }
346
347 const std::string fname_inp = argv[1];
348 const std::string fname_out = argv[2];
349
350 ggml_type qtype = GGML_TYPE_COUNT;
351 if (strcmp(argv[3], "q4_0") == 0) qtype = GGML_TYPE_Q4_0;
352 else if (strcmp(argv[3], "q4_1") == 0) qtype = GGML_TYPE_Q4_1;
353 else if (strcmp(argv[3], "q8_0") == 0) qtype = GGML_TYPE_Q8_0;
354 else {
355 fprintf(stderr, "%s: unknown quantization type '%s'\n", argv[0], argv[3]);
356 fprintf(stderr, " supported types: q4_0, q4_1, q8_0\n");
357 return 1;
358 }
359
360 fprintf(stderr, "%s: quantizing '%s' -> '%s' (%s)\n",
361 __func__, fname_inp.c_str(), fname_out.c_str(), ggml_type_name(qtype));
362
363 const int64_t t_start = ggml_time_us();
364
365 if (!sam3_quantize_model(fname_inp, fname_out, qtype)) {
366 fprintf(stderr, "%s: failed to quantize model\n", __func__);
367 return 1;
368 }
369
370 const double t_elapsed = (ggml_time_us() - t_start) / 1e6;
371 printf("%s: quantize time = %.2f s\n", __func__, t_elapsed);
372
373 return 0;
374}

Callers

nothing calls this directly

Calls 1

sam3_quantize_modelFunction · 0.85

Tested by

no test coverage detected