diff --git a/expose.cpp b/expose.cpp index 7824b8d2c..64928f218 100644 --- a/expose.cpp +++ b/expose.cpp @@ -35,6 +35,11 @@ extern "C" draftmodel_filename = inputs.draftmodel_filename; file_format = check_file_format(model.c_str(),&file_format_meta); + if (file_format == FileFormat::BADFORMAT) + { + fprintf(stderr, "%s: error: invalid or unsupported model file '%s'\n", __func__, model.c_str()); + return false; + } executable_path = inputs.executable_path; diff --git a/gpttype_adapter.cpp b/gpttype_adapter.cpp index a59e28d06..b3539d1f9 100644 --- a/gpttype_adapter.cpp +++ b/gpttype_adapter.cpp @@ -3564,6 +3564,11 @@ ModelLoadResult gpttype_load_model(const load_model_inputs inputs, FileFormat in } llama_model * llamamodel = llama_model_load_from_file(kcpp_data->model_filename.c_str(), model_params); + if (llamamodel == nullptr) + { + fprintf(stderr, "%s: error: failed to load model '%s'\n", __func__, kcpp_data->model_filename.c_str()); + return ModelLoadResult::FAIL; + } //now that the model is loaded, immediately check if SWA is used bool model_has_swa = (llama_model_n_swa(llamamodel)!=0); diff --git a/koboldcpp.py b/koboldcpp.py index a7e768573..2e79bb7c2 100644 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -12360,6 +12360,10 @@ def kcpp_main_process(launch_args, g_memory=None, gui_launcher=False): print("WARNING: Selected Text Model does not seem to be a GGUF file! Are you sure you picked the right file?") loadok = load_model(modelname) print("Load Text Model OK: " + str(loadok)) + if not loadok: + exitcounter = 999 + exit_with_error(3,"Could not load text model: " + modelname) + if args.mmproj and args.mmproj!="": # multimodal vision and audio support is only known at runtime has_audio_support = handle.has_audio_support() has_vision_support = handle.has_vision_support() @@ -12367,10 +12371,6 @@ def kcpp_main_process(launch_args, g_memory=None, gui_launcher=False): has_audio_support = False has_vision_support = False - if not loadok: - exitcounter = 999 - exit_with_error(3,"Could not load text model: " + modelname) - # The chat completions adapter is a list that needs derivation from chat templates # Try to derive chat completions adapter from chat template, now that we have the model loaded if args.model_param: diff --git a/model_adapter.cpp b/model_adapter.cpp index 80dcddab1..34a11e2f1 100644 --- a/model_adapter.cpp +++ b/model_adapter.cpp @@ -322,6 +322,11 @@ std::string gguf_get_model_arch(const std::string & gguf_filename) ggufparams.ctx = NULL; auto ctx = gguf_init_from_file(fname.c_str(), ggufparams); + if (ctx == nullptr) + { + fprintf(stderr, "%s: error: failed to read GGUF file '%s'\n", __func__, fname.c_str()); + return FileFormat::BADFORMAT; + } auto keyidx = gguf_find_key(ctx, "general.architecture"); std::string modelarch = "";