Skip to content

Commit 67e1868

Browse files
committed
[aux] GGUF split summary
The gguf-split utility now generates a `.txt` listing all tensors. Useful both for manual inspection/debugging and for incremental tensor loading where its not possible to know tensors present in other split files (the information is critical to handle optional tensors).
1 parent cd6f698 commit 67e1868

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

tools/gguf-split/gguf-split.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ static void split_print_usage(const char * executable) {
5050
printf("\n");
5151
printf("usage: %s [options] GGUF_IN GGUF_OUT\n", executable);
5252
printf("\n");
53-
printf("Apply a GGUF operation on IN to OUT.");
53+
printf("Apply a GGUF operation on IN to OUT.\n");
54+
printf("When splitting, also creates GGUF_OUT.tensors.txt with all tensor names.\n");
5455
printf("\n");
5556
printf("options:\n");
5657
printf(" -h, --help show this help message and exit\n");
@@ -303,6 +304,30 @@ struct split_strategy {
303304
}
304305
}
305306

307+
void write_tensor_list() {
308+
// Create a .txt file with all tensor names from all splits
309+
std::string tensor_list_path = params.output + ".tensors.txt";
310+
std::ofstream tensor_file(tensor_list_path);
311+
if (!tensor_file.is_open()) {
312+
fprintf(stderr, "warning: failed to create tensor list file %s\n", tensor_list_path.c_str());
313+
return;
314+
}
315+
316+
printf("Writing tensor list to %s ... ", tensor_list_path.c_str());
317+
fflush(stdout);
318+
319+
// Write all tensor names from all splits
320+
for (auto & ctx_out : ctx_outs) {
321+
for (int i = 0; i < gguf_get_n_tensors(ctx_out); ++i) {
322+
const char * t_name = gguf_get_tensor_name(ctx_out, i);
323+
tensor_file << t_name << "\n";
324+
}
325+
}
326+
327+
tensor_file.close();
328+
printf("done\n");
329+
}
330+
306331
void write() {
307332
int i_split = 0;
308333
int n_split = ctx_outs.size();
@@ -382,6 +407,9 @@ static void gguf_split(const split_params & split_params) {
382407
int n_split = strategy.ctx_outs.size();
383408
strategy.print_info();
384409

410+
// Write tensor list file
411+
strategy.write_tensor_list();
412+
385413
if (!split_params.dry_run) {
386414
// write all output splits
387415
strategy.write();

0 commit comments

Comments
 (0)