From a17b5f853d42f0678c36865d1f9c1a707480c1b2 Mon Sep 17 00:00:00 2001 From: Andrew Grant Date: Wed, 20 Sep 2023 10:48:15 -0400 Subject: [PATCH] Add spsa_reporting_type and spsa_distribution_type (#170) Reporting Method (BATCHED vs BULK) for SPSA Tests Send everything at once, vs every time a pair finishes Distribution Method (SINGLE vs MULTIPLE) for SPSA Tests Give 1 parameter set; Give as many sets as we can --- Client/Client.py | 6 ++- OpenBench/workloads/create_workload.py | 4 ++ OpenBench/workloads/get_workload.py | 36 +++++++++----- OpenBench/workloads/verify_workload.py | 68 +++++++++++++++----------- Templates/OpenBench/base.html | 2 +- Templates/OpenBench/create_tune.html | 19 ++++++- Templates/OpenBench/tune.html | 4 +- 7 files changed, 95 insertions(+), 44 deletions(-) diff --git a/Client/Client.py b/Client/Client.py index 227032c..29e1066 100644 --- a/Client/Client.py +++ b/Client/Client.py @@ -606,6 +606,10 @@ class ResultsReporter(object): self.last_report = 0 self.pending = [] + # Don't report until finished, for BULK SPSA tests + self.bulk = self.config.workload['test']['type'] == 'SPSA' + self.bulk = self.bulk and self.config.workload['reporting_type'] == 'BULK' + # Block up-to 5 seconds to get a new result def get_next_result(): try: return self.results_queue.get(timeout=5) @@ -618,7 +622,7 @@ class ResultsReporter(object): self.pending.append(result) # Send results every 30 seconds, until all Tasks are done - if self.send_results(report_interval=REPORT_INTERVAL): + if not self.bulk and self.send_results(report_interval=REPORT_INTERVAL): return # Kill everything if openbench.exit is created diff --git a/OpenBench/workloads/create_workload.py b/OpenBench/workloads/create_workload.py index b3f6731..1cdfd65 100644 --- a/OpenBench/workloads/create_workload.py +++ b/OpenBench/workloads/create_workload.py @@ -203,6 +203,10 @@ def extract_spas_params(request): spsa['pairs_per' ] = int(request.POST['spsa_pairs_per']) spsa['A' ] = spsa['A_ratio'] * spsa['iterations'] + # Tuning Methodologies + spsa['reporting_type' ] = request.POST['spsa_reporting_type'] + spsa['distribution_type'] = request.POST['spsa_distribution_type'] + # Each individual tuning parameter spsa['parameters'] = {} for line in request.POST['spsa_inputs'].split('\n'): diff --git a/OpenBench/workloads/get_workload.py b/OpenBench/workloads/get_workload.py index b60cf10..50e6f4d 100644 --- a/OpenBench/workloads/get_workload.py +++ b/OpenBench/workloads/get_workload.py @@ -37,9 +37,12 @@ # Our response includes three critical values: # # 1. cutechess-count The # of Sockets on the worker for SPRT/FIXED tests -# The # of max possible concurrent games for SPRT tests +# The # of max possible concurrent pairs for SPSA tests +# Unless the distribution type is SINGLE +# # 2. concurrency-per The # of concurrent games to run per Cutechess copy. # Function of the machine, and each engine's options +# # 3. games-per-cutechess # of total games to run per Cutechess copy # This is the 2 x workload_size x concurrency-per @@ -223,16 +226,24 @@ def workload_to_dictionary(test, result, machine): 'private' : OPENBENCH_CONFIG['engines'][test.base_engine]['private'], } - workload['distribution'] = game_distribution(test, machine) - workload['spsa'] = spsa_to_dictionary(test, workload['distribution']['cutechess-count']) + workload['distribution'] = game_distribution(test, machine) + workload['spsa'] = spsa_to_dictionary(test, workload) + workload['reporting_type'] = test.spsa['reporting_type'] return workload -def spsa_to_dictionary(test, permutations): +def spsa_to_dictionary(test, workload): if test.test_mode != 'SPSA': return None + # Only use one set of parameters if distribution is SINGLE. + # Duplicate the params, even though they are the same, across all + # Sockets on the machine, in the event of a singular SPSA distribution + is_single = test.spsa['distribution_type'] == 'SINGLE' + permutations = 1 if is_single else workload['distribution']['cutechess-count'] + duplicates = 1 if not is_single else workload['distribution']['cutechess-count'] + # C & R are scaled over the course of the iterations iteration = 1 + (test.games / (test.spsa['pairs_per'] * 2)) c_compression = iteration ** test.spsa['Gamma'] @@ -274,9 +285,11 @@ def spsa_to_dictionary(test, permutations): base = int(base) # Append each permutation - spsa[name]['dev' ].append(dev) - spsa[name]['base'].append(base) - spsa[name]['flip'].append(flip) + for g in range(duplicates): + spsa[name]['dev' ].append(dev) + spsa[name]['base'].append(base) + spsa[name]['flip'].append(flip) + return spsa @@ -307,10 +320,11 @@ def game_distribution(test, machine): # Number of params being evaluated at a single time spsa_count = (worker_threads // max(dev_threads, base_threads)) // 2 - is_spsa = test.test_mode == 'SPSA' + # SPSA is treated specially, if we are distributing many parameter sets at once + is_multiple_spsa = test.test_mode == 'SPSA' and test.spsa['distribution_type'] == 'MULTIPLE' return { - 'cutechess-count' : spsa_count if is_spsa else worker_sockets, - 'concurrency-per' : 2 if is_spsa else concurrency, - 'games-per-cutechess' : 2 * test.workload_size * (1 if is_spsa else concurrency), + 'cutechess-count' : spsa_count if is_multiple_spsa else worker_sockets, + 'concurrency-per' : 2 if is_multiple_spsa else concurrency, + 'games-per-cutechess' : 2 * test.workload_size * (1 if is_multiple_spsa else concurrency), } diff --git a/OpenBench/workloads/verify_workload.py b/OpenBench/workloads/verify_workload.py index 735734b..57d3a4c 100644 --- a/OpenBench/workloads/verify_workload.py +++ b/OpenBench/workloads/verify_workload.py @@ -111,45 +111,47 @@ def verify_tune_creation(errors, request): verifications = [ + # Verify the SPSA raw inputs and methods + (verify_spsa_inputs , 'spsa_inputs'), + (verify_spsa_reporting_type , 'spsa_reporting_type', 'Reporting Method'), + (verify_spsa_distribution_type, 'spsa_distribution_type', 'Distribution Method'), + # Verify everything about the Engine - (verify_configuration , 'dev_engine', 'Engine', 'engines'), - (verify_github_repo , 'dev_repo'), - (verify_network , 'dev_network', 'Network', 'dev_engine'), - (verify_options , 'dev_options', 'Threads', 'Options'), - (verify_options , 'dev_options', 'Hash', 'Options'), - (verify_time_control , 'dev_time_control', 'Time Control'), + (verify_configuration , 'dev_engine', 'Engine', 'engines'), + (verify_github_repo , 'dev_repo'), + (verify_network , 'dev_network', 'Network', 'dev_engine'), + (verify_options , 'dev_options', 'Threads', 'Options'), + (verify_options , 'dev_options', 'Hash', 'Options'), + (verify_time_control , 'dev_time_control', 'Time Control'), # Verify everything about the Test Settings - (verify_configuration , 'book_name', 'Book', 'books'), + (verify_configuration , 'book_name', 'Book', 'books'), # Verify everything about the General Settings - (verify_integer , 'priority', 'Priority'), - (verify_greater_than , 'throughput', 'Throughput', 0), - (verify_syzygy_field , 'syzygy_wdl', 'Syzygy WDL'), + (verify_integer , 'priority', 'Priority'), + (verify_greater_than , 'throughput', 'Throughput', 0), + (verify_syzygy_field , 'syzygy_wdl', 'Syzygy WDL'), # Verify everything about the Workload Settings - (verify_integer_or_none, 'worker_limit', 'Worker Limit'), - (verify_integer_or_none, 'thread_limit', 'Thread Limit'), + (verify_integer_or_none , 'worker_limit', 'Worker Limit'), + (verify_integer_or_none , 'thread_limit', 'Thread Limit'), # Verify everything about the Adjudicaton Settings - (verify_syzygy_field , 'syzygy_adj', 'Syzygy Adjudication'), - (verify_win_adj , 'win_adj'), - (verify_draw_adj , 'draw_adj'), + (verify_syzygy_field , 'syzygy_adj', 'Syzygy Adjudication'), + (verify_win_adj , 'win_adj'), + (verify_draw_adj , 'draw_adj'), # Verify everything about the SPSA Settings - (verify_float , 'spsa_alpha', 'SPSA A-Ratio'), - (verify_float , 'spsa_alpha', 'SPSA Alpha'), - (verify_float , 'spsa_gamma', 'SPSA Gamma'), - (verify_integer , 'spsa_iterations', 'SPSA Iterations'), - (verify_integer , 'spsa_pairs_per', 'SPSA Pairs-Per'), - (verify_greater_than , 'spsa_alpha', 'SPSA A-Ratio', 0.00), - (verify_greater_than , 'spsa_alpha', 'SPSA Alpha', 0.00), - (verify_greater_than , 'spsa_gamma', 'SPSA Gamma', 0.00), - (verify_greater_than , 'spsa_iterations', 'SPSA Iterations', 0), - (verify_greater_than , 'spsa_pairs_per', 'SPSA Pairs-Per', 0), - - # Verify the SPSA raw inputs for each parameter - (verify_spsa_inputs , 'spsa_inputs'), + (verify_float , 'spsa_alpha', 'SPSA A-Ratio'), + (verify_float , 'spsa_alpha', 'SPSA Alpha'), + (verify_float , 'spsa_gamma', 'SPSA Gamma'), + (verify_integer , 'spsa_iterations', 'SPSA Iterations'), + (verify_integer , 'spsa_pairs_per', 'SPSA Pairs-Per'), + (verify_greater_than , 'spsa_alpha', 'SPSA A-Ratio', 0.00), + (verify_greater_than , 'spsa_alpha', 'SPSA Alpha', 0.00), + (verify_greater_than , 'spsa_gamma', 'SPSA Gamma', 0.00), + (verify_greater_than , 'spsa_iterations', 'SPSA Iterations', 0), + (verify_greater_than , 'spsa_pairs_per', 'SPSA Pairs-Per', 0), ] for verification in verifications: @@ -268,6 +270,16 @@ def verify_spsa_inputs(errors, request, field): traceback.print_exc() errors.append('Malformed SPSA Input') +def verify_spsa_reporting_type(errors, request, field, field_name): + candidates = ['BULK', 'BATCHED'] + try: assert request.POST[field] in candidates + except: errors.append('%s must be in %s' % (field_name, ', '.join(candidates))) + +def verify_spsa_distribution_type(errors, request, field, field_name): + candidates = ['SINGLE', 'MULTIPLE'] + try: assert request.POST[field] in candidates + except: errors.append('%s must be in %s' % (field_name, ', '.join(candidates))) + def collect_github_info(errors, request, field): diff --git a/Templates/OpenBench/base.html b/Templates/OpenBench/base.html index ff99fe9..837eb72 100644 --- a/Templates/OpenBench/base.html +++ b/Templates/OpenBench/base.html @@ -86,7 +86,7 @@ diff --git a/Templates/OpenBench/create_tune.html b/Templates/OpenBench/create_tune.html index 2d57d79..52201a6 100644 --- a/Templates/OpenBench/create_tune.html +++ b/Templates/OpenBench/create_tune.html @@ -60,11 +60,26 @@ +

SPSA Methodologies

+ +
+ +
+ +
+ +
+

SPSA Input

- - +
diff --git a/Templates/OpenBench/tune.html b/Templates/OpenBench/tune.html index 974eed1..8d8ca15 100644 --- a/Templates/OpenBench/tune.html +++ b/Templates/OpenBench/tune.html @@ -67,7 +67,9 @@ Draw ADJ.{{test.draw_adj}} Alpha{{test.spsa.Alpha}} Gamma{{test.spsa.Gamma}} - A-Ratio{{test.spsa.A}} + A-Ratio{{test.spsa.A_ratio}} + Reporting Method{{test.spsa.reporting_type}} + Distribution Method{{test.spsa.distribution_type}}