Skip to content

Commit 95a492a

Browse files
committed
feat: add new GGUFValueType.OBJ virtual type
The content of the OBJ type is actually a list of all key names of the object. * Python * `gguf_writer.py`: * Added `def add_kv(self, key: str, val: Any) -> None`: Automatically determines the appropriate value type based on `val`. * Added `def add_dict(self, key: str, val: dict, excludes: Sequence[str] = []) -> None`: Adds object (dict) values, It will recursively add all subkeys. * Added `add_array_ex` to support the nested and mixed-type array. * `constants.py`: * Added `GGUFValueType.get_type_ex(val)`: Added support for numpy's integers and floating-point numbers, selecting the number of digits according to the size of the integer. * `gguf_reader.py`: * Added functionality to retrieve values from specific fields using `ReaderField.get()` method. * Unit test added * CPP * `ggml`: * Added `GGUF_TYPE_OBJ` to the `gguf_type` enum type. * Use `gguf_get_arr_n` and `gguf_get_arr_str` to get the subKey names of `GGUF_TYPE_OBJ`. * Added `gguf_set_obj_str` function to set object subkey names * Added `gguf_set_arr_obj` function to set object array count * Added `gguf_set_arr_arr` function to set nested array count * `llama`: * Modified `gguf_kv_to_str` * Added `LLAMA_API char * gguf_kv_to_c_str` function to get the c_str value as JSON format. * Maybe this API should be moved into `ggml` as `gguf_get_val_json`. (问题是 ggml.c 用的是C语言,而这里大量用了C++的功能) * Added basic support to `GGUF_TYPE_OBJ` and nested array * Unit test added feat: add basic support to GGUF_TYPE_OBJ on cpp feat(gguf.py): add OBJ and mixed-type array supports to GGUF ARRAY feat: add OBJ and mixed-type array supports to GGUF ARRAY(CPP) feat: add nested array supported feat: * Subkey name convention in OBJ types: * If the first letter of the subkey name is "/", it means referencing the full name of other keys. * If there is a ":" colon delimiter, it means that the string after the colon represents the subkey name in this object, otherwise the referencing subkey name is used. feat: add LLAMA_API gguf_kv_to_c_str to llama.h test: write test gguf file to tests folder directly(py) test: add test-gguf-meta.cpp feat: Key convention: "." indicates that the key is a subkey, not an independent key. feat: add excludes argument to add_dict(gguf_write.py) feat: add_array_ex to supports nested and mix-typed array, and keep the add_array to the same fix(constant.py): rollback the get_type function and add the new get_type_ex test: add test compatibility fix: use GGML_MALLOC instead of malloc
1 parent 906cff5 commit 95a492a

14 files changed

+576
-89
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,3 +854,6 @@ tests/test-model-load-cancel: tests/test-model-load-cancel.cpp ggml.o llama.o te
854854
tests/test-autorelease: tests/test-autorelease.cpp ggml.o llama.o tests/get-model.cpp $(COMMON_DEPS) $(OBJS)
855855
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
856856
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
857+
858+
tests/test-gguf-meta: tests/test-gguf-meta.cpp ggml.o llama.o tests/get-model.cpp $(COMMON_DEPS) $(OBJS)
859+
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)

examples/llava/clip.cpp

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "ggml.h"
77
#include "ggml-alloc.h"
88
#include "ggml-backend.h"
9+
#include "llama.h"
910

1011
#ifdef GGML_USE_CUBLAS
1112
#include "ggml-cuda.h"
@@ -148,24 +149,6 @@ static std::string get_ftype(int ftype) {
148149
return ggml_type_name(static_cast<ggml_type>(ftype));
149150
}
150151

151-
static std::string gguf_data_to_str(enum gguf_type type, const void * data, int i) {
152-
switch (type) {
153-
case GGUF_TYPE_UINT8: return std::to_string(((const uint8_t *)data)[i]);
154-
case GGUF_TYPE_INT8: return std::to_string(((const int8_t *)data)[i]);
155-
case GGUF_TYPE_UINT16: return std::to_string(((const uint16_t *)data)[i]);
156-
case GGUF_TYPE_INT16: return std::to_string(((const int16_t *)data)[i]);
157-
case GGUF_TYPE_UINT32: return std::to_string(((const uint32_t *)data)[i]);
158-
case GGUF_TYPE_INT32: return std::to_string(((const int32_t *)data)[i]);
159-
case GGUF_TYPE_UINT64: return std::to_string(((const uint64_t *)data)[i]);
160-
case GGUF_TYPE_INT64: return std::to_string(((const int64_t *)data)[i]);
161-
case GGUF_TYPE_FLOAT32: return std::to_string(((const float *)data)[i]);
162-
case GGUF_TYPE_FLOAT64: return std::to_string(((const double *)data)[i]);
163-
case GGUF_TYPE_BOOL: return ((const bool *)data)[i] ? "true" : "false";
164-
default: return format("unknown type %d", type);
165-
}
166-
}
167-
168-
169152
static void replace_all(std::string & s, const std::string & search, const std::string & replace) {
170153
std::string result;
171154
for (size_t pos = 0; ; pos += search.length()) {
@@ -180,43 +163,6 @@ static void replace_all(std::string & s, const std::string & search, const std::
180163
s = std::move(result);
181164
}
182165

183-
static std::string gguf_kv_to_str(const struct gguf_context * ctx_gguf, int i) {
184-
const enum gguf_type type = gguf_get_kv_type(ctx_gguf, i);
185-
186-
switch (type) {
187-
case GGUF_TYPE_STRING:
188-
return gguf_get_val_str(ctx_gguf, i);
189-
case GGUF_TYPE_ARRAY:
190-
{
191-
const enum gguf_type arr_type = gguf_get_arr_type(ctx_gguf, i);
192-
int arr_n = gguf_get_arr_n(ctx_gguf, i);
193-
const void * data = gguf_get_arr_data(ctx_gguf, i);
194-
std::stringstream ss;
195-
ss << "[";
196-
for (int j = 0; j < arr_n; j++) {
197-
if (arr_type == GGUF_TYPE_STRING) {
198-
std::string val = gguf_get_arr_str(ctx_gguf, i, j);
199-
// escape quotes
200-
replace_all(val, "\\", "\\\\");
201-
replace_all(val, "\"", "\\\"");
202-
ss << '"' << val << '"';
203-
} else if (arr_type == GGUF_TYPE_ARRAY) {
204-
ss << "???";
205-
} else {
206-
ss << gguf_data_to_str(arr_type, data, j);
207-
}
208-
if (j < arr_n - 1) {
209-
ss << ", ";
210-
}
211-
}
212-
ss << "]";
213-
return ss.str();
214-
}
215-
default:
216-
return gguf_data_to_str(type, gguf_get_val_data(ctx_gguf, i), 0);
217-
}
218-
}
219-
220166
static void print_tensor_info(const ggml_tensor* tensor, const char* prefix = "") {
221167
size_t tensor_size = ggml_nbytes(tensor);
222168
printf("%s: n_dims = %d, name = %s, tensor_size=%zu, shape:[%" PRId64 ", %" PRId64 ", %" PRId64 ", %" PRId64 "], type = %s\n",
@@ -784,11 +730,12 @@ struct clip_ctx * clip_model_load(const char * fname, const int verbosity = 1) {
784730
const char * name = gguf_get_key(ctx, i);
785731
const enum gguf_type type = gguf_get_kv_type(ctx, i);
786732
const std::string type_name =
787-
type == GGUF_TYPE_ARRAY
733+
type == GGUF_TYPE_ARRAY || type == GGUF_TYPE_OBJ
788734
? format("%s[%s,%d]", gguf_type_name(type), gguf_type_name(gguf_get_arr_type(ctx, i)), gguf_get_arr_n(ctx, i))
789735
: gguf_type_name(type);
790736

791-
std::string value = gguf_kv_to_str(ctx, i);
737+
char * v = gguf_kv_to_c_str(ctx, i, name);
738+
std::string value = v;
792739
const size_t MAX_VALUE_LEN = 40;
793740
if (value.size() > MAX_VALUE_LEN) {
794741
value = format("%s...", value.substr(0, MAX_VALUE_LEN - 3).c_str());

ggml.c

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19284,8 +19284,9 @@ static const size_t GGUF_TYPE_SIZE[GGUF_TYPE_COUNT] = {
1928419284
[GGUF_TYPE_INT64] = sizeof(int64_t),
1928519285
[GGUF_TYPE_FLOAT64] = sizeof(double),
1928619286
[GGUF_TYPE_ARRAY] = 0, // undefined
19287+
[GGUF_TYPE_OBJ] = 0, // undefined
1928719288
};
19288-
static_assert(GGUF_TYPE_COUNT == 13, "GGUF_TYPE_COUNT != 13");
19289+
static_assert(GGUF_TYPE_COUNT == 14, "GGUF_TYPE_COUNT != 14");
1928919290

1929019291
static const char * GGUF_TYPE_NAME[GGUF_TYPE_COUNT] = {
1929119292
[GGUF_TYPE_UINT8] = "u8",
@@ -19301,8 +19302,9 @@ static const char * GGUF_TYPE_NAME[GGUF_TYPE_COUNT] = {
1930119302
[GGUF_TYPE_UINT64] = "u64",
1930219303
[GGUF_TYPE_INT64] = "i64",
1930319304
[GGUF_TYPE_FLOAT64] = "f64",
19305+
[GGUF_TYPE_OBJ] = "obj",
1930419306
};
19305-
static_assert(GGUF_TYPE_COUNT == 13, "GGUF_TYPE_COUNT != 13");
19307+
static_assert(GGUF_TYPE_COUNT == 14, "GGUF_TYPE_COUNT != 14");
1930619308

1930719309
union gguf_value {
1930819310
uint8_t uint8;
@@ -19525,6 +19527,7 @@ struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_p
1952519527
case GGUF_TYPE_FLOAT64: ok = ok && gguf_fread_el (file, &kv->value.float64, sizeof(kv->value.float64), &offset); break;
1952619528
case GGUF_TYPE_BOOL: ok = ok && gguf_fread_el (file, &kv->value.bool_, sizeof(kv->value.bool_), &offset); break;
1952719529
case GGUF_TYPE_STRING: ok = ok && gguf_fread_str(file, &kv->value.str, &offset); break;
19530+
case GGUF_TYPE_OBJ:
1952819531
case GGUF_TYPE_ARRAY:
1952919532
{
1953019533
ok = ok && gguf_fread_el(file, &kv->value.arr.type, sizeof(kv->value.arr.type), &offset);
@@ -19571,7 +19574,8 @@ struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_p
1957119574
ok = ok && gguf_fread_str(file, &((struct gguf_str *) kv->value.arr.data)[j], &offset);
1957219575
}
1957319576
} break;
19574-
case GGUF_TYPE_ARRAY:
19577+
case GGUF_TYPE_OBJ:
19578+
case GGUF_TYPE_ARRAY: break;
1957519579
default: GGML_ASSERT(false && "invalid type"); break;
1957619580
}
1957719581
} break;
@@ -19778,7 +19782,7 @@ void gguf_free(struct gguf_context * ctx) {
1977819782
}
1977919783
}
1978019784

19781-
if (kv->type == GGUF_TYPE_ARRAY) {
19785+
if (kv->type == GGUF_TYPE_ARRAY || kv->type == GGUF_TYPE_OBJ) {
1978219786
if (kv->value.arr.data) {
1978319787
if (kv->value.arr.type == GGUF_TYPE_STRING) {
1978419788
for (uint64_t j = 0; j < kv->value.arr.n; ++j) {
@@ -19863,7 +19867,7 @@ enum gguf_type gguf_get_kv_type(const struct gguf_context * ctx, int key_id) {
1986319867

1986419868
enum gguf_type gguf_get_arr_type(const struct gguf_context * ctx, int key_id) {
1986519869
GGML_ASSERT(key_id >= 0 && key_id < gguf_get_n_kv(ctx));
19866-
GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_ARRAY);
19870+
GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_ARRAY || ctx->kv[key_id].type == GGUF_TYPE_OBJ);
1986719871
return ctx->kv[key_id].value.arr.type;
1986819872
}
1986919873

@@ -19875,15 +19879,15 @@ const void * gguf_get_arr_data(const struct gguf_context * ctx, int key_id) {
1987519879

1987619880
const char * gguf_get_arr_str(const struct gguf_context * ctx, int key_id, int i) {
1987719881
GGML_ASSERT(key_id >= 0 && key_id < gguf_get_n_kv(ctx));
19878-
GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_ARRAY);
19882+
GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_ARRAY || ctx->kv[key_id].type == GGUF_TYPE_OBJ);
1987919883
struct gguf_kv * kv = &ctx->kv[key_id];
1988019884
struct gguf_str * str = &((struct gguf_str *) kv->value.arr.data)[i];
1988119885
return str->data;
1988219886
}
1988319887

1988419888
int gguf_get_arr_n(const struct gguf_context * ctx, int key_id) {
1988519889
GGML_ASSERT(key_id >= 0 && key_id < gguf_get_n_kv(ctx));
19886-
GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_ARRAY);
19890+
GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_ARRAY || ctx->kv[key_id].type == GGUF_TYPE_OBJ);
1988719891
return ctx->kv[key_id].value.arr.n;
1988819892
}
1988919893

@@ -19962,6 +19966,7 @@ const char * gguf_get_val_str(const struct gguf_context * ctx, int key_id) {
1996219966
const void * gguf_get_val_data(const struct gguf_context * ctx, int key_id) {
1996319967
GGML_ASSERT(key_id >= 0 && key_id < gguf_get_n_kv(ctx));
1996419968
GGML_ASSERT(ctx->kv[key_id].type != GGUF_TYPE_ARRAY);
19969+
GGML_ASSERT(ctx->kv[key_id].type != GGUF_TYPE_OBJ);
1996519970
GGML_ASSERT(ctx->kv[key_id].type != GGUF_TYPE_STRING);
1996619971
return &ctx->kv[key_id].value;
1996719972
}
@@ -20106,6 +20111,10 @@ void gguf_set_arr_data(struct gguf_context * ctx, const char * key, enum gguf_ty
2010620111
ctx->kv[idx].type = GGUF_TYPE_ARRAY;
2010720112
ctx->kv[idx].value.arr.type = type;
2010820113
ctx->kv[idx].value.arr.n = n;
20114+
if (data == NULL) {
20115+
ctx->kv[idx].value.arr.data = NULL;
20116+
return;
20117+
}
2010920118
ctx->kv[idx].value.arr.data = GGML_MALLOC(n*gguf_type_size(type));
2011020119
memcpy(ctx->kv[idx].value.arr.data, data, n*gguf_type_size(type));
2011120120
}
@@ -20124,6 +20133,38 @@ void gguf_set_arr_str(struct gguf_context * ctx, const char * key, const char **
2012420133
}
2012520134
}
2012620135

20136+
void gguf_set_arr_obj(struct gguf_context * ctx, const char * key, int n) {
20137+
const int idx = gguf_get_or_add_key(ctx, key);
20138+
20139+
ctx->kv[idx].type = GGUF_TYPE_ARRAY;
20140+
ctx->kv[idx].value.arr.type = GGUF_TYPE_OBJ;
20141+
ctx->kv[idx].value.arr.n = n;
20142+
ctx->kv[idx].value.arr.data = NULL;
20143+
}
20144+
20145+
void gguf_set_arr_arr(struct gguf_context * ctx, const char * key, int n) {
20146+
const int idx = gguf_get_or_add_key(ctx, key);
20147+
20148+
ctx->kv[idx].type = GGUF_TYPE_ARRAY;
20149+
ctx->kv[idx].value.arr.type = GGUF_TYPE_ARRAY;
20150+
ctx->kv[idx].value.arr.n = n;
20151+
ctx->kv[idx].value.arr.data = NULL;
20152+
}
20153+
20154+
void gguf_set_obj_str(struct gguf_context * ctx, const char * key, const char ** data, int n) {
20155+
const int idx = gguf_get_or_add_key(ctx, key);
20156+
20157+
ctx->kv[idx].type = GGUF_TYPE_OBJ;
20158+
ctx->kv[idx].value.arr.type = GGUF_TYPE_STRING;
20159+
ctx->kv[idx].value.arr.n = n;
20160+
ctx->kv[idx].value.arr.data = GGML_MALLOC(n*sizeof(struct gguf_str));
20161+
for (int i = 0; i < n; i++) {
20162+
struct gguf_str * str = &((struct gguf_str *)ctx->kv[idx].value.arr.data)[i];
20163+
str->n = strlen(data[i]);
20164+
str->data = strdup(data[i]);
20165+
}
20166+
}
20167+
2012720168
// set or add KV pairs from another context
2012820169
void gguf_set_kv(struct gguf_context * ctx, struct gguf_context * src) {
2012920170
for (uint32_t i = 0; i < src->header.n_kv; i++) {
@@ -20140,6 +20181,15 @@ void gguf_set_kv(struct gguf_context * ctx, struct gguf_context * src) {
2014020181
case GGUF_TYPE_FLOAT64: gguf_set_val_f64 (ctx, src->kv[i].key.data, src->kv[i].value.float64); break;
2014120182
case GGUF_TYPE_BOOL: gguf_set_val_bool(ctx, src->kv[i].key.data, src->kv[i].value.bool_); break;
2014220183
case GGUF_TYPE_STRING: gguf_set_val_str (ctx, src->kv[i].key.data, src->kv[i].value.str.data); break;
20184+
case GGUF_TYPE_OBJ:
20185+
{
20186+
const char ** data = malloc(src->kv[i].value.arr.n*sizeof(char *));
20187+
for (uint32_t j = 0; j < src->kv[i].value.arr.n; j++) {
20188+
data[j] = ((struct gguf_str *)src->kv[i].value.arr.data)[j].data;
20189+
}
20190+
gguf_set_obj_str(ctx, src->kv[i].key.data, data, src->kv[i].value.arr.n);
20191+
free((void *)data);
20192+
} break;
2014320193
case GGUF_TYPE_ARRAY:
2014420194
{
2014520195
if (src->kv[i].value.arr.type == GGUF_TYPE_STRING) {
@@ -20149,8 +20199,6 @@ void gguf_set_kv(struct gguf_context * ctx, struct gguf_context * src) {
2014920199
}
2015020200
gguf_set_arr_str(ctx, src->kv[i].key.data, data, src->kv[i].value.arr.n);
2015120201
GGML_FREE((void *)data);
20152-
} else if (src->kv[i].value.arr.type == GGUF_TYPE_ARRAY) {
20153-
GGML_ASSERT(false && "nested arrays not supported");
2015420202
} else {
2015520203
gguf_set_arr_data(ctx, src->kv[i].key.data, src->kv[i].value.arr.type, src->kv[i].value.arr.data, src->kv[i].value.arr.n);
2015620204
}
@@ -20304,6 +20352,7 @@ static void gguf_write_to_buf(const struct gguf_context * ctx, struct gguf_buf *
2030420352
case GGUF_TYPE_FLOAT64: gguf_bwrite_el (buf, &kv->value.float64, sizeof(kv->value.float64)); break;
2030520353
case GGUF_TYPE_BOOL: gguf_bwrite_el (buf, &kv->value.bool_, sizeof(kv->value.bool_) ); break;
2030620354
case GGUF_TYPE_STRING: gguf_bwrite_str(buf, &kv->value.str ); break;
20355+
case GGUF_TYPE_OBJ:
2030720356
case GGUF_TYPE_ARRAY:
2030820357
{
2030920358
gguf_bwrite_el(buf, &kv->value.arr.type, sizeof(kv->value.arr.type));
@@ -20330,7 +20379,8 @@ static void gguf_write_to_buf(const struct gguf_context * ctx, struct gguf_buf *
2033020379
gguf_bwrite_str(buf, &((struct gguf_str *) kv->value.arr.data)[j]);
2033120380
}
2033220381
} break;
20333-
case GGUF_TYPE_ARRAY:
20382+
case GGUF_TYPE_OBJ:
20383+
case GGUF_TYPE_ARRAY: break;
2033420384
default: GGML_ASSERT(false && "invalid type"); break;
2033520385
}
2033620386
} break;

ggml.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,7 @@ extern "C" {
21412141
GGUF_TYPE_UINT64 = 10,
21422142
GGUF_TYPE_INT64 = 11,
21432143
GGUF_TYPE_FLOAT64 = 12,
2144+
GGUF_TYPE_OBJ = 13,
21442145
GGUF_TYPE_COUNT, // marks the end of the enum
21452146
};
21462147

@@ -2212,6 +2213,9 @@ extern "C" {
22122213
GGML_API void gguf_set_val_str (struct gguf_context * ctx, const char * key, const char * val);
22132214
GGML_API void gguf_set_arr_data(struct gguf_context * ctx, const char * key, enum gguf_type type, const void * data, int n);
22142215
GGML_API void gguf_set_arr_str (struct gguf_context * ctx, const char * key, const char ** data, int n);
2216+
GGML_API void gguf_set_arr_obj (struct gguf_context * ctx, const char * key, int n);
2217+
GGML_API void gguf_set_arr_arr (struct gguf_context * ctx, const char * key, int n);
2218+
GGML_API void gguf_set_obj_str (struct gguf_context * ctx, const char * key, const char ** data, int n);
22152219

22162220
// set or add KV pairs from another context
22172221
GGML_API void gguf_set_kv(struct gguf_context * ctx, struct gguf_context * src);

gguf-py/gguf/constants.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
from enum import Enum, IntEnum, auto
55
from typing import Any
6+
import numpy as np
67

78
#
89
# constants
@@ -550,6 +551,64 @@ class GGUFValueType(IntEnum):
550551
UINT64 = 10
551552
INT64 = 11
552553
FLOAT64 = 12
554+
OBJ = 13
555+
556+
@staticmethod
557+
def get_type_ex(val: Any) -> GGUFValueType:
558+
if isinstance(val, (str, bytes, bytearray)):
559+
return GGUFValueType.STRING
560+
elif isinstance(val, list):
561+
return GGUFValueType.ARRAY
562+
elif isinstance(val, np.float32):
563+
return GGUFValueType.FLOAT32
564+
elif isinstance(val, np.float64):
565+
return GGUFValueType.FLOAT64
566+
elif isinstance(val, float):
567+
return GGUFValueType.FLOAT32
568+
elif isinstance(val, bool):
569+
return GGUFValueType.BOOL
570+
elif isinstance(val, np.uint8):
571+
return GGUFValueType.UINT8
572+
elif isinstance(val, np.uint16):
573+
return GGUFValueType.UINT16
574+
elif isinstance(val, np.uint32):
575+
return GGUFValueType.UINT32
576+
elif isinstance(val, np.uint64):
577+
return GGUFValueType.UINT64
578+
elif isinstance(val, np.int8):
579+
return GGUFValueType.INT8
580+
elif isinstance(val, np.int16):
581+
return GGUFValueType.INT16
582+
elif isinstance(val, np.int32):
583+
return GGUFValueType.INT32
584+
elif isinstance(val, np.int64):
585+
return GGUFValueType.INT64
586+
elif isinstance(val, int):
587+
if val >=0 and val <= np.iinfo(np.uint8).max:
588+
return GGUFValueType.UINT8
589+
elif val >=0 and val <= np.iinfo(np.uint16).max:
590+
return GGUFValueType.UINT16
591+
elif val >=0 and val <= np.iinfo(np.uint32).max:
592+
return GGUFValueType.UINT32
593+
elif val >=0 and val <= np.iinfo(np.uint64).max:
594+
return GGUFValueType.UINT64
595+
elif val >=np.iinfo(np.int8).min and val <= np.iinfo(np.int8).max:
596+
return GGUFValueType.INT8
597+
elif val >=np.iinfo(np.int16).min and val <= np.iinfo(np.int16).max:
598+
return GGUFValueType.INT16
599+
elif val >=np.iinfo(np.int32).min and val <= np.iinfo(np.int32).max:
600+
return GGUFValueType.INT32
601+
elif val >=np.iinfo(np.int64).min and val <= np.iinfo(np.int64).max:
602+
return GGUFValueType.INT64
603+
else:
604+
print("The integer exceed limit:", val)
605+
sys.exit()
606+
elif isinstance(val, dict):
607+
return GGUFValueType.OBJ
608+
# TODO: need help with 64-bit types in Python
609+
else:
610+
print("Unknown type:", type(val))
611+
sys.exit()
553612

554613
@staticmethod
555614
def get_type(val: Any) -> GGUFValueType:

0 commit comments

Comments
 (0)