h3-blackwell-runtime/tools/inspect_safetensors.py

23 lines
672 B
Python
Raw Permalink Normal View History

2026-08-14 13:32:01 +07:00
"""Print safetensors key shapes."""
2026-08-12 14:12:42 +07:00
import argparse
2026-08-14 13:32:01 +07:00
from safetensors import safe_open
2026-08-12 14:12:42 +07:00
2026-08-14 13:32:01 +07:00
parser = argparse.ArgumentParser()
parser.add_argument("path")
parser.add_argument("--head", type=int, default=80)
parser.add_argument("--tail", type=int, default=30)
args = parser.parse_args()
2026-08-12 14:12:42 +07:00
2026-08-14 13:32:01 +07:00
with safe_open(args.path, framework="pt", device="cpu") as checkpoint:
keys = list(checkpoint.keys())
print({"path": args.path, "keys": len(keys)})
for key in keys[:args.head]:
print(key, checkpoint.get_slice(key).get_shape())
if args.tail:
print("last")
for key in keys[-args.tail:]:
print(key, checkpoint.get_slice(key).get_shape())