| 2352 | } |
| 2353 | |
| 2354 | bool bark_model_quantize(const char* fname_inp, const char* fname_out, enum ggml_ftype ftype) { |
| 2355 | printf("%s: loading model from '%s'\n", __func__, fname_inp); |
| 2356 | |
| 2357 | std::string fname_inp_str(fname_inp); |
| 2358 | std::string fname_out_str(fname_out); |
| 2359 | |
| 2360 | auto fin = std::ifstream(fname_inp_str, std::ios::binary); |
| 2361 | if (!fin) { |
| 2362 | fprintf(stderr, "%s: failed to open '%s' for reading\n", __func__, fname_inp); |
| 2363 | return false; |
| 2364 | } |
| 2365 | |
| 2366 | auto fout = std::ofstream(fname_out_str, std::ios::binary); |
| 2367 | if (!fout) { |
| 2368 | fprintf(stderr, "%s: failed to open '%s' for writing\n", __func__, fname_out); |
| 2369 | return false; |
| 2370 | } |
| 2371 | |
| 2372 | // verify magic |
| 2373 | { |
| 2374 | uint32_t magic; |
| 2375 | fin.read((char*)&magic, sizeof(magic)); |
| 2376 | if (magic != GGML_FILE_MAGIC) { |
| 2377 | fprintf(stderr, "%s: invalid model file '%s' (bad magic)\n", __func__, fname_inp); |
| 2378 | return false; |
| 2379 | } |
| 2380 | |
| 2381 | fout.write((char*)&magic, sizeof(magic)); |
| 2382 | } |
| 2383 | |
| 2384 | // transfer vocab data from fin to fout |
| 2385 | { |
| 2386 | uint32_t n_vocab; |
| 2387 | read_safe(fin, n_vocab); |
| 2388 | write_safe(fout, n_vocab); |
| 2389 | |
| 2390 | std::string word; |
| 2391 | for (int i = 0; i < n_vocab; i++) { |
| 2392 | uint32_t len; |
| 2393 | read_safe(fin, len); |
| 2394 | write_safe(fout, len); |
| 2395 | |
| 2396 | word.resize(len); |
| 2397 | fin.read((char*)word.data(), len); |
| 2398 | fout.write((char*)word.data(), len); |
| 2399 | } |
| 2400 | } |
| 2401 | |
| 2402 | // text model |
| 2403 | if (!bark_model_weights_quantize(fin, fout, ftype)) { |
| 2404 | fprintf(stderr, "%s: failed to quantize text model\n", __func__); |
| 2405 | return false; |
| 2406 | } |
| 2407 | |
| 2408 | // coarse model |
| 2409 | if (!bark_model_weights_quantize(fin, fout, ftype)) { |
| 2410 | fprintf(stderr, "%s: failed to quantize coarse model\n", __func__); |
| 2411 | return false; |
nothing calls this directly
no test coverage detected