File size: 898 Bytes
db32e07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import torch
import sys
from pathlib import Path

path = Path("out/stage2/perceiver.pt")
if not path.exists():
    print(f"{path} does not exist.")
    sys.exit(1)

print(f"Loading {path}...")
state = torch.load(path, map_location="cpu")

print("Checking parameters...")
has_nan = False
has_inf = False
all_zeros = False

for k, v in state.items():
    if torch.isnan(v).any():
        print(f"NAN found in {k}")
        has_nan = True
    if torch.isinf(v).any():
        print(f"INF found in {k}")
        has_inf = True
    if (v == 0).all():
        print(f"ALL ZEROS in {k}")
        all_zeros = True
    
    # print stats
    print(f"{k}: mean={v.mean().item():.4f}, std={v.std().item():.4f}")

if has_nan or has_inf:
    print("FATAL: Model weights contain NaN or Inf.")
elif all_zeros:
    print("WARNING: Some layers are all zeros.")
else:
    print("Weights look healthy (no NaN/Inf).")