"""Makes the release files into ~/hw-bench/glm_release/ (paths are those of the author's machine; adjust): vision.onnx, text.onnx one file each (the weights inside; the graphs of parts/, parts/) embeddings.bin the word table as int8, one row of 1536 per word, then one float32 scale per row (row value = int8 * scale) SHA256SUMS python3 make_release.py [VISION_PART] [TEXT_PART] (default v_nb8_b128 t_nb4_b128)""" import hashlib, json, os, sys, numpy as np, onnx root = os.path.expanduser('~/hw-bench/glm_onnx'); out = os.path.expanduser('~/hw-bench/glm_release'); os.makedirs(out, exist_ok=True) vpart = sys.argv[1] if len(sys.argv) > 1 else 'v_nb8_b128'; tpart = sys.argv[2] if len(sys.argv) > 2 else 't_nb4_b128' for part, src in (('vision', vpart), ('text', tpart)): m = onnx.load(f'{root}/parts/{src}/{part}.onnx') # (reads the .data file beside it) onnx.save_model(m, f'{out}/{part}.onnx') # (and writes everything into one file) print(part, os.path.getsize(f'{out}/{part}.onnx') // 2**20, 'MB') e = np.load(f'{root}/embed.npy').astype(np.float32) scale = np.abs(e).max(1) / 127 + 1e-12 q = np.round(e / scale[:, None]).astype(np.int8) with open(f'{out}/embeddings.bin', 'wb') as f: f.write(q.tobytes()); f.write(scale.astype('