mirror of
https://github.com/antirez/gguf-tools.git
synced 2025-09-18 12:48:08 +08:00
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.
This commit is contained in:
21
gguf-tools.c
21
gguf-tools.c
@@ -14,6 +14,7 @@
|
|||||||
/* Global options that can could be used for all the subcommands. */
|
/* Global options that can could be used for all the subcommands. */
|
||||||
struct {
|
struct {
|
||||||
int verbose; // --verbose option
|
int verbose; // --verbose option
|
||||||
|
int diffable; // --diffable option
|
||||||
} Opt = {0};
|
} Opt = {0};
|
||||||
|
|
||||||
/* ========================== Utility functions ============================ */
|
/* ========================== Utility functions ============================ */
|
||||||
@@ -167,16 +168,20 @@ void gguf_tools_show(const char *filename) {
|
|||||||
gguf_tensor tensor;
|
gguf_tensor tensor;
|
||||||
uint64_t params = 0;
|
uint64_t params = 0;
|
||||||
while (gguf_get_tensor(ctx,&tensor)) {
|
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),
|
gguf_get_tensor_type_name(tensor.type),
|
||||||
(int)tensor.namelen,
|
(int)tensor.namelen,
|
||||||
tensor.name,
|
tensor.name);
|
||||||
tensor.offset,
|
if (!Opt.diffable)
|
||||||
tensor.num_weights);
|
printf(" @%" PRIu64, tensor.offset);
|
||||||
|
printf(", %" PRIu64 " weights, dims ", tensor.num_weights);
|
||||||
for (uint32_t j = 0; j < tensor.ndim; j++) {
|
for (uint32_t j = 0; j < tensor.ndim; j++) {
|
||||||
printf("%s%" PRIu64 "",(j == 0) ? "[" : ",", tensor.dim[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;
|
params += tensor.num_weights;
|
||||||
}
|
}
|
||||||
@@ -507,6 +512,7 @@ void gguf_tools_usage(const char *progname) {
|
|||||||
" split-mixtral <ids...> mixtral.gguf out.gguf -- extract expert.\n"
|
" split-mixtral <ids...> mixtral.gguf out.gguf -- extract expert.\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
" --verbose :With 'show', print full arrays (e.g. token lists)\n"
|
" --verbose :With 'show', print full arrays (e.g. token lists)\n"
|
||||||
|
" --diffable :Don't show tensor file offsets and sizes\n"
|
||||||
"Example:\n"
|
"Example:\n"
|
||||||
" split-mixtral 65230776370407150546470161412165 mixtral.gguf out.gguf\n"
|
" split-mixtral 65230776370407150546470161412165 mixtral.gguf out.gguf\n"
|
||||||
, progname);
|
, progname);
|
||||||
@@ -527,6 +533,11 @@ int main(int argc, char **argv) {
|
|||||||
argc--;
|
argc--;
|
||||||
Opt.verbose = 1;
|
Opt.verbose = 1;
|
||||||
}
|
}
|
||||||
|
if (!strcmp(argv[j],"--diffable")) {
|
||||||
|
argv[j] = NULL;
|
||||||
|
argc--;
|
||||||
|
Opt.diffable = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Strip empty elements. */
|
/* Strip empty elements. */
|
||||||
|
Reference in New Issue
Block a user