diff --git a/gguf-llama.cpp b/gguf-llama.cpp index 11dcb1cc5..e70cae44c 100644 --- a/gguf-llama.cpp +++ b/gguf-llama.cpp @@ -660,6 +660,12 @@ struct gguf_file_saver { float f32_val; int16_t i16_val; int32_t i32_val; + int8_t i8_val; + std::string str_val; + uint16_t u16_val; + uint32_t u32_val; + uint8_t u8_val; + switch(vtype) { case GGUF_TYPE_BOOL: @@ -679,10 +685,25 @@ struct gguf_file_saver { file.write_val(key, GGUF_TYPE_INT32, i32_val); break; case GGUF_TYPE_INT8: + i8_val = gguf_get_val_i8(any_file_loader->gguf_ctx, i); + file.write_val(key, GGUF_TYPE_INT8, i8_val); + break; case GGUF_TYPE_STRING: + str_val = gguf_get_val_str(any_file_loader->gguf_ctx, i); + file.write_val(key, GGUF_TYPE_STRING, str_val); + break; case GGUF_TYPE_UINT16: + u16_val = gguf_get_val_u16(any_file_loader->gguf_ctx, i); + file.write_val(key, GGUF_TYPE_UINT16, u16_val); + break; case GGUF_TYPE_UINT32: + u32_val = gguf_get_val_u32(any_file_loader->gguf_ctx, i); + file.write_val(key, GGUF_TYPE_UINT32, u32_val); + break; case GGUF_TYPE_UINT8: + u8_val = gguf_get_val_u8(any_file_loader->gguf_ctx, i); + file.write_val(key, GGUF_TYPE_UINT8, u8_val); + break; case GGUF_TYPE_ARRAY: break; default: diff --git a/gguf-util.h b/gguf-util.h index 94ea9006a..9134019a4 100644 --- a/gguf-util.h +++ b/gguf-util.h @@ -140,6 +140,33 @@ struct gguf_file { fwrite((const char *) &n, sizeof(n), 1, fp); fwrite(val.data(), sizeof(T), n, fp); } + template<> + void write_val(const std::string & key, enum gguf_type type, const std::string & val) { + write_str(key); + fwrite((const char *) &type, sizeof(type), 1, fp); + + const int32_t n = val.size(); + fwrite((const char *) &n, sizeof(n), 1, fp); + fwrite(val.c_str(), n, 1, fp); + } + + template<> + void write_arr(const std::string & key, enum gguf_type type, const std::vector & val) { + write_str(key); + { + const enum gguf_type tarr = GGUF_TYPE_ARRAY; + fwrite((const char *) &tarr, sizeof(tarr), 1, fp); + } + + const int32_t n = val.size(); + fwrite((const char *) &type, sizeof(type), 1, fp); + fwrite((const char *) &n, sizeof(n), 1, fp); + for (int i = 0; i < n; ++i) { + const int32_t nstr = val[i].size(); + fwrite((const char *) &nstr, sizeof(nstr), 1, fp); + fwrite(val[i].c_str(), nstr, 1, fp); + } + } }; #if defined(_WIN32)