gguf : start implementing quantization (WIP)

This commit is contained in:
M. Yusuf Sarıgöz 2023-08-12 10:40:56 +03:00
parent 186c496fdf
commit 4fa017a1f9
2 changed files with 20 additions and 7 deletions

View File

@ -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);
}

View File

@ -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<typename T>
@ -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)