diff --git a/convert_edgetam_to_ggml.py b/convert_edgetam_to_ggml.py index 468293b..047b754 100644 --- a/convert_edgetam_to_ggml.py +++ b/convert_edgetam_to_ggml.py @@ -19,14 +19,12 @@ import struct import sys import os -import numpy as np +from ggml_writer import KEEP_F32, write_tensor # ── Constants ────────────────────────────────────────────────────────────────── MAGIC = 0x73616D32 # "sam2" — reuse SAM2 magic, dispatch on backbone_type VERSION = 1 -FTYPE_F32 = 0 -FTYPE_F16 = 1 # EdgeTAM hyperparameters (from edgetam.yaml) EDGETAM_HPARAMS = { @@ -472,48 +470,6 @@ def write_header(fout, ftype, n_tensors, hp): fout.write(struct.pack("= 2 - and "embed" not in name - and "pos_embed" not in name - and "tpos" not in name - and "pe_gaussian" not in name - and "token" not in name - and "no_obj" not in name - and "no_mem" not in name - and "gamma" not in name - and "latents" not in name) - - dtype_id = FTYPE_F16 if use_f16 else FTYPE_F32 - - if use_f16: - data = data.astype(np.float16) - else: - data = data.astype(np.float32) - - fout.write(struct.pack("= 2 - and "embed" not in name - and "pos_embed" not in name - and "tpos" not in name - and "pe_gaussian" not in name - and "token" not in name - and "no_obj" not in name - and "no_mem" not in name - and "gamma" not in name) - - dtype_id = FTYPE_F16 if use_f16 else FTYPE_F32 - - if use_f16: - data = data.astype(np.float16) - else: - data = data.astype(np.float32) - - fout.write(struct.pack(" str: diff --git a/convert_sam3_to_ggml.py b/convert_sam3_to_ggml.py index d35534f..56ae837 100644 --- a/convert_sam3_to_ggml.py +++ b/convert_sam3_to_ggml.py @@ -14,13 +14,12 @@ import os import re import numpy as np +from ggml_writer import KEEP_F32, write_tensor # ── Constants ────────────────────────────────────────────────────────────────── MAGIC = 0x73616D33 # "sam3" VERSION = 3 -FTYPE_F32 = 0 -FTYPE_F16 = 1 # ── Hyperparameter defaults ─────────────────────────────────────────────────── @@ -211,50 +210,6 @@ def write_header(fout, ftype: int, n_tensors: int, visual_only: bool = False): fout.write(struct.pack("= 2 - and "embed" not in name - and "pos_embed" not in name - and "tpos" not in name - and "pe_gaussian" not in name - and "freqs_cis" not in name - and "token" not in name - and "no_obj" not in name - and "no_mem" not in name - and "gamma" not in name) - - dtype_id = FTYPE_F16 if use_f16 else FTYPE_F32 - - if use_f16: - data = data.astype(np.float16) - else: - data = data.astype(np.float32) - - # Write: n_dims, name_len, dtype, shape (reversed), name, padding, data - fout.write(struct.pack("= 2 and not any(s in name for s in keep_f32) + name_bytes = name.encode("utf-8") + fout.write(struct.pack("<3i", data.ndim, len(name_bytes), FTYPE_F16 if use_f16 else FTYPE_F32)) + fout.write(struct.pack(f"<{data.ndim}i", *reversed(data.shape))) # ggml dims are reversed + fout.write(name_bytes) + fout.write(b"\x00" * (-fout.tell() % 32)) + fout.write(data.astype(np.float16 if use_f16 else np.float32).tobytes())