{
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;
}
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;
}
}
{
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;
}
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;
}
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
//