1
0

quantize.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. #include "common.h"
  2. #include "llama.h"
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <vector>
  6. #include <string>
  7. #include <unordered_map>
  8. #include <fstream>
  9. #include <cmath>
  10. #include <cctype>
  11. struct quant_option {
  12. std::string name;
  13. llama_ftype ftype;
  14. std::string desc;
  15. };
  16. static const std::vector<struct quant_option> QUANT_OPTIONS = {
  17. { "Q4_0", LLAMA_FTYPE_MOSTLY_Q4_0, " 4.34G, +0.4685 ppl @ Llama-3-8B", },
  18. { "Q4_1", LLAMA_FTYPE_MOSTLY_Q4_1, " 4.78G, +0.4511 ppl @ Llama-3-8B", },
  19. { "Q5_0", LLAMA_FTYPE_MOSTLY_Q5_0, " 5.21G, +0.1316 ppl @ Llama-3-8B", },
  20. { "Q5_1", LLAMA_FTYPE_MOSTLY_Q5_1, " 5.65G, +0.1062 ppl @ Llama-3-8B", },
  21. { "IQ2_XXS", LLAMA_FTYPE_MOSTLY_IQ2_XXS, " 2.06 bpw quantization", },
  22. { "IQ2_XS", LLAMA_FTYPE_MOSTLY_IQ2_XS, " 2.31 bpw quantization", },
  23. { "IQ2_S", LLAMA_FTYPE_MOSTLY_IQ2_S, " 2.5 bpw quantization", },
  24. { "IQ2_M", LLAMA_FTYPE_MOSTLY_IQ2_M, " 2.7 bpw quantization", },
  25. { "IQ1_S", LLAMA_FTYPE_MOSTLY_IQ1_S, " 1.56 bpw quantization", },
  26. { "IQ1_M", LLAMA_FTYPE_MOSTLY_IQ1_M, " 1.75 bpw quantization", },
  27. { "TQ1_0", LLAMA_FTYPE_MOSTLY_TQ1_0, " 1.69 bpw ternarization", },
  28. { "TQ2_0", LLAMA_FTYPE_MOSTLY_TQ2_0, " 2.06 bpw ternarization", },
  29. { "Q2_K", LLAMA_FTYPE_MOSTLY_Q2_K, " 2.96G, +3.5199 ppl @ Llama-3-8B", },
  30. { "Q2_K_S", LLAMA_FTYPE_MOSTLY_Q2_K_S, " 2.96G, +3.1836 ppl @ Llama-3-8B", },
  31. { "IQ3_XXS", LLAMA_FTYPE_MOSTLY_IQ3_XXS, " 3.06 bpw quantization", },
  32. { "IQ3_S", LLAMA_FTYPE_MOSTLY_IQ3_S, " 3.44 bpw quantization", },
  33. { "IQ3_M", LLAMA_FTYPE_MOSTLY_IQ3_M, " 3.66 bpw quantization mix", },
  34. { "Q3_K", LLAMA_FTYPE_MOSTLY_Q3_K_M, "alias for Q3_K_M" },
  35. { "IQ3_XS", LLAMA_FTYPE_MOSTLY_IQ3_XS, " 3.3 bpw quantization", },
  36. { "Q3_K_S", LLAMA_FTYPE_MOSTLY_Q3_K_S, " 3.41G, +1.6321 ppl @ Llama-3-8B", },
  37. { "Q3_K_M", LLAMA_FTYPE_MOSTLY_Q3_K_M, " 3.74G, +0.6569 ppl @ Llama-3-8B", },
  38. { "Q3_K_L", LLAMA_FTYPE_MOSTLY_Q3_K_L, " 4.03G, +0.5562 ppl @ Llama-3-8B", },
  39. { "IQ4_NL", LLAMA_FTYPE_MOSTLY_IQ4_NL, " 4.50 bpw non-linear quantization", },
  40. { "IQ4_XS", LLAMA_FTYPE_MOSTLY_IQ4_XS, " 4.25 bpw non-linear quantization", },
  41. { "Q4_K", LLAMA_FTYPE_MOSTLY_Q4_K_M, "alias for Q4_K_M", },
  42. { "Q4_K_S", LLAMA_FTYPE_MOSTLY_Q4_K_S, " 4.37G, +0.2689 ppl @ Llama-3-8B", },
  43. { "Q4_K_M", LLAMA_FTYPE_MOSTLY_Q4_K_M, " 4.58G, +0.1754 ppl @ Llama-3-8B", },
  44. { "Q5_K", LLAMA_FTYPE_MOSTLY_Q5_K_M, "alias for Q5_K_M", },
  45. { "Q5_K_S", LLAMA_FTYPE_MOSTLY_Q5_K_S, " 5.21G, +0.1049 ppl @ Llama-3-8B", },
  46. { "Q5_K_M", LLAMA_FTYPE_MOSTLY_Q5_K_M, " 5.33G, +0.0569 ppl @ Llama-3-8B", },
  47. { "Q6_K", LLAMA_FTYPE_MOSTLY_Q6_K, " 6.14G, +0.0217 ppl @ Llama-3-8B", },
  48. { "Q8_0", LLAMA_FTYPE_MOSTLY_Q8_0, " 7.96G, +0.0026 ppl @ Llama-3-8B", },
  49. { "F16", LLAMA_FTYPE_MOSTLY_F16, "14.00G, +0.0020 ppl @ Mistral-7B", },
  50. { "BF16", LLAMA_FTYPE_MOSTLY_BF16, "14.00G, -0.0050 ppl @ Mistral-7B", },
  51. { "F32", LLAMA_FTYPE_ALL_F32, "26.00G @ 7B", },
  52. // Note: Ensure COPY comes after F32 to avoid ftype 0 from matching.
  53. { "COPY", LLAMA_FTYPE_ALL_F32, "only copy tensors, no quantizing", },
  54. };
  55. static const char * const LLM_KV_QUANTIZE_IMATRIX_FILE = "quantize.imatrix.file";
  56. static const char * const LLM_KV_QUANTIZE_IMATRIX_DATASET = "quantize.imatrix.dataset";
  57. static const char * const LLM_KV_QUANTIZE_IMATRIX_N_ENTRIES = "quantize.imatrix.entries_count";
  58. static const char * const LLM_KV_QUANTIZE_IMATRIX_N_CHUNKS = "quantize.imatrix.chunks_count";
  59. static bool striequals(const char * a, const char * b) {
  60. while (*a && *b) {
  61. if (std::tolower(*a) != std::tolower(*b)) {
  62. return false;
  63. }
  64. a++; b++;
  65. }
  66. return *a == *b;
  67. }
  68. static bool try_parse_ftype(const std::string & ftype_str_in, llama_ftype & ftype, std::string & ftype_str_out) {
  69. std::string ftype_str;
  70. for (auto ch : ftype_str_in) {
  71. ftype_str.push_back(std::toupper(ch));
  72. }
  73. for (auto & it : QUANT_OPTIONS) {
  74. if (striequals(it.name.c_str(), ftype_str.c_str())) {
  75. ftype = it.ftype;
  76. ftype_str_out = it.name;
  77. return true;
  78. }
  79. }
  80. try {
  81. int ftype_int = std::stoi(ftype_str);
  82. for (auto & it : QUANT_OPTIONS) {
  83. if (it.ftype == ftype_int) {
  84. ftype = it.ftype;
  85. ftype_str_out = it.name;
  86. return true;
  87. }
  88. }
  89. }
  90. catch (...) {
  91. // stoi failed
  92. }
  93. return false;
  94. }
  95. // usage:
  96. // ./llama-quantize [--allow-requantize] [--leave-output-tensor] [--pure] models/llama/ggml-model.gguf [models/llama/ggml-model-quant.gguf] type [nthreads]
  97. //
  98. [[noreturn]]
  99. static void usage(const char * executable) {
  100. printf("usage: %s [--help] [--allow-requantize] [--leave-output-tensor] [--pure] [--imatrix] [--include-weights] [--exclude-weights] [--output-tensor-type] [--token-embedding-type] [--override-kv] model-f32.gguf [model-quant.gguf] type [nthreads]\n\n", executable);
  101. printf(" --allow-requantize: Allows requantizing tensors that have already been quantized. Warning: This can severely reduce quality compared to quantizing from 16bit or 32bit\n");
  102. printf(" --leave-output-tensor: Will leave output.weight un(re)quantized. Increases model size but may also increase quality, especially when requantizing\n");
  103. printf(" --pure: Disable k-quant mixtures and quantize all tensors to the same type\n");
  104. printf(" --imatrix file_name: use data in file_name as importance matrix for quant optimizations\n");
  105. printf(" --include-weights tensor_name: use importance matrix for this/these tensor(s)\n");
  106. printf(" --exclude-weights tensor_name: use importance matrix for this/these tensor(s)\n");
  107. printf(" --output-tensor-type ggml_type: use this ggml_type for the output.weight tensor\n");
  108. printf(" --token-embedding-type ggml_type: use this ggml_type for the token embeddings tensor\n");
  109. printf(" --keep-split: will generate quantized model in the same shards as input\n");
  110. printf(" --override-kv KEY=TYPE:VALUE\n");
  111. printf(" Advanced option to override model metadata by key in the quantized model. May be specified multiple times.\n");
  112. printf("Note: --include-weights and --exclude-weights cannot be used together\n");
  113. printf("\nAllowed quantization types:\n");
  114. for (auto & it : QUANT_OPTIONS) {
  115. if (it.name != "COPY") {
  116. printf(" %2d or ", it.ftype);
  117. } else {
  118. printf(" ");
  119. }
  120. printf("%-7s : %s\n", it.name.c_str(), it.desc.c_str());
  121. }
  122. exit(1);
  123. }
  124. static int load_imatrix(const std::string & imatrix_file, std::string & imatrix_dataset, std::unordered_map<std::string, std::vector<float>> & imatrix_data) {
  125. std::ifstream in(imatrix_file.c_str(), std::ios::binary);
  126. if (!in) {
  127. printf("%s: failed to open %s\n",__func__, imatrix_file.c_str());
  128. exit(1);
  129. }
  130. int n_entries;
  131. in.read((char *)&n_entries, sizeof(n_entries));
  132. if (in.fail() || n_entries < 1) {
  133. printf("%s: no data in file %s\n", __func__, imatrix_file.c_str());
  134. exit(1);
  135. }
  136. for (int i = 0; i < n_entries; ++i) {
  137. int len; in.read((char *)&len, sizeof(len));
  138. std::vector<char> name_as_vec(len+1);
  139. in.read((char *)name_as_vec.data(), len);
  140. if (in.fail()) {
  141. printf("%s: failed reading name for entry %d from %s\n", __func__, i+1, imatrix_file.c_str());
  142. exit(1);
  143. }
  144. name_as_vec[len] = 0;
  145. std::string name{name_as_vec.data()};
  146. auto & e = imatrix_data[name];
  147. int ncall;
  148. in.read((char *)&ncall, sizeof(ncall));
  149. int nval;
  150. in.read((char *)&nval, sizeof(nval));
  151. if (in.fail() || nval < 1) {
  152. printf("%s: failed reading number of values for entry %d\n", __func__, i);
  153. imatrix_data = {};
  154. exit(1);
  155. }
  156. e.resize(nval);
  157. in.read((char *)e.data(), nval*sizeof(float));
  158. if (in.fail()) {
  159. printf("%s: failed reading data for entry %d\n", __func__, i);
  160. imatrix_data = {};
  161. exit(1);
  162. }
  163. if (ncall > 0) {
  164. for (auto& v : e) v /= ncall;
  165. }
  166. if (getenv("LLAMA_TRACE")) {
  167. printf("%s: loaded data (size = %6d, ncall = %6d) for '%s'\n", __func__, int(e.size()), ncall, name.c_str());
  168. }
  169. }
  170. // latest imatrix version contains the dataset filename at the end of the file
  171. int m_last_call = 0;
  172. if (in.peek() != EOF) {
  173. in.read((char *)&m_last_call, sizeof(m_last_call));
  174. int dataset_len;
  175. in.read((char *)&dataset_len, sizeof(dataset_len));
  176. std::vector<char> dataset_as_vec(dataset_len);
  177. in.read(dataset_as_vec.data(), dataset_len);
  178. imatrix_dataset.assign(dataset_as_vec.begin(), dataset_as_vec.end());
  179. printf("%s: imatrix dataset='%s'\n", __func__, imatrix_dataset.c_str());
  180. }
  181. printf("%s: loaded %d importance matrix entries from %s computed on %d chunks\n", __func__, int(imatrix_data.size()), imatrix_file.c_str(), m_last_call);
  182. return m_last_call;
  183. }
  184. static int prepare_imatrix(const std::string & imatrix_file,
  185. std::string & imatrix_dataset,
  186. const std::vector<std::string> & included_weights,
  187. const std::vector<std::string> & excluded_weights,
  188. std::unordered_map<std::string, std::vector<float>> & imatrix_data) {
  189. int m_last_call = -1;
  190. if (!imatrix_file.empty()) {
  191. m_last_call = load_imatrix(imatrix_file, imatrix_dataset, imatrix_data);
  192. }
  193. if (imatrix_data.empty()) {
  194. return m_last_call;
  195. }
  196. if (!excluded_weights.empty()) {
  197. for (auto& name : excluded_weights) {
  198. for (auto it = imatrix_data.begin(); it != imatrix_data.end(); ) {
  199. auto pos = it->first.find(name);
  200. if (pos != std::string::npos) it = imatrix_data.erase(it);
  201. else ++it;
  202. }
  203. }
  204. }
  205. if (!included_weights.empty()) {
  206. std::unordered_map<std::string, std::vector<float>> tmp;
  207. for (auto& name : included_weights) {
  208. for (auto& e : imatrix_data) {
  209. auto pos = e.first.find(name);
  210. if (pos != std::string::npos) {
  211. tmp.emplace(std::move(e));
  212. }
  213. }
  214. }
  215. imatrix_data = std::move(tmp);
  216. }
  217. if (!imatrix_data.empty()) {
  218. printf("%s: have %d importance matrix entries\n", __func__, int(imatrix_data.size()));
  219. }
  220. return m_last_call;
  221. }
  222. static ggml_type parse_ggml_type(const char * arg) {
  223. for (int i = 0; i < GGML_TYPE_COUNT; ++i) {
  224. auto type = (ggml_type)i;
  225. const auto * name = ggml_type_name(type);
  226. if (name && striequals(name, arg)) {
  227. return type;
  228. }
  229. }
  230. fprintf(stderr, "%s: invalid ggml_type '%s'\n", __func__, arg);
  231. return GGML_TYPE_COUNT;
  232. }
  233. int main(int argc, char ** argv) {
  234. if (argc < 3) {
  235. usage(argv[0]);
  236. }
  237. llama_model_quantize_params params = llama_model_quantize_default_params();
  238. int arg_idx = 1;
  239. std::string imatrix_file;
  240. std::vector<std::string> included_weights, excluded_weights;
  241. std::vector<llama_model_kv_override> kv_overrides;
  242. for (; arg_idx < argc && strncmp(argv[arg_idx], "--", 2) == 0; arg_idx++) {
  243. if (strcmp(argv[arg_idx], "--leave-output-tensor") == 0) {
  244. params.quantize_output_tensor = false;
  245. } else if (strcmp(argv[arg_idx], "--output-tensor-type") == 0) {
  246. if (arg_idx < argc-1) {
  247. params.output_tensor_type = parse_ggml_type(argv[++arg_idx]);
  248. if (params.output_tensor_type == GGML_TYPE_COUNT) {
  249. usage(argv[0]);
  250. }
  251. } else {
  252. usage(argv[0]);
  253. }
  254. } else if (strcmp(argv[arg_idx], "--token-embedding-type") == 0) {
  255. if (arg_idx < argc-1) {
  256. params.token_embedding_type = parse_ggml_type(argv[++arg_idx]);
  257. if (params.token_embedding_type == GGML_TYPE_COUNT) {
  258. usage(argv[0]);
  259. }
  260. } else {
  261. usage(argv[0]);
  262. }
  263. } else if (strcmp(argv[arg_idx], "--override-kv") == 0) {
  264. if (arg_idx == argc-1 || !string_parse_kv_override(argv[++arg_idx], kv_overrides)) {
  265. usage(argv[0]);
  266. }
  267. } else if (strcmp(argv[arg_idx], "--allow-requantize") == 0) {
  268. params.allow_requantize = true;
  269. } else if (strcmp(argv[arg_idx], "--pure") == 0) {
  270. params.pure = true;
  271. } else if (strcmp(argv[arg_idx], "--imatrix") == 0) {
  272. if (arg_idx < argc-1) {
  273. imatrix_file = argv[++arg_idx];
  274. } else {
  275. usage(argv[0]);
  276. }
  277. } else if (strcmp(argv[arg_idx], "--include-weights") == 0) {
  278. if (arg_idx < argc-1) {
  279. included_weights.emplace_back(argv[++arg_idx]);
  280. } else {
  281. usage(argv[0]);
  282. }
  283. } else if (strcmp(argv[arg_idx], "--exclude-weights") == 0) {
  284. if (arg_idx < argc-1) {
  285. excluded_weights.emplace_back(argv[++arg_idx]);
  286. } else {
  287. usage(argv[0]);
  288. }
  289. } else if (strcmp(argv[arg_idx], "--keep-split") == 0) {
  290. params.keep_split = true;
  291. } else {
  292. usage(argv[0]);
  293. }
  294. }
  295. if (argc - arg_idx < 2) {
  296. printf("%s: bad arguments\n", argv[0]);
  297. usage(argv[0]);
  298. }
  299. if (!included_weights.empty() && !excluded_weights.empty()) {
  300. usage(argv[0]);
  301. }
  302. std::string imatrix_dataset;
  303. std::unordered_map<std::string, std::vector<float>> imatrix_data;
  304. int m_last_call = prepare_imatrix(imatrix_file, imatrix_dataset, included_weights, excluded_weights, imatrix_data);
  305. if (!imatrix_data.empty()) {
  306. params.imatrix = &imatrix_data;
  307. {
  308. llama_model_kv_override kvo;
  309. std::strcpy(kvo.key, LLM_KV_QUANTIZE_IMATRIX_FILE);
  310. kvo.tag = LLAMA_KV_OVERRIDE_TYPE_STR;
  311. strncpy(kvo.val_str, imatrix_file.c_str(), 127);
  312. kvo.val_str[127] = '\0';
  313. kv_overrides.emplace_back(std::move(kvo));
  314. }
  315. if (!imatrix_dataset.empty()) {
  316. llama_model_kv_override kvo;
  317. std::strcpy(kvo.key, LLM_KV_QUANTIZE_IMATRIX_DATASET);
  318. kvo.tag = LLAMA_KV_OVERRIDE_TYPE_STR;
  319. strncpy(kvo.val_str, imatrix_dataset.c_str(), 127);
  320. kvo.val_str[127] = '\0';
  321. kv_overrides.emplace_back(std::move(kvo));
  322. }
  323. {
  324. llama_model_kv_override kvo;
  325. std::strcpy(kvo.key, LLM_KV_QUANTIZE_IMATRIX_N_ENTRIES);
  326. kvo.tag = LLAMA_KV_OVERRIDE_TYPE_INT;
  327. kvo.val_i64 = imatrix_data.size();
  328. kv_overrides.emplace_back(std::move(kvo));
  329. }
  330. if (m_last_call > 0) {
  331. llama_model_kv_override kvo;
  332. std::strcpy(kvo.key, LLM_KV_QUANTIZE_IMATRIX_N_CHUNKS);
  333. kvo.tag = LLAMA_KV_OVERRIDE_TYPE_INT;
  334. kvo.val_i64 = m_last_call;
  335. kv_overrides.emplace_back(std::move(kvo));
  336. }
  337. }
  338. if (!kv_overrides.empty()) {
  339. kv_overrides.emplace_back();
  340. kv_overrides.back().key[0] = 0;
  341. params.kv_overrides = &kv_overrides;
  342. }
  343. llama_backend_init();
  344. // parse command line arguments
  345. const std::string fname_inp = argv[arg_idx];
  346. arg_idx++;
  347. std::string fname_out;
  348. std::string ftype_str;
  349. std::string suffix = ".gguf";
  350. if (try_parse_ftype(argv[arg_idx], params.ftype, ftype_str)) {
  351. std::string fpath;
  352. const size_t pos = fname_inp.find_last_of("/\\");
  353. if (pos != std::string::npos) {
  354. fpath = fname_inp.substr(0, pos + 1);
  355. }
  356. // export as [inp path]/ggml-model-[ftype]. Only add extension if there is no splitting
  357. fname_out = fpath + "ggml-model-" + ftype_str;
  358. if (!params.keep_split) {
  359. fname_out += suffix;
  360. }
  361. arg_idx++;
  362. if (ftype_str == "COPY") {
  363. params.only_copy = true;
  364. }
  365. } else {
  366. fname_out = argv[arg_idx];
  367. if (params.keep_split && fname_out.find(suffix) != std::string::npos) {
  368. fname_out = fname_out.substr(0, fname_out.length() - suffix.length());
  369. }
  370. arg_idx++;
  371. if (argc <= arg_idx) {
  372. fprintf(stderr, "%s: missing ftype\n", __func__);
  373. return 1;
  374. }
  375. if (!try_parse_ftype(argv[arg_idx], params.ftype, ftype_str)) {
  376. fprintf(stderr, "%s: invalid ftype '%s'\n", __func__, argv[3]);
  377. return 1;
  378. }
  379. if (ftype_str == "COPY") {
  380. params.only_copy = true;
  381. }
  382. arg_idx++;
  383. }
  384. // parse nthreads
  385. if (argc > arg_idx) {
  386. try {
  387. params.nthread = std::stoi(argv[arg_idx]);
  388. }
  389. catch (const std::exception & e) {
  390. fprintf(stderr, "%s: invalid nthread '%s' (%s)\n", __func__, argv[arg_idx], e.what());
  391. return 1;
  392. }
  393. }
  394. if ((params.ftype == LLAMA_FTYPE_MOSTLY_IQ2_XS || params.ftype == LLAMA_FTYPE_MOSTLY_IQ2_XXS ||
  395. params.ftype == LLAMA_FTYPE_MOSTLY_IQ2_S ||
  396. params.ftype == LLAMA_FTYPE_MOSTLY_Q2_K_S ||
  397. params.ftype == LLAMA_FTYPE_MOSTLY_IQ1_S ||
  398. params.ftype == LLAMA_FTYPE_MOSTLY_IQ1_M) && imatrix_data.empty()) {
  399. fprintf(stderr, "\n==========================================================================================================\n");
  400. fprintf(stderr, "Please do not use IQ1_S, IQ1_M, IQ2_S, IQ2_XXS, IQ2_XS or Q2_K_S quantization without an importance matrix\n");
  401. fprintf(stderr, "==========================================================================================================\n\n\n");
  402. return 1;
  403. }
  404. print_build_info();
  405. fprintf(stderr, "%s: quantizing '%s' to '%s' as %s", __func__, fname_inp.c_str(), fname_out.c_str(), ftype_str.c_str());
  406. if (params.nthread > 0) {
  407. fprintf(stderr, " using %d threads", params.nthread);
  408. }
  409. fprintf(stderr, "\n");
  410. const int64_t t_main_start_us = llama_time_us();
  411. int64_t t_quantize_us = 0;
  412. // load the model
  413. {
  414. const int64_t t_start_us = llama_time_us();
  415. if (llama_model_quantize(fname_inp.c_str(), fname_out.c_str(), &params)) {
  416. fprintf(stderr, "%s: failed to quantize model from '%s'\n", __func__, fname_inp.c_str());
  417. return 1;
  418. }
  419. t_quantize_us = llama_time_us() - t_start_us;
  420. }
  421. // report timing
  422. {
  423. const int64_t t_main_end_us = llama_time_us();
  424. printf("\n");
  425. printf("%s: quantize time = %8.2f ms\n", __func__, t_quantize_us/1000.0);
  426. printf("%s: total time = %8.2f ms\n", __func__, (t_main_end_us - t_main_start_us)/1000.0);
  427. }
  428. llama_backend_free();
  429. return 0;
  430. }