From e00becb643b3a99de16462b3a032717a93b983d9 Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Wed, 17 Jun 2026 01:21:41 +0200 Subject: all: accept F16 safetensors weights (widen to F32 at load) --- src/model_internal.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/model_internal.h') diff --git a/src/model_internal.h b/src/model_internal.h index f61b069..acbba07 100644 --- a/src/model_internal.h +++ b/src/model_internal.h @@ -12,7 +12,8 @@ * file. The frontends and the GPU backends do not include this header. */ /* Validate that a safetensor matches an expected dtype/rank/shape and that its - * bytes lie within the mapped file. bf16_ok permits BF16 in addition to F32. */ + * bytes lie within the mapped file. bf16_ok permits either 16-bit float format + * (BF16 or F16) in addition to F32. */ int tensor_has_supported_shape(const safetensors_file_t *sf, const safetensor_t *t, const char *name, @@ -20,6 +21,12 @@ int tensor_has_supported_shape(const safetensors_file_t *sf, int ndim, int bf16_ok); +/* Build a weight ref from a located tensor: F32/BF16 borrow the mmap, F16 is + * widened to an owned F32 buffer (no fused F16 kernel). Shared by the model + * loader and the late-interaction projection loader; the owner frees ref.data + * when ref.owned is set. Returns ref.data == NULL on allocation failure. */ +embed_weight_ref_t weight_ref_from_tensor(const safetensors_file_t *sf, const safetensor_t *t); + /* True if model_dir carries a 1_Dense projection (a late-interaction model). */ int model_dir_has_late_projection(const char *model_dir); -- cgit v1.3.1