mirror of
https://github.com/antirez/gguf-tools.git
synced 2025-12-16 00:18:52 +08:00
gguf-tools: accept subcommands.
This commit is contained in:
35
gguf-tools.c
35
gguf-tools.c
@@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
#include "gguflib.h"
|
#include "gguflib.h"
|
||||||
|
|
||||||
/* ========================== Utility functions ============================ */
|
/* ========================== Utility functions ============================ */
|
||||||
@@ -126,14 +127,10 @@ int strmatch(const char *pattern, int patternLen,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ======================= Main and CLI options parsing ===================== */
|
/* ========================== 'show' subcommand ============================= */
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
void gguf_tools_show(const char *filename) {
|
||||||
if (argc != 2) {
|
gguf_ctx *ctx = gguf_init(filename);
|
||||||
printf("Usage: %s <filename>\n",argv[0]);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
gguf_ctx *ctx = gguf_init(argv[1]);
|
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
perror("Opening GGUF file");
|
perror("Opening GGUF file");
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -141,7 +138,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
/* Show general information about the neural network. */
|
/* Show general information about the neural network. */
|
||||||
printf("%s (ver %d): %llu key-value pairs, %llu tensors\n",
|
printf("%s (ver %d): %llu key-value pairs, %llu tensors\n",
|
||||||
argv[1],
|
filename,
|
||||||
(int)ctx->header->version,
|
(int)ctx->header->version,
|
||||||
(unsigned long long)ctx->header->metadata_kv_count,
|
(unsigned long long)ctx->header->metadata_kv_count,
|
||||||
(unsigned long long)ctx->header->tensor_count);
|
(unsigned long long)ctx->header->tensor_count);
|
||||||
@@ -165,5 +162,27 @@ int main(int argc, char **argv) {
|
|||||||
tensor.num_weights,
|
tensor.num_weights,
|
||||||
tensor.bsize);
|
tensor.bsize);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ======================= Main and CLI options parsing ===================== */
|
||||||
|
|
||||||
|
void gguf_tools_usage(const char *progname) {
|
||||||
|
printf("Usage: %s <subcommand> [options...]\n"
|
||||||
|
"Subcommands:\n"
|
||||||
|
" show <filename> -- show GGUF model keys and tensors.\n"
|
||||||
|
" split-mixtral <id> mixtral.gguf out.gguf -- extract expert.\n"
|
||||||
|
, progname);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
if (argc < 3) gguf_tools_usage(argv[0]);
|
||||||
|
|
||||||
|
if (!strcmp(argv[1],"show") && argc == 3) {
|
||||||
|
gguf_tools_show(argv[2]);
|
||||||
|
} else {
|
||||||
|
gguf_tools_usage(argv[0]);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -332,7 +332,8 @@ void gguf_print_value_callback(void *privdata, uint32_t type, union gguf_value *
|
|||||||
struct gguf_print_options *po = privdata;
|
struct gguf_print_options *po = privdata;
|
||||||
if (po && po->max_array_items && in_array > po->max_array_items) {
|
if (po && po->max_array_items && in_array > po->max_array_items) {
|
||||||
if (in_array-1 == po->max_array_items)
|
if (in_array-1 == po->max_array_items)
|
||||||
printf("... %llu more items", array_len-in_array+1);
|
printf("... %llu more items of %llu", array_len-in_array+1,
|
||||||
|
array_len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user