From 945dff5b0bb1cf8a5663fd57eb8ded34f6412677 Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Tue, 24 Dec 2024 13:22:57 +0900 Subject: [PATCH 1/2] use last path component for unnamed ggufs Usually, a ggml-model-XXX.gguf file will reside in the directory named after the model, e.g. if the user generated the quant themselves and didn't move it. Instead of displaying models as ggml-model-xxx.gguf, this picks the last directory component and tacks the quant info on it. --- koboldcpp.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/koboldcpp.py b/koboldcpp.py index 5793098c753b0..8d94fec885e4f 100644 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -4496,6 +4496,14 @@ def main(launch_args,start_server=True): # sanitize and replace the default vanity name. remember me.... if args.model_param and args.model_param!="": newmdldisplayname = os.path.basename(args.model_param) + if ( + len(newmdldisplayname) < 25 + and args.model_param.count("/") > 1 + and newmdldisplayname.startswith("ggml-model-") + and newmdldisplayname.endswith(".gguf") + ): + # use the last path as model name, and stack on the quant info + newmdldisplayname = args.model_param.rsplit("/", 2)[1] + newmdldisplayname[10:] newmdldisplayname = os.path.splitext(newmdldisplayname)[0] friendlymodelname = "koboldcpp/" + sanitize_string(newmdldisplayname) From 109e6ea3d259e38c914e1d71b5d1920fada0bd5f Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Wed, 25 Dec 2024 13:50:33 +0900 Subject: [PATCH 2/2] only use path component in friendlymodelname if there are .safetensors files in the same dir --- koboldcpp.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/koboldcpp.py b/koboldcpp.py index 8d94fec885e4f..e439475a50f03 100644 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -4502,8 +4502,11 @@ def main(launch_args,start_server=True): and newmdldisplayname.startswith("ggml-model-") and newmdldisplayname.endswith(".gguf") ): - # use the last path as model name, and stack on the quant info - newmdldisplayname = args.model_param.rsplit("/", 2)[1] + newmdldisplayname[10:] + # if there are .safetensors files in the same dir, we can safely assume this is a model dir + # and the last path component is the model name + if any(p.endswith(".safetensors") for p in os.listdir(os.path.dirname(args.model_param))): + # use the last path as model name, and stack on the quant info + newmdldisplayname = args.model_param.rsplit("/", 2)[1] + newmdldisplayname[10:] newmdldisplayname = os.path.splitext(newmdldisplayname)[0] friendlymodelname = "koboldcpp/" + sanitize_string(newmdldisplayname)