gguf : start implementing gguf_file_saver (WIP)

This commit is contained in:
M. Yusuf Sarıgöz 2023-08-11 10:50:02 +03:00
parent e7d346c37c
commit a356b0e228

View File

@ -625,20 +625,25 @@ struct gguf_file_saver {
gguf_file_saver(const char * fname, gguf_file_loader * any_file_loader, enum llama_ftype new_ftype) gguf_file_saver(const char * fname, gguf_file_loader * any_file_loader, enum llama_ftype new_ftype)
: file(fname, "wb"), any_file_loader(any_file_loader) { : file(fname, "wb"), any_file_loader(any_file_loader) {
fprintf(stderr, "llama.cpp: saving model to %s\n", fname); fprintf(stderr, "llama.cpp: saving model to %s\n", fname);
write_magic(); write_header();
write_version();
write_hparams(new_ftype); write_hparams(new_ftype);
write_vocab(); write_vocab();
} }
void write_magic() { // TODO: probably it's better to move these to gguf_file
void write_header() {
const int32_t magic = GGUF_MAGIC; const int32_t magic = GGUF_MAGIC;
file.write_i32(magic); file.write_i32(magic);
}
void write_version() {
const int32_t version = GGUF_VERSION; const int32_t version = GGUF_VERSION;
file.write_i32(version); file.write_i32(version);
const int32_t n_tensors = gguf_get_n_tensors(any_file_loader->gguf_ctx);
file.write_i32(n_tensors);
const int32_t n_kv = gguf_get_n_kv(any_file_loader->gguf_ctx);
file.write_i32(n_kv);
} }
void write_hparams(enum llama_ftype new_ftype) { void write_hparams(enum llama_ftype new_ftype) {