aboutsummaryrefslogtreecommitdiff
path: root/quantize.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'quantize.cpp')
-rw-r--r--quantize.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/quantize.cpp b/quantize.cpp
index 14c7b27..166e916 100644
--- a/quantize.cpp
+++ b/quantize.cpp
@@ -3,6 +3,7 @@
#include "utils.h"
#include <cassert>
+#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
@@ -63,12 +64,28 @@ bool llama_model_quantize(const std::string & fname_inp, const std::string & fna
{
uint32_t magic;
finp.read((char *) &magic, sizeof(magic));
- if (magic != 0x67676d6c) {
+ if (magic == 0x67676d6c) {
+ fprintf(stderr, "%s: invalid model file '%s' (too old, regenerate your model files!)\n",
+ __func__, fname_inp.c_str());
+ return false;
+ }
+ if (magic != 0x67676d66) {
fprintf(stderr, "%s: invalid model file '%s' (bad magic)\n", __func__, fname_inp.c_str());
return false;
}
fout.write((char *) &magic, sizeof(magic));
+
+ uint32_t format_version;
+ finp.read((char *) &format_version, sizeof(format_version));
+
+ if (format_version != 1) {
+ fprintf(stderr, "%s: invalid model file '%s' (unsupported format version %" PRIu32 ")\n",
+ __func__, fname_inp.c_str(), format_version);
+ return false;
+ }
+
+ fout.write((char *) &format_version, sizeof(format_version));
}
llama_hparams hparams;
@@ -122,8 +139,13 @@ bool llama_model_quantize(const std::string & fname_inp, const std::string & fna
finp.read ((char *) word.data(), len);
fout.write((char *) word.data(), len);
+ float score;
+ finp.read ((char *) &score, sizeof(score));
+ fout.write((char *) &score, sizeof(score));
+
vocab.token_to_id[word] = i;
vocab.id_to_token[i] = word;
+ vocab.score[i] = score;
}
}