From 86a9f104928eec36bfa5f38a372425d533104d64 Mon Sep 17 00:00:00 2001 From: Ben Horowitz Date: Thu, 26 Dec 2024 12:57:13 -0800 Subject: [PATCH 1/2] adds gpu_type column to submission table --- .../cogs/leaderboard_cog.py | 4 ++++ src/discord-cluster-manager/leaderboard_db.py | 9 ++++++-- ...226_01_ZQSOK-add_gpu_type_to_submission.py | 21 +++++++++++++++++++ src/discord-cluster-manager/utils.py | 11 ++++------ 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 src/discord-cluster-manager/migrations/20241226_01_ZQSOK-add_gpu_type_to_submission.py diff --git a/src/discord-cluster-manager/cogs/leaderboard_cog.py b/src/discord-cluster-manager/cogs/leaderboard_cog.py index 665da77..ba6b80d 100644 --- a/src/discord-cluster-manager/cogs/leaderboard_cog.py +++ b/src/discord-cluster-manager/cogs/leaderboard_cog.py @@ -75,6 +75,7 @@ async def submit_modal( "code": submission_content, "user_id": interaction.user.id, "submission_score": score, + "gpu_type": gpu_type.name, } ) @@ -179,6 +180,8 @@ async def submit_github( "code": submission_content, "user_id": interaction.user.id, "submission_score": score, + # TODO: Change this to multiple GPUs (see above) + "gpu_type": "nvidia", } ) @@ -420,6 +423,7 @@ async def get_leaderboard_submissions( self, interaction: discord.Interaction, leaderboard_name: str, + # TODO add GPU type ): try: with self.bot.leaderboard_db as db: diff --git a/src/discord-cluster-manager/leaderboard_db.py b/src/discord-cluster-manager/leaderboard_db.py index 0da899e..3a58b03 100644 --- a/src/discord-cluster-manager/leaderboard_db.py +++ b/src/discord-cluster-manager/leaderboard_db.py @@ -132,10 +132,11 @@ def create_submission(self, submission: SubmissionItem): self.cursor.execute( """ INSERT INTO leaderboard.submission (leaderboard_id, name, - user_id, code, submission_time, score) + user_id, code, submission_time, score, gpu_type, stdout, + profiler_output) VALUES ( (SELECT id FROM leaderboard.leaderboard WHERE name = %s), - %s, %s, %s, %s, %s) + %s, %s, %s, %s, %s, %s, %s, %s) """, ( submission["leaderboard_name"], @@ -144,6 +145,9 @@ def create_submission(self, submission: SubmissionItem): submission["code"], submission["submission_time"], submission["submission_score"], + submission["gpu_type"], + submission.get("stdout", None), + submission.get("profiler_output", None), ), ) self.connection.commit() @@ -193,6 +197,7 @@ def get_leaderboard(self, leaderboard_name: str) -> int | None: else: return None + # TODO: add GPU type def get_leaderboard_submissions(self, leaderboard_name: str) -> list[SubmissionItem]: self.cursor.execute( """ diff --git a/src/discord-cluster-manager/migrations/20241226_01_ZQSOK-add_gpu_type_to_submission.py b/src/discord-cluster-manager/migrations/20241226_01_ZQSOK-add_gpu_type_to_submission.py new file mode 100644 index 0000000..a5e9ef2 --- /dev/null +++ b/src/discord-cluster-manager/migrations/20241226_01_ZQSOK-add_gpu_type_to_submission.py @@ -0,0 +1,21 @@ +""" +This migration adds a score column to runinfo, and drops the score column in +submission. +""" + +from yoyo import step + +__depends__ = {'20241224_01_Pg4FX-delete-cascade'} + +steps = [ + step("DROP TABLE leaderboard.runinfo"), + + step(""" + ALTER TABLE leaderboard.submission + ADD COLUMN gpu_type TEXT NOT NULL DEFAULT 'nvidia' + """), + + step("ALTER TABLE leaderboard.submission ADD COLUMN stdout TEXT"), + + step("ALTER TABLE leaderboard.submission ADD COLUMN profiler_output TEXT"), +] diff --git a/src/discord-cluster-manager/utils.py b/src/discord-cluster-manager/utils.py index 6b506cd..85e0643 100644 --- a/src/discord-cluster-manager/utils.py +++ b/src/discord-cluster-manager/utils.py @@ -2,7 +2,7 @@ import logging import re import subprocess -from typing import Any, List, TypedDict +from typing import Any, List, NotRequired, TypedDict import discord @@ -143,9 +143,6 @@ class SubmissionItem(TypedDict): leaderboard_name: str code: str user_id: int - - -class ProfilingItem(TypedDict): - submission_name: str - ncu_output: str - stdout: str + gpu_type: str + stdout: NotRequired[str] + profiler_output: NotRequired[str] \ No newline at end of file From 5c5f0c63e225460c17cb56accf0d573feddb5bbd Mon Sep 17 00:00:00 2001 From: Ben Horowitz Date: Thu, 26 Dec 2024 13:05:08 -0800 Subject: [PATCH 2/2] changes to make ruff happy --- src/discord-cluster-manager/cogs/leaderboard_cog.py | 2 +- src/discord-cluster-manager/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/discord-cluster-manager/cogs/leaderboard_cog.py b/src/discord-cluster-manager/cogs/leaderboard_cog.py index ba6b80d..444f2da 100644 --- a/src/discord-cluster-manager/cogs/leaderboard_cog.py +++ b/src/discord-cluster-manager/cogs/leaderboard_cog.py @@ -181,7 +181,7 @@ async def submit_github( "user_id": interaction.user.id, "submission_score": score, # TODO: Change this to multiple GPUs (see above) - "gpu_type": "nvidia", + "gpu_type": "nvidia", } ) diff --git a/src/discord-cluster-manager/utils.py b/src/discord-cluster-manager/utils.py index 85e0643..ada4e0c 100644 --- a/src/discord-cluster-manager/utils.py +++ b/src/discord-cluster-manager/utils.py @@ -145,4 +145,4 @@ class SubmissionItem(TypedDict): user_id: int gpu_type: str stdout: NotRequired[str] - profiler_output: NotRequired[str] \ No newline at end of file + profiler_output: NotRequired[str]