mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2025-01-06 02:48:57 +01:00
gguf : start implementing quantization (WIP)
This commit is contained in:
parent
186c496fdf
commit
4fa017a1f9
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
23
gguf-util.h
23
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<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)
|
||||
|
Loading…
Reference in New Issue
Block a user