| 358 | }; |
| 359 | |
| 360 | static void gguf_split(const split_params & split_params) { |
| 361 | struct ggml_context * ctx_meta = NULL; |
| 362 | |
| 363 | struct gguf_init_params params = { |
| 364 | /*.no_alloc = */ true, |
| 365 | /*.ctx = */ &ctx_meta, |
| 366 | }; |
| 367 | |
| 368 | std::ifstream f_input(split_params.input.c_str(), std::ios::binary); |
| 369 | if (!f_input.is_open()) { |
| 370 | fprintf(stderr, "%s: failed to open input GGUF from %s\n", __func__, split_params.input.c_str()); |
| 371 | exit(EXIT_FAILURE); |
| 372 | } |
| 373 | |
| 374 | auto * ctx_gguf = gguf_init_from_file(split_params.input.c_str(), params); |
| 375 | if (!ctx_gguf) { |
| 376 | fprintf(stderr, "%s: failed to load input GGUF from %s\n", __func__, split_params.input.c_str()); |
| 377 | exit(EXIT_FAILURE); |
| 378 | } |
| 379 | |
| 380 | // prepare the strategy |
| 381 | split_strategy strategy(split_params, f_input, ctx_gguf, ctx_meta); |
| 382 | int n_split = strategy.ctx_outs.size(); |
| 383 | strategy.print_info(); |
| 384 | |
| 385 | if (!split_params.dry_run) { |
| 386 | // write all output splits |
| 387 | strategy.write(); |
| 388 | } |
| 389 | |
| 390 | // done, clean up |
| 391 | gguf_free(ctx_gguf); |
| 392 | f_input.close(); |
| 393 | |
| 394 | fprintf(stderr, "%s: %d gguf split written with a total of %d tensors.\n", |
| 395 | __func__, n_split, strategy.n_tensors); |
| 396 | } |
| 397 | |
| 398 | static void gguf_merge(const split_params & split_params) { |
| 399 | fprintf(stderr, "%s: %s -> %s\n", |
no test coverage detected