Julia-1-LiteRT / conversion /make_table.py
mlboydaisuke's picture
Julia-1 LiteRT: S512 and S1024 fp32 graphs, float16 token table, Python host, conversion scripts
b92a0d2 verified
Raw History Blame Contribute Delete
815 Bytes
"""Write the host token tables from the checkpoint: [256000, 384] little-endian float16 (shipped) and float32."""
import hashlib
from pathlib import Path
import numpy as np
from safetensors import safe_open
ROOT = Path(__file__).resolve().parents[1]
def main():
with safe_open(str(ROOT / 'src/Julia-1/model.safetensors'), 'pt') as f:
table = f.get_tensor('encoder.embeddings.tok_embeddings.weight').numpy()
assert table.shape == (256000, 384) and table.dtype == np.float32
out = ROOT / 'exports'
out.mkdir(exist_ok=True)
for name, dtype in (('julia1_token_table_fp16.bin', '<f2'), ('julia1_token_table_f32.bin', '<f4')):
table.astype(dtype).tofile(out / name)
print(name, hashlib.sha256((out / name).read_bytes()).hexdigest())
if __name__ == '__main__':
main()