From 6deab767f95194ec1a8eca897d12849747a8214f Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Sun, 26 May 2024 00:23:41 -0700 Subject: [PATCH] Introduce --diffable flag Sometimes it's useful to get an overview of how tensors changes when using different quantization formats. For example: diff -u <(gguf-tools show --diffable ggml-model-bf16.gguf) \ <(gguf-tools show --diffable ggml-model-Q6_K.gguf) | less Is now able to produces nice clean output. Without this change, every line would have been different due to the file offsets and byte sizes which means `diff -u` would produce one gigantic unreadable chunk. --- gguf-tools.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/gguf-tools.c b/gguf-tools.c index c847c17..ce54d0f 100644 --- a/gguf-tools.c +++ b/gguf-tools.c @@ -14,6 +14,7 @@ /* Global options that can could be used for all the subcommands. */ struct { int verbose; // --verbose option + int diffable; // --diffable option } Opt = {0}; /* ========================== Utility functions ============================ */ @@ -167,16 +168,20 @@ void gguf_tools_show(const char *filename) { gguf_tensor tensor; uint64_t params = 0; while (gguf_get_tensor(ctx,&tensor)) { - printf("%s tensor %.*s @%" PRIu64 ", %" PRIu64 " weights, dims ", + printf("%s tensor %.*s", gguf_get_tensor_type_name(tensor.type), (int)tensor.namelen, - tensor.name, - tensor.offset, - tensor.num_weights); + tensor.name); + if (!Opt.diffable) + printf(" @%" PRIu64, tensor.offset); + printf(", %" PRIu64 " weights, dims ", tensor.num_weights); for (uint32_t j = 0; j < tensor.ndim; j++) { printf("%s%" PRIu64 "",(j == 0) ? "[" : ",", tensor.dim[j]); } - printf("], %" PRIu64 " bytes\n", tensor.bsize); + printf("]"); + if (!Opt.diffable) + printf(", %" PRIu64 " bytes", tensor.bsize); + printf("\n"); params += tensor.num_weights; } @@ -507,6 +512,7 @@ void gguf_tools_usage(const char *progname) { " split-mixtral mixtral.gguf out.gguf -- extract expert.\n" "Options:\n" " --verbose :With 'show', print full arrays (e.g. token lists)\n" +" --diffable :Don't show tensor file offsets and sizes\n" "Example:\n" " split-mixtral 65230776370407150546470161412165 mixtral.gguf out.gguf\n" , progname); @@ -527,6 +533,11 @@ int main(int argc, char **argv) { argc--; Opt.verbose = 1; } + if (!strcmp(argv[j],"--diffable")) { + argv[j] = NULL; + argc--; + Opt.diffable = 1; + } } /* Strip empty elements. */