examples/ is based on KasperskyLab/knp at 55470ed6 with local changes to the mnist-learn altai/blifat models, cuda-backend CMake and model_loader. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1.9 KiB
Python
37 lines
1.9 KiB
Python
"""Select a bounded STDP model family with parallel independent KNP runs."""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument('--jobs', type=int, default=4)
|
|
ap.add_argument('--prefix', default='v2_val')
|
|
a = ap.parse_args()
|
|
if not re.fullmatch(r'[A-Za-z0-9_-]+', a.prefix):
|
|
ap.error('Invalid run prefix')
|
|
root = Path('/home/int/run/cats-dogs')
|
|
out = root / ('selection-v2.json' if a.prefix == 'v2_val' else f'{a.prefix}-selection.json')
|
|
if out.exists():
|
|
ap.error('Selection already exists; use a new --prefix')
|
|
folder = root / 'acceleration'
|
|
folder.mkdir(exist_ok=True)
|
|
jobs, configs = [], []
|
|
for columns in (20, 60):
|
|
for threshold in (600, 1600, 4000, 8000):
|
|
name = f'{a.prefix}_c{columns}_t{threshold}'
|
|
jobs.append({'name': name, 'args': ['--data-dir', str(root / 'features-v2'),
|
|
'--dataset', 'sparse_hog_validation', '--train', '4000', '--count', '1000',
|
|
'--threshold', str(threshold), '--columns', str(columns), '--quant', 'weights']})
|
|
configs.append(dict(run=name, columns=columns, threshold=threshold, encoding='sparse_hog', quant='weights'))
|
|
plan = folder / f'{a.prefix}-plan.json'
|
|
plan.write_text(json.dumps({'jobs': jobs}, indent=2) + '\n')
|
|
subprocess.run([sys.executable, str(Path(__file__).with_name('run_batch.py')), str(plan),
|
|
'--jobs', str(a.jobs), '--summary', str(folder / f'{a.prefix}-summary.json')], check=True)
|
|
rows = [dict(**cfg, **json.loads((root / cfg['run'] / 'metrics.json').read_text())) for cfg in configs]
|
|
selection = {'method': '8 predeclared configurations on fresh validation only; first wins ties',
|
|
'parallel_jobs': a.jobs, 'rows': rows, 'selected': max(rows, key=lambda row: row['accuracy'])}
|
|
out.write_text(json.dumps(selection, indent=2) + '\n')
|
|
print('SELECTED', json.dumps(selection['selected']), flush=True)
|