From 4201fa5cb854118b4f172a758e4bcd421866f3bf Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Tue, 9 May 2023 18:19:13 +0300 Subject: [PATCH] llama : produce error upon loading old model files --- llama.cpp | 15 +++++++++++++-- llama.h | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/llama.cpp b/llama.cpp index 367522ac9..334d4e1bc 100644 --- a/llama.cpp +++ b/llama.cpp @@ -402,6 +402,7 @@ enum llama_file_version { LLAMA_FILE_VERSION_GGML, LLAMA_FILE_VERSION_GGMF_V1, // added version field and scores in vocab LLAMA_FILE_VERSION_GGJT_V1, // added padding + LLAMA_FILE_VERSION_GGJT_V2, // changed quantization format }; struct llama_file_loader { @@ -432,6 +433,8 @@ struct llama_file_loader { file_version = LLAMA_FILE_VERSION_GGMF_V1; } else if (magic == 'ggjt' && version == 1) { file_version = LLAMA_FILE_VERSION_GGJT_V1; + } else if (magic == 'ggjt' && version == 2) { + file_version = LLAMA_FILE_VERSION_GGJT_V2; } else { throw format("unknown (magic, version) combination: %08x, %08x; is this really a GGML file?", magic, version); @@ -837,8 +840,8 @@ static const char *llama_file_version_name(llama_file_version version) { switch (version) { case LLAMA_FILE_VERSION_GGML: return "'ggml' (old version with low tokenizer quality and no mmap support)"; case LLAMA_FILE_VERSION_GGMF_V1: return "ggmf v1 (old version with no mmap support)"; - case LLAMA_FILE_VERSION_GGJT_V1: return "ggjt v1 (latest)"; - default: LLAMA_ASSERT(false); + case LLAMA_FILE_VERSION_GGJT_V1: return "ggjt v1 (pre #1305)"; + case LLAMA_FILE_VERSION_GGJT_V2: return "ggjt v2 (latest)"; } } @@ -915,6 +918,14 @@ static void llama_model_load_internal( fprintf(stderr, "%s: model size = %s\n", __func__, llama_model_type_name(model.type)); } + if (file_version != LLAMA_FILE_VERSION_GGJT_V2) { + if (hparams.ftype != LLAMA_FTYPE_ALL_F32 && + hparams.ftype != LLAMA_FTYPE_MOSTLY_F16 && + hparams.ftype != LLAMA_FTYPE_MOSTLY_Q8_0) { + throw format("this format is no longer supported (see https://github.com/ggerganov/llama.cpp/pull/1305)"); + } + } + if (vocab_only) { return; } diff --git a/llama.h b/llama.h index fea5ffeff..1a65cd589 100644 --- a/llama.h +++ b/llama.h @@ -19,7 +19,7 @@ # define LLAMA_API #endif -#define LLAMA_FILE_VERSION 1 +#define LLAMA_FILE_VERSION 2 #define LLAMA_FILE_MAGIC 'ggjt' #define LLAMA_FILE_MAGIC_UNVERSIONED 'ggml' #define LLAMA_SESSION_MAGIC 'ggsn'