"""Dump the token-embedding matrix of a GGUF model as raw float32 (n_vocab x n_embd), dequantized exactly as llama.cpp reads it, so that feeding E[t] as an input embedding is the same as feeding token t. usage: dump_embd.py gguf/lfm3-orig-q5km.gguf gguf/lfm3-q5km.embd.f32 """ import sys import numpy as np sys.path.insert(0, "C:/Users/user/llama-src/gguf-py") from gguf import GGUFReader # noqa: E402 from gguf.quants import dequantize # noqa: E402 r = GGUFReader(sys.argv[1]) t = next(t for t in r.tensors if t.name == "token_embd.weight") print(t.name, t.tensor_type.name, t.shape) E = dequantize(t.data, t.tensor_type).astype(np.float32) E = E.reshape(-1, E.shape[-1]) print("dequantized", E.shape, float(np.abs(E).mean())) E.tofile(sys.argv[2])