Implement support for DATAGEN Workloads through the genfens interface (#200)

This commit is contained in:
Andrew Grant authored and GitHub committed 2024-03-12 21:22:07 -04:00
1 parent 45302fa347
commit 2fcb7329ce
57 files changed
+1096 -131

No files matched your search

+49 -24
View File
@@ -50,6 +50,7 @@ from client import try_forever
from utils import *
from pgn_util import compress_list_of_pgns
from genfens import create_genfens_opening_book
## Basic configuration of the Client. These timeouts can be changed at will
@@ -277,7 +278,7 @@ class ServerReporter:
return ServerReporter.report(config, 'clientSubmitError', payload)
@staticmethod
def report_engine_error(config, error, pgn):
def report_engine_error(config, error, pgn=None):
payload = {
'test_id' : config.workload['test']['id'],
@@ -379,8 +380,12 @@ class Cutechess:
is_frc = 'FRC' in book_name or '960' in book_name or 'FISCHER' in book_name
variant = ['standard', 'fischerandom'][is_frc]
# Always include -repeat and -recover
return '-repeat -recover -variant %s' % (variant)
# Only include -repeat if not skipping the reverses in DATAGEN
is_datagen = config.workload['test']['type'] == 'DATAGEN'
no_reverse = is_datagen and not config.workload['test']['play_reverses']
# Always include -recover and -variant
return ['-repeat', ''][no_reverse] + ' -recover -variant %s' % (variant)
@staticmethod
def concurrency_settings(config):
@@ -417,6 +422,15 @@ class Cutechess:
@staticmethod
def book_settings(config, cutechess_idx):
# DATAGEN creates their own book
if config.workload['test']['type'] == 'DATAGEN':
# -repeat might not be applied, so handle the book offsets
no_reverse = not config.workload['test']['play_reverses']
pairs = config.workload['distribution']['games-per-cutechess'] // 2
start = 1 + (cutechess_idx * pairs * (1 + no_reverse))
return '-openings file=Books/openbench.genfens.epd format=epd order=sequential start=%d' % (start)
# Can handle EPD and PGN Books, which must be specified
book_name = config.workload['test']['book']['name']
book_suffix = book_name.split('.')[-1]
@@ -522,14 +536,13 @@ class Cutechess:
def kill_everything(dev_process, base_process):
if IS_LINUX:
subprocess.run(['pkill', '-f', 'cutechess-ob'])
subprocess.run(['pkill', '-f', dev_process])
subprocess.run(['pkill', '-f', base_process])
kill_process_by_name('cutechess-ob')
if IS_WINDOWS:
subprocess.run(['taskkill', '/f', '/im', 'cutechess-ob.exe'])
subprocess.run(['taskkill', '/f', '/im', dev_process])
subprocess.run(['taskkill', '/f', '/im', base_process])
kill_process_by_name('cutechess-ob.exe')
kill_process_by_name(dev_process)
kill_process_by_name(base_process)
@staticmethod
def pgn_name(config, timestamp, cutechess_idx):
@@ -940,16 +953,20 @@ def complete_workload(config):
)
# Download each NNUE file, throws an exception on corruption
dev_network = download_network_weights(config, 'dev' )
base_network = download_network_weights(config, 'base')
dev_network = safe_download_network_weights(config, 'dev' )
base_network = safe_download_network_weights(config, 'base')
# Build or download each engine, or exit if an error occured
dev_name = download_engine(config, 'dev' , dev_network )
base_name = download_engine(config, 'base', base_network)
dev_name = safe_download_engine(config, 'dev' , dev_network )
base_name = safe_download_engine(config, 'base', base_network)
# Datagen creates a book on-the-fly
if config.workload['test']['type'] == 'DATAGEN':
safe_create_genfens_opening_book(config, dev_name, dev_network)
# Run the benchmarks and compute the scaling NPS value
dev_nps = run_benchmarks(config, 'dev' , dev_name , dev_network )
base_nps = run_benchmarks(config, 'base', base_name, base_network)
dev_nps = safe_run_benchmarks(config, 'dev' , dev_name , dev_network )
base_nps = safe_run_benchmarks(config, 'base', base_name, base_network)
ServerReporter.report_nps(config, dev_nps, base_nps)
# Scale the engines together, using their NPS relative to expected
@@ -962,11 +979,6 @@ def complete_workload(config):
print ('Scale Factor Base : %.4f' % (base_factor))
print ('Scale Factor Avg : %.4f' % (avg_factor ))
# Scale using the base factor only, in the event of a cross-engine test
dev_engine = config.workload['test']['dev' ]['engine']
base_engine = config.workload['test']['base']['engine']
scale_factor = base_factor if dev_engine != base_engine else avg_factor
# Server knows how many copies of Cutechess we should run
cutechess_cnt = config.workload['distribution']['cutechess-count']
concurrency_per = config.workload['distribution']['concurrency-per']
@@ -975,7 +987,12 @@ def complete_workload(config):
print () # Record this information
print ('%d cutechess copies' % (cutechess_cnt))
print ('%d concurrent games per copy' % (concurrency_per))
print ('%d total games per cutechess copy' % (games_per))
print ('%d total games per cutechess copy\n' % (games_per))
# Scale using the base factor only, in the event of a cross-engine test
dev_engine = config.workload['test']['dev' ]['engine']
base_engine = config.workload['test']['base']['engine']
scale_factor = base_factor if dev_engine != base_engine else avg_factor
# Launch and manage all of the Cutechess workers
with ThreadPoolExecutor(max_workers=cutechess_cnt) as executor:
@@ -1009,7 +1026,7 @@ def complete_workload(config):
pgn_files = [Cutechess.pgn_name(config, timestamp, x) for x in range(cutechess_cnt)]
ServerReporter.report_pgn(config, compress_list_of_pgns(pgn_files, scale_factor, compact))
def download_network_weights(config, branch):
def safe_download_network_weights(config, branch):
# Wraps utils.py:download_network()
# May raise OpenBenchCorruptedNetworkException
@@ -1028,7 +1045,7 @@ def download_network_weights(config, branch):
return net_path
def download_engine(config, branch, net_path):
def safe_download_engine(config, branch, net_path):
# Wraps utils.py:download_public_engine() and utils.py:download_private_engine()
@@ -1070,8 +1087,15 @@ def download_engine(config, branch, net_path):
ServerReporter.report_build_fail(config, branch, error.logs)
raise
def safe_create_genfens_opening_book(config, dev_name, dev_network):
def run_benchmarks(config, branch, engine, network):
try: create_genfens_opening_book(config, dev_name, dev_network)
except OpenBenchFailedGenfensException as error:
ServerReporter.report_engine_error(config, error.message)
raise
def safe_run_benchmarks(config, branch, engine, network):
name = config.workload['test'][branch]['name']
private = config.workload['test'][branch]['private']
@@ -1091,6 +1115,7 @@ def run_benchmarks(config, branch, engine, network):
print('Speed for %s is %d' % (name, speed))
return speed
def build_cutechess_command(config, dev_cmd, base_cmd, scale_factor, timestamp, cutechess_idx):
flags = ' ' + Cutechess.basic_settings(config)