mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2025-01-06 02:48:57 +01:00
gguf : write metadata in gguf_file_saver (WIP)
This commit is contained in:
parent
28abfc90fa
commit
781b9ec3f5
@ -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<int32_t>(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<int8_t>(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<std::string>(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<uint16_t>(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<uint32_t>(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<uint8_t>(key, GGUF_TYPE_UINT8, u8_val);
|
||||
break;
|
||||
case GGUF_TYPE_ARRAY:
|
||||
break;
|
||||
default:
|
||||
|
27
gguf-util.h
27
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<std::string>(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<std::string>(const std::string & key, enum gguf_type type, const std::vector<std::string> & 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)
|
||||
|
Loading…
Reference in New Issue
Block a user