diff --git a/gguf-llama.cpp b/gguf-llama.cpp index f80f823a0..0581755b1 100644 --- a/gguf-llama.cpp +++ b/gguf-llama.cpp @@ -614,6 +614,7 @@ struct ggml_context * ctx_data = NULL; struct gguf_file_saver { gguf_file file; gguf_file_loader * fl; + size_t info_offset; gguf_file_saver(const char * fname, gguf_file_loader * fl, enum llama_ftype new_ftype) : file(fname, "wb"), fl(fl) { fprintf(stderr, "llama.cpp: saving model to %s\n", fname); @@ -734,6 +735,9 @@ struct gguf_file_saver { } } + info_offset = file.tell(); + size_t count = gguf_get_data_offset(fl->gguf_ctx) - info_offset; + file.write_zeros(count); } diff --git a/gguf-util.h b/gguf-util.h index 9134019a4..0964e6d02 100644 --- a/gguf-util.h +++ b/gguf-util.h @@ -106,18 +106,21 @@ struct gguf_file { } - void write_str(const std::string & val) { + size_t write_str(const std::string & val) { + size_t total_written = 0; const int32_t n = val.size(); - fwrite((const char *) &n, sizeof(n), 1, fp); - fwrite(val.c_str(), n, 1, fp); + total_written += fwrite((const char *) &n, sizeof(n), 1, fp); + total_written += fwrite(val.c_str(), n, 1, fp); + + return total_written; } - void write_i32(int32_t val) { - fwrite((const char *) &val, sizeof(val), 1, fp); + size_t write_i32(int32_t val) { + return fwrite((const char *) &val, sizeof(val), 1, fp); } - void write_u64(size_t val) { - fwrite((const char *) &val, sizeof(val), 1, fp); + size_t write_u64(size_t val) { + return fwrite((const char *) &val, sizeof(val), 1, fp); } template @@ -167,6 +170,12 @@ struct gguf_file { fwrite(val[i].c_str(), nstr, 1, fp); } } + + void write_zeros(size_t count) { + for (size_t i = 0; i < count; ++i) { + fputc(0, fp); + } + } }; #if defined(_WIN32)