]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
move file magic/version to header, print expected version (#319)
authorMack Straight <redacted>
Mon, 20 Mar 2023 19:26:01 +0000 (12:26 -0700)
committerGitHub <redacted>
Mon, 20 Mar 2023 19:26:01 +0000 (19:26 +0000)
main.cpp
quantize.cpp
utils.h

index 15903337339fb1bf2c59535e56e2318b09639f93..3321818d3e27f5638c6bcec1c84ed5ee4fe0f471 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -106,12 +106,12 @@ bool llama_model_load(const std::string & fname, llama_model & model, gpt_vocab
     {
         uint32_t magic;
         fin.read((char *) &magic, sizeof(magic));
-        if (magic == 0x67676d6c) {
+        if (magic == FILE_MAGIC_UNVERSIONED) {
             fprintf(stderr, "%s: invalid model file '%s' (too old, regenerate your model files!)\n",
                     __func__, fname.c_str());
             return false;
         }
-        if (magic != 0x67676d66) {
+        if (magic != FILE_MAGIC) {
             fprintf(stderr, "%s: invalid model file '%s' (bad magic)\n", __func__, fname.c_str());
             return false;
         }
@@ -119,9 +119,9 @@ bool llama_model_load(const std::string & fname, llama_model & model, gpt_vocab
         uint32_t format_version;
         fin.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.c_str(), format_version);
+        if (format_version != FILE_VERSION) {
+            fprintf(stderr, "%s: invalid model file '%s' (unsupported format version %" PRIu32 ", expected %d)\n",
+                    __func__, fname.c_str(), format_version, FILE_VERSION);
             return false;
         }
     }
index 166e9163adafdbb333056e809f9c1c396d1f1a54..07db33a3caefe0b1baa85a599d688f59930cd1ec 100644 (file)
@@ -64,12 +64,12 @@ 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 == FILE_MAGIC_UNVERSIONED) {
             fprintf(stderr, "%s: invalid model file '%s' (too old, regenerate your model files!)\n",
                     __func__, fname_inp.c_str());
             return false;
         }
-        if (magic != 0x67676d66) {
+        if (magic != FILE_MAGIC) {
             fprintf(stderr, "%s: invalid model file '%s' (bad magic)\n", __func__, fname_inp.c_str());
             return false;
         }
@@ -79,9 +79,9 @@ bool llama_model_quantize(const std::string & fname_inp, const std::string & fna
         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);
+        if (format_version != FILE_VERSION) {
+            fprintf(stderr, "%s: invalid model file '%s' (unsupported format version %" PRIu32 ", expected %d)\n",
+                    __func__, fname_inp.c_str(), format_version, FILE_VERSION);
             return false;
         }
 
diff --git a/utils.h b/utils.h
index b3a0f47246208effc1601bb11d83f208bb1db507..65fe02ba15f73237fd95280eede259a24ef2a333 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -48,6 +48,14 @@ void gpt_print_usage(int argc, char ** argv, const gpt_params & params);
 
 std::string gpt_random_prompt(std::mt19937 & rng);
 
+//
+// Model file parsing
+//
+
+#define FILE_MAGIC_UNVERSIONED 0x67676d6c // pre-versioned files
+#define FILE_MAGIC 0x67676d66 // 'ggmf' in hex
+#define FILE_VERSION 1
+
 //
 // Vocab utils
 //