import argparse import json from pathlib import Path from types import SimpleNamespace from safetensors.torch import load_file from interseek.base import sha256 from interseek.cli import execution_device, make_model from interseek.data import read_records from interseek.engine import TrainConfig, predict, source_identity, write_predictions parser = argparse.ArgumentParser(description='Predict interactions with exported InterSeek weights.') parser.add_argument('--data', required=True) parser.add_argument('--predictions', required=True) parser.add_argument('--device', default='auto') args = parser.parse_args() root = Path(__file__).resolve().parent metadata = json.loads((root / 'config.json').read_text()) if sha256(root / 'model.safetensors') != metadata['weights_sha256']: raise ValueError('Exported weights checksum mismatch.') if source_identity() != metadata['inference_source_sha256']: raise ValueError('Install the InterSeek wheel included with this export.') config = TrainConfig(**metadata['protocol']['config']) device, precision = execution_device(args.device, 'auto') model, batcher, _ = make_model(SimpleNamespace(), config, metadata['protocol']['initialization']) model.restore(load_file(str(root / 'model.safetensors'))) model.to(device) model.eval() rows = read_records(args.data, labelled=False) scores = predict(model, batcher, rows, device, config.batch_size, precision, progress=True) write_predictions(args.predictions, rows, scores) print(json.dumps({'pairs': len(rows), 'predictions': args.predictions, 'validation_threshold': metadata['threshold']}))