| |
| """Minimal reader for tte-cmix-residual-blocks. This is the whole API.""" |
| import json, numpy as np |
|
|
| def load_block(root, bid): |
| M = json.load(open(f"{root}/manifest.json")) |
| B = next(b for b in M["blocks"] if b["id"] == bid) |
| n, d = M["block_bits"], f"{root}/blocks/{bid}" |
| X = np.fromfile(f"{d}/experts_i8.bin", np.int8).reshape(n, 25) |
| X = X * np.array(M["int8_scales"], np.float32) |
| fp = np.fromfile(f"{d}/final_p_u16.bin", np.uint16) |
| fl = np.fromfile(f"{d}/labels_u8.bin", np.uint8) |
| return dict( |
| experts=X, |
| final_p=fp.astype(np.float32) / 65536.0, |
| y=(fl & 1).astype(np.float32), |
| lstm_override=(fl >> 1) & 1, |
| bitpos=np.arange(n, dtype=np.int64) % 8, |
| byteoff=B["byte_start"] + np.arange(n, dtype=np.int64) // 8, |
| bytes_ctx=np.fromfile(f"{d}/bytes_ctx.bin", np.uint8), |
| meta=B, manifest=M, |
| ) |
|
|
| if __name__ == "__main__": |
| import sys |
| b = load_block(sys.argv[1] if len(sys.argv) > 1 else ".", sys.argv[2] if len(sys.argv) > 2 else "b000") |
| print({k: (v.shape if hasattr(v, "shape") else "…") for k, v in b.items()}) |
|
|