Files
chess-engine/python/python/evaluate.py
KeshavAnandCode 9e2fe0cae6 feat: add project structure and basic NNUE model
- Create python directory with data/, model/ subdirectories
- Implement LinearEval(61072->1) model
- Add config, constants, feature_extractor
- Add tests with 4 passing test cases
2026-04-14 18:03:42 -05:00

30 lines
610 B
Python

"""Evaluate model performance"""
import time
import torch
import numpy as np
from python.model.nnue_linear import LinearEval
def benchmark(model: LinearEval, samples: int = 1000) -> dict:
"""
Benchmark inference speed.
Returns:
dict with speed metrics
"""
model.eval()
x = torch.randn(samples, 61072)
start = time.time()
with torch.no_grad():
for _ in range(samples):
_ = model(x)
end = time.time()
return {
"samples": samples,
"time_seconds": end - start,
"ms_per_sample": (end - start) / samples * 1000,
}