]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
convert : handle mmproj filename/path properly (#16760)
authorGalunid <redacted>
Sat, 25 Oct 2025 18:41:36 +0000 (20:41 +0200)
committerGitHub <redacted>
Sat, 25 Oct 2025 18:41:36 +0000 (20:41 +0200)
* convert: handle mmproj model output filename properly

* remove redundant commits

* Add model_type to gguf utility

* Use mmproj- prefix instead of suffix

* Apply CISC suggestion

Co-authored-by: Sigbjørn Skjæret <redacted>
---------

Co-authored-by: Sigbjørn Skjæret <redacted>
convert_hf_to_gguf.py

index 859c1443f5f8494d42f83ef2d325aadc978421a9..05d791806df1e8a73528b3aa23b193484cfd6ab7 100755 (executable)
@@ -1497,6 +1497,17 @@ class MmprojModel(ModelBase):
     def set_type(self):
         self.gguf_writer.add_type(gguf.GGUFType.MMPROJ)
 
+    def prepare_metadata(self, vocab_only: bool):
+        super().prepare_metadata(vocab_only=vocab_only)
+
+        output_type: str = self.ftype.name.partition("_")[2]
+
+        if self.fname_out.is_dir():
+            fname_default: str = gguf.naming_convention(self.metadata.name, self.metadata.basename, self.metadata.finetune, self.metadata.version, size_label=None, output_type=output_type, model_type=None)
+            self.fname_out = self.fname_out / f"mmproj-{fname_default}.gguf"
+        else:
+            self.fname_out = self.fname_out.parent / gguf.fill_templated_filename(self.fname_out.name, output_type)
+
     def set_gguf_parameters(self):
         self.gguf_writer.add_file_type(self.ftype)
 
@@ -9729,10 +9740,6 @@ def main() -> None:
 
     logger.info(f"Loading model: {dir_model.name}")
 
-    if args.mmproj:
-        if "mmproj" not in fname_out.name:
-            fname_out = ModelBase.add_prefix_to_filename(fname_out, "mmproj-")
-
     is_mistral_format = args.mistral_format
     if is_mistral_format and not _mistral_common_installed:
         raise ImportError(_mistral_import_error_msg)