File size: 1,366 Bytes
7c325a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
Utility to safely inspect .safetensors checkpoints without opening binary files in text editors.
"""

import sys
import os
from safetensors import safe_open


def inspect_safetensors(filepath: str):
    if not os.path.exists(filepath):
        print(f"Error: File not found: {filepath}")
        return

    file_size_mb = os.path.getsize(filepath) / (1024 * 1024)
    print(f"==================================================")
    print(f" File: {os.path.basename(filepath)}")
    print(f" Path: {filepath}")
    print(f" Size: {file_size_mb:.2f} MB")
    print(f"==================================================")

    with safe_open(filepath, framework="pt") as f:
        meta = f.metadata() or {}
        print("\n--- Header Metadata ---")
        if meta:
            for k, v in meta.items():
                print(f"  {k}: {v}")
        else:
            print("  (No custom metadata embedded)")

        keys = list(f.keys())
        print(f"\n--- Tensors ({len(keys)} total) ---")
        for k in keys[:8]:
            t = f.get_tensor(k)
            print(f"  {k:45s} | shape: {str(list(t.shape)):20s} | dtype: {t.dtype}")

        if len(keys) > 8:
            print(f"  ... and {len(keys) - 8} more tensors.")


if __name__ == "__main__":
    target = sys.argv[1] if len(sys.argv) > 1 else "PRISM-1.safetensors"
    inspect_safetensors(target)