Skip to content

Commit e56b270

Browse files
committed
Add multiple nets support to the server
Required by the new SF architecture with multiple nets, see: official-stockfish/Stockfish#4915 official-stockfish/Stockfish#5068
1 parent 9af4606 commit e56b270

File tree

4 files changed

+69
-45
lines changed

4 files changed

+69
-45
lines changed

server/fishtest/rundb.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
# To make this practical we will eventually put all schemas
5151
# in a separate module "schemas.py".
5252

53-
net_name = regex("nn-[a-z0-9]{12}.nnue", name="net_name")
53+
net_name = regex("nn-[a-f0-9]{12}.nnue", name="net_name")
5454
tc = regex(r"([1-9]\d*/)?\d+(\.\d+)?(\+\d+(\.\d+)?)?", name="tc")
5555
str_int = regex(r"[1-9]\d*", name="str_int")
5656
sha = regex(r"[a-f0-9]{40}", name="sha")
@@ -111,8 +111,8 @@
111111
"args": {
112112
"base_tag": str,
113113
"new_tag": str,
114-
"base_net": net_name,
115-
"new_net": net_name,
114+
"base_nets": [net_name, ...],
115+
"new_nets": [net_name, ...],
116116
"num_games": int,
117117
"tc": tc,
118118
"new_tc": tc,
@@ -322,8 +322,8 @@ def new_run(
322322
msg_new="",
323323
base_signature="",
324324
new_signature="",
325-
base_net=None,
326-
new_net=None,
325+
base_nets=None,
326+
new_nets=None,
327327
rescheduled_from=None,
328328
base_same_as_master=None,
329329
start_time=None,
@@ -344,8 +344,8 @@ def new_run(
344344
run_args = {
345345
"base_tag": base_tag,
346346
"new_tag": new_tag,
347-
"base_net": base_net,
348-
"new_net": new_net,
347+
"base_nets": base_nets,
348+
"new_nets": new_nets,
349349
"num_games": num_games,
350350
"tc": tc,
351351
"new_tc": new_tc,

server/fishtest/views.py

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -729,35 +729,34 @@ def get_sha(branch, repo_url):
729729
return "", ""
730730

731731

732-
def get_net(commit_sha, repo_url):
733-
"""Get the net from evaluate.h or ucioption.cpp in the repo"""
732+
def get_nets(commit_sha, repo_url):
733+
"""Get the nets from evaluate.h or ucioption.cpp in the repo"""
734734
api_url = repo_url.replace(
735735
"https://github.com", "https://raw.githubusercontent.com"
736736
)
737737
try:
738-
net = None
738+
nets = []
739+
pattern = re.compile("nn-[a-f0-9]{12}.nnue")
739740

740741
url1 = api_url + "/" + commit_sha + "/src/evaluate.h"
741742
options = requests.get(url1).content.decode("utf-8")
742743
for line in options.splitlines():
743744
if "EvalFileDefaultName" in line and "define" in line:
744-
p = re.compile("nn-[a-z0-9]{12}.nnue")
745-
m = p.search(line)
745+
m = pattern.search(line)
746746
if m:
747-
net = m.group(0)
747+
nets.append(m.group(0))
748748

749-
if net:
750-
return net
749+
if nets:
750+
return nets
751751

752752
url2 = api_url + "/" + commit_sha + "/src/ucioption.cpp"
753753
options = requests.get(url2).content.decode("utf-8")
754754
for line in options.splitlines():
755755
if "EvalFile" in line and "Option" in line:
756-
p = re.compile("nn-[a-z0-9]{12}.nnue")
757-
m = p.search(line)
756+
m = pattern.search(line)
758757
if m:
759-
net = m.group(0)
760-
return net
758+
nets.append(m.group(0))
759+
return nets
761760
except:
762761
raise Exception("Unable to access developer repository: " + api_url)
763762

@@ -919,19 +918,29 @@ def strip_message(m):
919918
)
920919
data["base_same_as_master"] = master_diff.text == ""
921920

922-
# Test existence of net
923-
new_net = get_net(data["resolved_new"], data["tests_repo"])
924-
if new_net:
921+
# Test existence of nets
922+
new_nets = get_nets(data["resolved_new"], data["tests_repo"])
923+
missing_nets = []
924+
for new_net in new_nets:
925925
if not request.rundb.get_nn(new_net):
926-
raise Exception(
927-
"The net {}, used by {}, is not "
928-
"known to Fishtest. Please upload it to: "
929-
"{}/upload.".format(new_net, data["new_tag"], request.host_url)
926+
missing_nets.append(new_net)
927+
if missing_nets:
928+
verb, pronoun = ("are", "them") if len(missing_nets) > 1 else ("is", "it")
929+
raise Exception(
930+
"The following net(s): {}, used by {}, {} not "
931+
"known to Fishtest. Please upload {} to: "
932+
"{}/upload.".format(
933+
", ".join(missing_nets),
934+
data["new_tag"],
935+
verb,
936+
pronoun,
937+
request.host_url,
930938
)
939+
)
931940

932-
# Store net info
933-
data["new_net"] = new_net
934-
data["base_net"] = get_net(data["resolved_base"], data["tests_repo"])
941+
# Store nets info
942+
data["new_nets"] = new_nets
943+
data["base_nets"] = get_nets(data["resolved_base"], data["tests_repo"])
935944

936945
# Integer parameters
937946
data["threads"] = int(request.POST["threads"])
@@ -1004,21 +1013,31 @@ def update_nets(request, run):
10041013
run_id = str(run["_id"])
10051014
data = run["args"]
10061015
if run["base_same_as_master"]:
1007-
base_net = data["base_net"]
1008-
if base_net:
1016+
base_nets = data["base_nets"]
1017+
missing_nets = []
1018+
for base_net in base_nets:
10091019
net = request.rundb.get_nn(base_net)
10101020
if not net:
10111021
# Should never happen:
1012-
raise Exception(
1013-
"The net {}, used by {}, is not "
1014-
"known to Fishtest. Please upload it to: "
1015-
"{}/upload.".format(base_net, data["base_tag"], request.host_url)
1016-
)
1017-
if "is_master" not in net:
1022+
missing_nets.append(base_net)
1023+
elif "is_master" not in net:
10181024
net["is_master"] = True
10191025
request.rundb.update_nn(net)
1020-
new_net = data["new_net"]
1021-
if new_net:
1026+
if missing_nets:
1027+
verb, pronoun = ("are", "them") if len(missing_nets) > 1 else ("is", "it")
1028+
raise Exception(
1029+
"The following net(s): {}, used by {}, {} not "
1030+
"known to Fishtest. Please upload {} to: "
1031+
"{}/upload.".format(
1032+
", ".join(missing_nets),
1033+
data["base_tag"],
1034+
verb,
1035+
pronoun,
1036+
request.host_url,
1037+
)
1038+
)
1039+
new_nets = data["new_nets"]
1040+
for new_net in new_nets:
10221041
net = request.rundb.get_nn(new_net)
10231042
if not net:
10241043
return
@@ -1367,11 +1386,13 @@ def tests_view(request):
13671386
"new_options",
13681387
"resolved_new",
13691388
"new_net",
1389+
"new_nets",
13701390
"base_tag",
13711391
"base_signature",
13721392
"base_options",
13731393
"resolved_base",
13741394
"base_net",
1395+
"base_nets",
13751396
"sprt",
13761397
"num_games",
13771398
"spsa",
@@ -1401,6 +1422,9 @@ def tests_view(request):
14011422
if name == "base_tag" and "msg_base" in run["args"]:
14021423
value += " (" + run["args"]["msg_base"][:50] + ")"
14031424

1425+
if name in ("new_nets", "base_nets"):
1426+
value = ", ".join(value)
1427+
14041428
if name == "sprt" and value != "-":
14051429
value = "elo0: {:.2f} alpha: {:.2f} elo1: {:.2f} beta: {:.2f} state: {} ({})".format(
14061430
value["elo0"],

server/tests/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def new_run(self, add_tasks=0):
3939
msg_new="Super stuff",
4040
base_signature="123456",
4141
new_signature="654321",
42-
base_net="nn-0000000000a0.nnue",
43-
new_net="nn-0000000000a0.nnue",
42+
base_nets=["nn-0000000000a0.nnue"],
43+
new_nets=["nn-0000000000a0.nnue", "nn-0000000000a1.nnue"],
4444
rescheduled_from="653db116cc309ae839563103",
4545
base_same_as_master=False,
4646
tests_repo="https://google.com",

server/tests/test_rundb.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def test_10_create_run(self):
7272
msg_new="Super stuff",
7373
base_signature="123456",
7474
new_signature="654321",
75-
base_net="nn-0000000000a0.nnue",
76-
new_net="nn-0000000000a0.nnue",
75+
base_nets=["nn-0000000000a0.nnue"],
76+
new_nets=["nn-0000000000a0.nnue", "nn-0000000000a1.nnue"],
7777
rescheduled_from="653db116cc309ae839563103",
7878
base_same_as_master=False,
7979
tests_repo="https://google.com",
@@ -113,8 +113,8 @@ def test_10_create_run(self):
113113
msg_new="Super stuff",
114114
base_signature="123456",
115115
new_signature="654321",
116-
base_net="nn-0000000000a0.nnue",
117-
new_net="nn-0000000000a0.nnue",
116+
base_nets=["nn-0000000000a0.nnue"],
117+
new_nets=["nn-0000000000a0.nnue", "nn-0000000000a1.nnue"],
118118
rescheduled_from="653db116cc309ae839563103",
119119
base_same_as_master=False,
120120
tests_repo="https://google.com",

0 commit comments

Comments
 (0)