Skip to content

Commit db4b172

Browse files
committed
move file magic/version to header, print expected version
1 parent 074bea2 commit db4b172

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ bool llama_model_load(const std::string & fname, llama_model & model, gpt_vocab
120120
fin.read((char *) &format_version, sizeof(format_version));
121121

122122
if (format_version != 1) {
123-
fprintf(stderr, "%s: invalid model file '%s' (unsupported format version %" PRIu32 ")\n",
124-
__func__, fname.c_str(), format_version);
123+
fprintf(stderr, "%s: invalid model file '%s' (unsupported format version %" PRIu32 ", expected %d)\n",
124+
__func__, fname.c_str(), format_version, FILE_VERSION);
125125
return false;
126126
}
127127
}

quantize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ bool llama_model_quantize(const std::string & fname_inp, const std::string & fna
7979
uint32_t format_version;
8080
finp.read((char *) &format_version, sizeof(format_version));
8181

82-
if (format_version != 1) {
83-
fprintf(stderr, "%s: invalid model file '%s' (unsupported format version %" PRIu32 ")\n",
84-
__func__, fname_inp.c_str(), format_version);
82+
if (format_version != FILE_VERSION) {
83+
fprintf(stderr, "%s: invalid model file '%s' (unsupported format version %" PRIu32 ", expected %d)\n",
84+
__func__, fname_inp.c_str(), format_version, FILE_VERSION);
8585
return false;
8686
}
8787

utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ void gpt_print_usage(int argc, char ** argv, const gpt_params & params);
4848

4949
std::string gpt_random_prompt(std::mt19937 & rng);
5050

51+
//
52+
// Model file parsing
53+
//
54+
55+
#define FILE_MAGIC_UNVERSIONED 0x67676d6c // pre-versioned files
56+
#define FILE_MAGIC 0x67676d66 // 'ggmf' in hex
57+
#define FILE_VERSION 1
58+
5159
//
5260
// Vocab utils
5361
//

0 commit comments

Comments
 (0)