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
"""Compare serial/parallel throughput on the same four validation configurations."""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
root = Path('/home/int/run/cats-dogs')
|
|
out = root / 'acceleration'
|
|
out.mkdir(exist_ok=True)
|
|
script = Path(__file__).with_name('run_batch.py')
|
|
summaries = {}
|
|
for mode, workers in [('serial', 1), ('parallel', 4)]:
|
|
jobs = []
|
|
for threshold in (600, 1600, 4000, 8000):
|
|
jobs.append({'name': f'bench_{mode}_t{threshold}', 'args': [
|
|
'--data-dir', str(root / 'features-v2'), '--dataset', 'sparse_hog_validation',
|
|
'--train', '4000', '--count', '1000', '--threshold', str(threshold),
|
|
'--columns', '20', '--quant', 'weights', '--backend', 'single']})
|
|
plan, summary = out / f'{mode}-plan.json', out / f'{mode}-summary.json'
|
|
plan.write_text(json.dumps({'jobs': jobs}, indent=2) + '\n')
|
|
subprocess.run([sys.executable, str(script), str(plan), '--jobs', str(workers),
|
|
'--summary', str(summary)], check=True)
|
|
summaries[mode] = json.loads(summary.read_text())
|
|
checks = {}
|
|
for threshold in (600, 1600, 4000, 8000):
|
|
checks[str(threshold)] = {}
|
|
for file in ('float_weights.csv', 'quant_weights.csv', 'float_neurons.csv', 'quant_neurons.csv', 'result.csv'):
|
|
a = (root / f'bench_serial_t{threshold}' / file).read_bytes()
|
|
b = (root / f'bench_parallel_t{threshold}' / file).read_bytes()
|
|
checks[str(threshold)][file] = a == b
|
|
assert all(value for files in checks.values() for value in files.values()), 'Parallel run changed results'
|
|
result = {'serial': summaries['serial'], 'parallel': summaries['parallel'],
|
|
'speedup': summaries['serial']['elapsed_seconds'] / summaries['parallel']['elapsed_seconds'],
|
|
'bitwise_equal': checks}
|
|
(out / 'batch-benchmark.json').write_text(json.dumps(result, indent=2) + '\n')
|
|
print('SPEEDUP', result['speedup'], flush=True)
|