Skip to content

Commit 4201fa5

Browse files
committed
llama : produce error upon loading old model files
1 parent 0e48eb6 commit 4201fa5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

llama.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ enum llama_file_version {
402402
LLAMA_FILE_VERSION_GGML,
403403
LLAMA_FILE_VERSION_GGMF_V1, // added version field and scores in vocab
404404
LLAMA_FILE_VERSION_GGJT_V1, // added padding
405+
LLAMA_FILE_VERSION_GGJT_V2, // changed quantization format
405406
};
406407

407408
struct llama_file_loader {
@@ -432,6 +433,8 @@ struct llama_file_loader {
432433
file_version = LLAMA_FILE_VERSION_GGMF_V1;
433434
} else if (magic == 'ggjt' && version == 1) {
434435
file_version = LLAMA_FILE_VERSION_GGJT_V1;
436+
} else if (magic == 'ggjt' && version == 2) {
437+
file_version = LLAMA_FILE_VERSION_GGJT_V2;
435438
} else {
436439
throw format("unknown (magic, version) combination: %08x, %08x; is this really a GGML file?",
437440
magic, version);
@@ -837,8 +840,8 @@ static const char *llama_file_version_name(llama_file_version version) {
837840
switch (version) {
838841
case LLAMA_FILE_VERSION_GGML: return "'ggml' (old version with low tokenizer quality and no mmap support)";
839842
case LLAMA_FILE_VERSION_GGMF_V1: return "ggmf v1 (old version with no mmap support)";
840-
case LLAMA_FILE_VERSION_GGJT_V1: return "ggjt v1 (latest)";
841-
default: LLAMA_ASSERT(false);
843+
case LLAMA_FILE_VERSION_GGJT_V1: return "ggjt v1 (pre #1305)";
844+
case LLAMA_FILE_VERSION_GGJT_V2: return "ggjt v2 (latest)";
842845
}
843846
}
844847

@@ -915,6 +918,14 @@ static void llama_model_load_internal(
915918
fprintf(stderr, "%s: model size = %s\n", __func__, llama_model_type_name(model.type));
916919
}
917920

921+
if (file_version != LLAMA_FILE_VERSION_GGJT_V2) {
922+
if (hparams.ftype != LLAMA_FTYPE_ALL_F32 &&
923+
hparams.ftype != LLAMA_FTYPE_MOSTLY_F16 &&
924+
hparams.ftype != LLAMA_FTYPE_MOSTLY_Q8_0) {
925+
throw format("this format is no longer supported (see https://github.com/ggerganov/llama.cpp/pull/1305)");
926+
}
927+
}
928+
918929
if (vocab_only) {
919930
return;
920931
}

llama.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# define LLAMA_API
2020
#endif
2121

22-
#define LLAMA_FILE_VERSION 1
22+
#define LLAMA_FILE_VERSION 2
2323
#define LLAMA_FILE_MAGIC 'ggjt'
2424
#define LLAMA_FILE_MAGIC_UNVERSIONED 'ggml'
2525
#define LLAMA_SESSION_MAGIC 'ggsn'

0 commit comments

Comments
 (0)