#!/usr/bin/env python3 """Export NNUE weights to binary format for runtime loading.""" import torch import struct import sys from pathlib import Path def export_weights_to_binary(weights_file, output_file): """Load PyTorch weights and export as binary file.""" if not Path(weights_file).exists(): print(f"Error: Weights file not found at {weights_file}") sys.exit(1) # Load weights state_dict = torch.load(weights_file, map_location='cpu') # Debug: print available layers print(f"Available layers in {weights_file}:") for key in sorted(state_dict.keys()): print(f" {key}: {state_dict[key].shape}") # Create output directory if needed output_path = Path(output_file) output_path.parent.mkdir(parents=True, exist_ok=True) with open(output_file, 'wb') as f: # Write magic number and version f.write(b'NNUE') f.write(struct.pack(' 1: weights_file = sys.argv[1] if len(sys.argv) > 2: output_file = sys.argv[2] export_weights_to_binary(weights_file, output_file)