| 2286 | } |
| 2287 | |
| 2288 | bool bark_model_weights_quantize(std::ifstream& fin, std::ofstream& fout, ggml_ftype ftype) { |
| 2289 | gpt_model model; |
| 2290 | gpt_hparams hparams; |
| 2291 | |
| 2292 | // load hparams |
| 2293 | { |
| 2294 | auto& hparams = model.hparams; |
| 2295 | |
| 2296 | read_safe(fin, hparams.n_layer); |
| 2297 | read_safe(fin, hparams.n_head); |
| 2298 | read_safe(fin, hparams.n_embd); |
| 2299 | read_safe(fin, hparams.block_size); |
| 2300 | read_safe(fin, hparams.bias); |
| 2301 | read_safe(fin, hparams.n_in_vocab); |
| 2302 | read_safe(fin, hparams.n_out_vocab); |
| 2303 | read_safe(fin, hparams.n_lm_heads); |
| 2304 | read_safe(fin, hparams.n_wtes); |
| 2305 | read_safe(fin, hparams.ftype); |
| 2306 | |
| 2307 | const int32_t qntvr_src = hparams.ftype / GGML_QNT_VERSION_FACTOR; |
| 2308 | int32_t ftype_dst = GGML_QNT_VERSION * GGML_QNT_VERSION_FACTOR + ftype; |
| 2309 | |
| 2310 | printf("%s: n_in_vocab = %d\n", __func__, hparams.n_in_vocab); |
| 2311 | printf("%s: n_out_vocab = %d\n", __func__, hparams.n_out_vocab); |
| 2312 | printf("%s: block_size = %d\n", __func__, hparams.block_size); |
| 2313 | printf("%s: bias = %d\n", __func__, hparams.bias); |
| 2314 | printf("%s: n_embd = %d\n", __func__, hparams.n_embd); |
| 2315 | printf("%s: n_head = %d\n", __func__, hparams.n_head); |
| 2316 | printf("%s: n_layer = %d\n", __func__, hparams.n_layer); |
| 2317 | printf("%s: n_lm_heads = %d\n", __func__, hparams.n_lm_heads); |
| 2318 | printf("%s: n_wtes = %d\n", __func__, hparams.n_wtes); |
| 2319 | printf("%s: ftype (src) = %d\n", __func__, hparams.ftype); |
| 2320 | printf("%s: qntvr (src) = %d\n", __func__, qntvr_src); |
| 2321 | printf("%s: ftype (dst) = %d\n", __func__, ftype_dst); |
| 2322 | printf("%s: qntvr (dst) = %d\n", __func__, GGML_QNT_VERSION); |
| 2323 | |
| 2324 | write_safe(fout, hparams.n_layer); |
| 2325 | write_safe(fout, hparams.n_head); |
| 2326 | write_safe(fout, hparams.n_embd); |
| 2327 | write_safe(fout, hparams.block_size); |
| 2328 | write_safe(fout, hparams.bias); |
| 2329 | write_safe(fout, hparams.n_in_vocab); |
| 2330 | write_safe(fout, hparams.n_out_vocab); |
| 2331 | write_safe(fout, hparams.n_lm_heads); |
| 2332 | write_safe(fout, hparams.n_wtes); |
| 2333 | write_safe(fout, ftype_dst); |
| 2334 | } |
| 2335 | |
| 2336 | // regexes of tensor names to be quantized |
| 2337 | const std::vector<std::string> to_quant = { |
| 2338 | "model/wte/.*", |
| 2339 | "model/lm_head/.*", |
| 2340 | "model/h.*/attn/c_attn/w", |
| 2341 | "model/h.*/attn/c_proj/w", |
| 2342 | "model/h.*/mlp/c_fc/w", |
| 2343 | "model/h.*/mlp/c_proj/w", |
| 2344 | }; |
| 2345 |
no test coverage detected