constella-zero / scripts /convert-to-safensors.py
jmzzomg's picture DylanCouzon's picture itsclelia's picture
feat: add static-embeddings like F16 safetensors lookup table (#1)
d06c1cc
Raw History Blame Contribute Delete
621 Bytes
#!/usr/bin/env -S uv run --script
#
# /// script
# requires-python = ">=3.12"
# dependencies = ["safetensors", "numpy"]
# ///
import numpy as np
from safetensors.numpy import save_file
d = np.load("model.npz")
W = np.ascontiguousarray(d["rows_int8"]) # (30522, 1024) int8, the released table
scale = d["int8_scale"].astype(np.float32) # (30522,) per-row dequantization scale
assert W.shape == (30522, 1024) and W.dtype == np.int8 and scale.shape == (30522,)
# FastEmbed's static models multiply each token's row by `weights`, which dequantizes it.
save_file({"embeddings": W, "weights": scale}, "model.safetensors")