| 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).") | |