"""Gate 0: merge a text GGUF and its mmproj GGUF into one file (text KVs win on key clashes), to test whether llama.cpp can load the same file as both -m and --mmproj.""" import sys from gguf import GGUFReader, GGUFWriter, GGUFValueType text_path, mm_path, out_path = sys.argv[1:4] readers = [GGUFReader(text_path), GGUFReader(mm_path)] w = GGUFWriter(out_path, readers[0].fields["general.architecture"].contents()) seen = {"general.architecture"} for r in readers: for name, f in r.fields.items(): if name in seen or name.startswith("GGUF."): continue seen.add(name) t = f.types[0] w.add_key_value(name, f.contents(), t, sub_type=f.types[-1] if t == GGUFValueType.ARRAY else None) for r in readers: for t in r.tensors: w.add_tensor_info(t.name, t.data.shape, t.data.dtype, t.data.nbytes, raw_dtype=t.tensor_type) w.write_header_to_file() w.write_kv_data_to_file() w.write_ti_data_to_file() for r in readers: for t in r.tensors: w.write_tensor_data(t.data) w.close() print("wrote", out_path, sum(len(r.tensors) for r in readers), "tensors")