prevent segfault on load fail

This commit is contained in:
Concedo
2026-09-13 22:01:18 +08:00
parent bcc718d836
commit 49b9132287
4 changed files with 19 additions and 4 deletions
+5
View File
@@ -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;
+5
View File
@@ -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);
+4 -4
View File
@@ -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:
+5
View File
@@ -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 = "";