#!/usr/bin/env python3 """Scan FP8-E4M3 weight-scale tensors in a safetensors checkpoint for NaN bytes. ModelOpt 0.44 can occasionally emit literal E4M3 NaN encodings (0x7F / 0xFF) when the float32->FP8 cast of a per-block weight scale rounds above the E4M3 max of 448. A single NaN in any weight_scale collapses served output. Expect ZERO hits. Usage: python scan_weight_scale_nan.py /path/to/checkpoint_dir_or_file [--all-fp8] """ import argparse import glob import json import os import struct import sys def iter_safetensors_headers(path): with open(path, "rb") as f: header_len = struct.unpack("