Skip to content

Commit 7d7a96e

Browse files
committed
secret seeds in database
1 parent 7a04804 commit 7d7a96e

6 files changed

Lines changed: 54 additions & 26 deletions

File tree

src/discord-cluster-manager/cogs/leaderboard_cog.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import copy
23
from datetime import datetime, timedelta
34
from io import StringIO
45
from typing import TYPE_CHECKING, Callable, List, Optional
@@ -46,12 +47,20 @@ async def async_submit_cog_job(
4647
script: discord.Attachment,
4748
command: Callable,
4849
task: LeaderboardTask,
50+
seed: Optional[int],
4951
reporter: RunProgressReporter,
5052
gpu: app_commands.Choice[str],
5153
runner_name: str,
5254
mode: SubmissionMode,
5355
submission_id: int,
5456
):
57+
if seed is not None:
58+
# careful, we've got a reference here
59+
# that is shared with the other run
60+
# invocations.
61+
task = copy.copy(task)
62+
task.seed = seed
63+
5564
result: FullResult = await command(
5665
interaction,
5766
script,
@@ -152,8 +161,8 @@ async def before_submit_hook(
152161
return None, None
153162

154163
gpus = db.get_leaderboard_gpu_types(leaderboard_name)
155-
task = leaderboard_item["task"]
156-
return task, gpus
164+
task: LeaderboardTask = leaderboard_item["task"]
165+
return task, gpus, leaderboard_item['secret_seed']
157166

158167
def _get_run_command(self, gpu) -> Optional[Callable]:
159168
runner_cog = self.bot.get_cog(f"{gpu.runner}Cog")
@@ -230,7 +239,7 @@ async def on_submit_hook( # noqa: C901
230239
)
231240
return -1
232241

233-
task, task_gpus = await self.before_submit_hook(
242+
task, task_gpus, secret_seed = await self.before_submit_hook(
234243
interaction,
235244
leaderboard_name,
236245
)
@@ -297,6 +306,7 @@ async def on_submit_hook( # noqa: C901
297306
script,
298307
command,
299308
task,
309+
None,
300310
reporter.add_run(f"{gpu.name} on {gpu.runner}"),
301311
app_commands.Choice(name=gpu.name, value=gpu.value),
302312
gpu.runner,
@@ -315,6 +325,7 @@ async def on_submit_hook( # noqa: C901
315325
script,
316326
command,
317327
task,
328+
secret_seed,
318329
reporter.add_run(f"{gpu.name} on {gpu.runner} (secret)"),
319330
app_commands.Choice(name=gpu.name, value=gpu.value),
320331
gpu.runner,

src/discord-cluster-manager/leaderboard_db.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def get_leaderboard_gpu_types(self, leaderboard_name: str) -> List[str] | None:
418418
def get_leaderboard(self, leaderboard_name: str) -> LeaderboardItem | None:
419419
self.cursor.execute(
420420
"""
421-
SELECT id, name, deadline, task, creator_id, forum_id
421+
SELECT id, name, deadline, task, creator_id, forum_id, secret_seed
422422
FROM leaderboard.leaderboard
423423
WHERE name = %s
424424
""",
@@ -436,6 +436,7 @@ def get_leaderboard(self, leaderboard_name: str) -> LeaderboardItem | None:
436436
task=task,
437437
creator_id=res[4],
438438
forum_id=res[5],
439+
secret_seed=res[6],
439440
)
440441
else:
441442
return None
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
Add a secret seed column.
3+
Note: double epsilon is eps=2.22e-16, so 1/eps = 4504504504504504 >> 2^31 = 2147483648,
4+
so we should get reasonably uniform integers here
5+
"""
6+
7+
from yoyo import step
8+
9+
__depends__ = {"20250316_01_5oMi3-remember-forum-id"}
10+
11+
steps = [
12+
step(
13+
"ALTER TABLE leaderboard.leaderboard ADD COLUMN secret_seed BIGINT NOT NULL "
14+
"DEFAULT FLOOR(RANDOM() * 2147483648) ",
15+
),
16+
]

src/discord-cluster-manager/run_eval.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,14 @@ def compile_cuda_script( # # noqa: C901
217217
)
218218

219219

220-
def run_program(args: list[str], seed: int, timeout: int) -> RunResult:
220+
def run_program(args: list[str], seed: Optional[int], timeout: int) -> RunResult:
221221
print("[Running]")
222222
# set up a pipe so the tester can communicate its verdict with us
223223
env = os.environ.copy()
224224
pipe_read, pipe_write = os.pipe()
225225
env["POPCORN_FD"] = str(pipe_write)
226-
env["POPCORN_SEED"] = str(seed)
226+
if seed is not None:
227+
env["POPCORN_SEED"] = str(seed)
227228

228229
execution_start_time = time.perf_counter()
229230
try:
@@ -283,7 +284,7 @@ def run_single_evaluation(
283284
test_timeout: int = Timeout.TEST,
284285
benchmark_timeout: int = Timeout.BENCHMARK,
285286
ranked_timeout: int = Timeout.RANKED,
286-
seed: Optional[int] = 42,
287+
seed: Optional[int] = None,
287288
) -> RunResult:
288289
"""
289290
A single runner run, either in the context of test files, or in the
@@ -542,7 +543,7 @@ def run_config(config: dict):
542543
common_args = {
543544
"tests": build_test_string(config.get("tests", [])),
544545
"benchmarks": build_test_string(config.get("benchmarks", [])),
545-
"seed": 42,
546+
"seed": config.get("seed", None),
546547
}
547548
if config["lang"] == "py":
548549
runner = functools.partial(

src/discord-cluster-manager/task.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import dataclasses
33
import json
44
from pathlib import Path
5-
from typing import Dict, Union
5+
from typing import Dict, Optional, Union
66

77
from consts import Language
88

@@ -60,6 +60,7 @@ class LeaderboardTask:
6060
benchmark_timeout: int = 60
6161
ranked_timeout: int = 90
6262
templates: dict[str, str] = dataclasses.field(default_factory=dict)
63+
seed: Optional[int] = None
6364

6465
@staticmethod
6566
def from_dict(data: dict):

src/discord-cluster-manager/utils.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import functools
33
import logging
44
import subprocess
5-
from typing import Any, List, Optional, TypedDict
5+
from typing import Any, List, NotRequired, Optional, TypedDict
66

77
import discord
88
from consts import Language, SubmissionMode
@@ -191,6 +191,7 @@ class LeaderboardItem(TypedDict):
191191
task: LeaderboardTask
192192
gpu_types: List[str]
193193
forum_id: int
194+
secret_seed: NotRequired[int]
194195

195196

196197
class LeaderboardRankedEntry(TypedDict):
@@ -266,18 +267,23 @@ def build_task_config(
266267
else:
267268
all_files[n] = c
268269

270+
common = {
271+
"lang": task.lang.value,
272+
"arch": arch,
273+
"benchmarks": task.benchmarks,
274+
"tests": task.tests,
275+
"mode": mode.value,
276+
"test_timeout": task.test_timeout,
277+
"benchmark_timeout": task.benchmark_timeout,
278+
"ranked_timeout": task.ranked_timeout,
279+
"seed": task.seed,
280+
}
281+
269282
if task.lang == Language.Python:
270283
return {
271-
"lang": task.lang.value,
272-
"arch": arch,
273284
"main": task.config.main,
274285
"sources": all_files,
275-
"benchmarks": task.benchmarks,
276-
"tests": task.tests,
277-
"mode": mode.value,
278-
"test_timeout": task.test_timeout,
279-
"benchmark_timeout": task.benchmark_timeout,
280-
"ranked_timeout": task.ranked_timeout,
286+
**common
281287
}
282288
else:
283289
sources = {}
@@ -289,17 +295,9 @@ def build_task_config(
289295
headers[f] = all_files[f]
290296

291297
return {
292-
"lang": task.lang.value,
293-
"arch": arch,
294298
"sources": sources,
295299
"headers": headers,
296-
"tests": task.tests,
297-
"benchmarks": task.benchmarks,
298300
"include_dirs": task.config.include_dirs,
299-
"mode": mode.value,
300-
"test_timeout": task.test_timeout,
301-
"benchmark_timeout": task.benchmark_timeout,
302-
"ranked_timeout": task.ranked_timeout,
303301
}
304302

305303

0 commit comments

Comments
 (0)