From ec51f0e4a70e15ce079d601d44ca28dbd937772e Mon Sep 17 00:00:00 2001 From: Mark Saroufim Date: Sun, 9 Mar 2025 17:50:14 -0700 Subject: [PATCH 1/5] Add Terms --- .../cogs/leaderboard_cog.py | 11 ++++++++ src/discord-cluster-manager/run_eval.py | 25 +++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/discord-cluster-manager/cogs/leaderboard_cog.py b/src/discord-cluster-manager/cogs/leaderboard_cog.py index e205ba6b..867f56f1 100644 --- a/src/discord-cluster-manager/cogs/leaderboard_cog.py +++ b/src/discord-cluster-manager/cogs/leaderboard_cog.py @@ -347,6 +347,17 @@ async def on_submit_hook( # noqa: C901 return sub_id async def interaction_check(self, interaction: discord.Interaction) -> bool: + # Check if user has the Leaderboard Participant role + participant_role = discord.utils.get(interaction.guild.roles, name="Leaderboard Participant") + if not participant_role or participant_role not in interaction.user.roles: + await interaction.response.send_message( + "You need the **Leaderboard Participant** role to use submit commands. " + "Please go to the #start-here channel and react with a robot emoji to the Carl-Bot message to get the role.", + ephemeral=True, + ) + return False + + # Check if in the correct channel if interaction.channel_id != self.bot.leaderboard_submissions_id: await interaction.response.send_message( f"Submissions are only allowed in <#{self.bot.leaderboard_submissions_id}> channel", diff --git a/src/discord-cluster-manager/run_eval.py b/src/discord-cluster-manager/run_eval.py index c32bc6ee..3658f713 100644 --- a/src/discord-cluster-manager/run_eval.py +++ b/src/discord-cluster-manager/run_eval.py @@ -104,6 +104,7 @@ def compile_cuda_script( # # noqa: C901 libraries: Optional[list[str]] = None, flags: Optional[list[str]] = None, verbose: bool = False, + generate_ptx: bool = False, ) -> CompileResult: """ Compiles a set of cuda files with nvcc. @@ -116,6 +117,7 @@ def compile_cuda_script( # # noqa: C901 libraries: Additional libraries to link to flags: Other compiler flags verbose: whether to print progress or be silent + generate_ptx: whether to compile to PTX instead of binary executable Returns: A `CompileResult` that summarizes the compilation process. @@ -177,7 +179,10 @@ def compile_cuda_script( # # noqa: C901 else: ARCH = f"-gencode=arch=compute_{arch},code=sm_{arch}" - command = [nvcc] + flags + files + [ARCH, "-o", "eval.out"] + if generate_ptx: + command = [nvcc] + flags + ["-ptx"] + files + [ARCH, "-o", "eval.ptx"] + else: + command = [nvcc] + flags + files + [ARCH, "-o", "eval.out"] print_("[Compiling]") try: @@ -301,6 +306,7 @@ def run_cuda_script( # # noqa: C901 include_dirs: Optional[list[str]] = None, libraries: Optional[list[str]] = None, flags: Optional[list[str]] = None, + generate_ptx: bool = False, **kwargs, ) -> EvalResult: """ @@ -316,6 +322,7 @@ def run_cuda_script( # # noqa: C901 defines: Preprocessor defines libraries: Additional libraries to link to flags: Additional flags to give to the compiler + generate_ptx: whether to compile to PTX instead of binary executable seed: Random seed to initialize the RNG for testing Returns: @@ -335,6 +342,7 @@ def run_cuda_script( # # noqa: C901 libraries=libraries, flags=flags, verbose=True, + generate_ptx=generate_ptx, ) if not compile_result.success: @@ -350,10 +358,16 @@ def run_cuda_script( # # noqa: C901 if os.path.exists(f): os.remove(f) - run_result = run_single_evaluation(["./eval.out"], **kwargs) - return EvalResult( - start=start, end=datetime.datetime.now(), compilation=compile_result, run=run_result - ) + if generate_ptx: + # When generating PTX, we don't execute the code + return EvalResult( + start=start, end=datetime.datetime.now(), compilation=compile_result, run=None + ) + else: + run_result = run_single_evaluation(["./eval.out"], **kwargs) + return EvalResult( + start=start, end=datetime.datetime.now(), compilation=compile_result, run=run_result + ) def run_pytorch_script( # noqa: C901 @@ -492,6 +506,7 @@ def run_config(config: dict): include_dirs=config.get("include_dirs", []), libraries=config.get("libraries", []), flags=CUDA_FLAGS, + generate_ptx=config.get("generate_ptx", False), **common_args, ) else: From c79cc8df27ca14626a1f2bd23119dc32c2597281 Mon Sep 17 00:00:00 2001 From: Mark Saroufim Date: Sun, 9 Mar 2025 17:51:45 -0700 Subject: [PATCH 2/5] revert --- src/discord-cluster-manager/run_eval.py | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/discord-cluster-manager/run_eval.py b/src/discord-cluster-manager/run_eval.py index 3658f713..c32bc6ee 100644 --- a/src/discord-cluster-manager/run_eval.py +++ b/src/discord-cluster-manager/run_eval.py @@ -104,7 +104,6 @@ def compile_cuda_script( # # noqa: C901 libraries: Optional[list[str]] = None, flags: Optional[list[str]] = None, verbose: bool = False, - generate_ptx: bool = False, ) -> CompileResult: """ Compiles a set of cuda files with nvcc. @@ -117,7 +116,6 @@ def compile_cuda_script( # # noqa: C901 libraries: Additional libraries to link to flags: Other compiler flags verbose: whether to print progress or be silent - generate_ptx: whether to compile to PTX instead of binary executable Returns: A `CompileResult` that summarizes the compilation process. @@ -179,10 +177,7 @@ def compile_cuda_script( # # noqa: C901 else: ARCH = f"-gencode=arch=compute_{arch},code=sm_{arch}" - if generate_ptx: - command = [nvcc] + flags + ["-ptx"] + files + [ARCH, "-o", "eval.ptx"] - else: - command = [nvcc] + flags + files + [ARCH, "-o", "eval.out"] + command = [nvcc] + flags + files + [ARCH, "-o", "eval.out"] print_("[Compiling]") try: @@ -306,7 +301,6 @@ def run_cuda_script( # # noqa: C901 include_dirs: Optional[list[str]] = None, libraries: Optional[list[str]] = None, flags: Optional[list[str]] = None, - generate_ptx: bool = False, **kwargs, ) -> EvalResult: """ @@ -322,7 +316,6 @@ def run_cuda_script( # # noqa: C901 defines: Preprocessor defines libraries: Additional libraries to link to flags: Additional flags to give to the compiler - generate_ptx: whether to compile to PTX instead of binary executable seed: Random seed to initialize the RNG for testing Returns: @@ -342,7 +335,6 @@ def run_cuda_script( # # noqa: C901 libraries=libraries, flags=flags, verbose=True, - generate_ptx=generate_ptx, ) if not compile_result.success: @@ -358,16 +350,10 @@ def run_cuda_script( # # noqa: C901 if os.path.exists(f): os.remove(f) - if generate_ptx: - # When generating PTX, we don't execute the code - return EvalResult( - start=start, end=datetime.datetime.now(), compilation=compile_result, run=None - ) - else: - run_result = run_single_evaluation(["./eval.out"], **kwargs) - return EvalResult( - start=start, end=datetime.datetime.now(), compilation=compile_result, run=run_result - ) + run_result = run_single_evaluation(["./eval.out"], **kwargs) + return EvalResult( + start=start, end=datetime.datetime.now(), compilation=compile_result, run=run_result + ) def run_pytorch_script( # noqa: C901 @@ -506,7 +492,6 @@ def run_config(config: dict): include_dirs=config.get("include_dirs", []), libraries=config.get("libraries", []), flags=CUDA_FLAGS, - generate_ptx=config.get("generate_ptx", False), **common_args, ) else: From 071a4eb4fc4e923bf8c26e1f7eefd9130b23c247 Mon Sep 17 00:00:00 2001 From: Mark Saroufim Date: Sun, 9 Mar 2025 17:58:37 -0700 Subject: [PATCH 3/5] update --- .../cogs/leaderboard_cog.py | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/discord-cluster-manager/cogs/leaderboard_cog.py b/src/discord-cluster-manager/cogs/leaderboard_cog.py index 867f56f1..e74e4521 100644 --- a/src/discord-cluster-manager/cogs/leaderboard_cog.py +++ b/src/discord-cluster-manager/cogs/leaderboard_cog.py @@ -347,24 +347,20 @@ async def on_submit_hook( # noqa: C901 return sub_id async def interaction_check(self, interaction: discord.Interaction) -> bool: - # Check if user has the Leaderboard Participant role - participant_role = discord.utils.get(interaction.guild.roles, name="Leaderboard Participant") - if not participant_role or participant_role not in interaction.user.roles: - await interaction.response.send_message( - "You need the **Leaderboard Participant** role to use submit commands. " - "Please go to the #start-here channel and react with a robot emoji to the Carl-Bot message to get the role.", - ephemeral=True, - ) - return False - - # Check if in the correct channel - if interaction.channel_id != self.bot.leaderboard_submissions_id: - await interaction.response.send_message( - f"Submissions are only allowed in <#{self.bot.leaderboard_submissions_id}> channel", - ephemeral=True, - ) - return False - return True + allowed_roles = ["Leaderboard Participant", "Leaderboard Creator", "Leaderboard Admin"] + + for role_name in allowed_roles: + role = discord.utils.get(interaction.guild.roles, name=role_name) + if role and role in interaction.user.roles: + return True + + await interaction.response.send_message( + "You need the **Leaderboard Participant** role to use these commands. " + "Please go to the #start-here channel and react with a " + "robot emoji to the Carl-Bot message to get the role.", + ephemeral=True, + ) + return False async def submit( self, From 089615102094ab1f7e24bd1c08d7eb5e156875fc Mon Sep 17 00:00:00 2001 From: Mark Saroufim Date: Sun, 9 Mar 2025 18:14:23 -0700 Subject: [PATCH 4/5] Only allow interaction if using rank --- .../cogs/leaderboard_cog.py | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/discord-cluster-manager/cogs/leaderboard_cog.py b/src/discord-cluster-manager/cogs/leaderboard_cog.py index e74e4521..52b62da4 100644 --- a/src/discord-cluster-manager/cogs/leaderboard_cog.py +++ b/src/discord-cluster-manager/cogs/leaderboard_cog.py @@ -347,20 +347,25 @@ async def on_submit_hook( # noqa: C901 return sub_id async def interaction_check(self, interaction: discord.Interaction) -> bool: - allowed_roles = ["Leaderboard Participant", "Leaderboard Creator", "Leaderboard Admin"] - - for role_name in allowed_roles: - role = discord.utils.get(interaction.guild.roles, name=role_name) - if role and role in interaction.user.roles: - return True - - await interaction.response.send_message( - "You need the **Leaderboard Participant** role to use these commands. " - "Please go to the #start-here channel and react with a " - "robot emoji to the Carl-Bot message to get the role.", - ephemeral=True, - ) - return False + # Only check for role if the command is the ranked submission command + if interaction.command and interaction.command.name == "ranked": + allowed_roles = ["Leaderboard Participant", "Leaderboard Creator", "Leaderboard Admin"] + + for role_name in allowed_roles: + role = discord.utils.get(interaction.guild.roles, name=role_name) + if role and role in interaction.user.roles: + return True + + await interaction.response.send_message( + "You need the **Leaderboard Participant** role to make ranked submissions. " + "Please go to the #start-here channel and react with a " + "robot emoji to the Carl-Bot message to get the role.", + ephemeral=True, + ) + return False + + # Allow all other commands without role check + return True async def submit( self, From 15b8534e8390f8d9395f4d1350340f70ed4c5bbb Mon Sep 17 00:00:00 2001 From: Mark Saroufim Date: Sun, 9 Mar 2025 18:16:04 -0700 Subject: [PATCH 5/5] update --- src/discord-cluster-manager/cogs/leaderboard_cog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/discord-cluster-manager/cogs/leaderboard_cog.py b/src/discord-cluster-manager/cogs/leaderboard_cog.py index 52b62da4..f4b9d4df 100644 --- a/src/discord-cluster-manager/cogs/leaderboard_cog.py +++ b/src/discord-cluster-manager/cogs/leaderboard_cog.py @@ -363,7 +363,7 @@ async def interaction_check(self, interaction: discord.Interaction) -> bool: ephemeral=True, ) return False - + # Allow all other commands without role check return True