#!/usr/bin/env python3 """P0-01: parse vendor safetensors header + config into a tensor/precision map. Reads only the 2 MB header prefix and config/index JSON. Never loads weights. """ import json import struct import collections import sys from pathlib import Path V = Path(__file__).resolve().parent.parent / "vendor" OUT = Path(__file__).resolve().parent.parent / "results" def load_header(path): b = path.read_bytes() n = struct.unpack("2} {'attn':<8} {'loop':<5} {'expertq':<7} {'expert Gp':>9} {'nonexp Mp':>10}") for i in layers: v = per_layer[i] print(f"{i:>2} {v['attn']:<8} {str(v['loop']):<5} {v['expert_quant']:<7} " f"{v['expert_logical_params']/1e9:9.3f} {v['layer_non_expert_params']/1e6:10.2f}") print("\n== quant method groups (hf_quant_config) ==") for grp, body in qcfg.items(): if not isinstance(body, dict): print(" ", grp, body) continue for pg in body.get("parameter_groups", []): print(f" {grp}: compute={pg.get('compute_dtype')} out={pg.get('output_dtype')} " f"act_q={pg.get('required_activation_quantization')} n={len(pg.get('tensors', []))}") OUT.mkdir(exist_ok=True) out = { "source": { "repo": "thinkingmachines/Inkling-2-Mini", "revision": json.load(open(V / "inkling-api.json"))["sha"], "total_size_bytes": json.load(open(V / "inkling-model.safetensors.index.json"))["metadata"]["total_size"], }, "config": cfg, "per_layer": {str(k): v for k, v in per_layer.items()}, "accounting": { "expert_logical_params": expert_logical_total, "text_total_params": text_layer_logical + embed_params, "vision_total_params": vision_params, "attn_res_params": attn_res, }, } (OUT / "tensor-map.json").write_text(json.dumps(out, indent=1)) print(f"\nwrote {OUT/'tensor-map.json'}") if __name__ == "__main__": sys.exit(main())