|
1 | | -import asyncio |
2 | 1 | from datetime import datetime, timedelta |
3 | 2 | from io import StringIO |
4 | 3 | from typing import TYPE_CHECKING, List, Optional |
5 | 4 |
|
6 | 5 | import discord |
7 | 6 | from consts import ( |
8 | 7 | SubmissionMode, |
9 | | - get_gpu_by_name, |
10 | 8 | ) |
11 | 9 | from discord import app_commands |
12 | 10 | from discord.ext import commands |
13 | | -from discord_reporter import MultiProgressReporter |
| 11 | +from discord_reporter import MultiProgressReporterDiscord |
14 | 12 | from discord_utils import ( |
15 | 13 | get_user_from_id, |
16 | 14 | leaderboard_name_autocomplete, |
@@ -85,79 +83,25 @@ async def on_submit_hook( # noqa: C901 |
85 | 83 | ) |
86 | 84 | return -1 |
87 | 85 |
|
| 86 | + if not interaction.response.is_done(): |
| 87 | + await interaction.response.defer(ephemeral=True) |
| 88 | + |
88 | 89 | req = SubmissionRequest( |
89 | 90 | code=submission_content, |
90 | 91 | file_name=script.filename, |
91 | 92 | user_id=interaction.user.id, |
| 93 | + user_name=interaction.user.global_name or interaction.user.name, |
92 | 94 | gpus=cmd_gpus, |
93 | 95 | leaderboard=leaderboard_name, |
94 | 96 | ) |
95 | 97 | req = prepare_submission(req, self.bot.leaderboard_db) |
96 | 98 |
|
97 | | - # if there is more than one candidate GPU, display UI to let user select, |
98 | | - # otherwise just run on that GPU |
99 | | - if not interaction.response.is_done(): |
100 | | - await interaction.response.defer(ephemeral=True) |
101 | | - |
102 | 99 | if req.gpus is None: |
103 | 100 | view = await self.select_gpu_view(interaction, leaderboard_name, req.task_gpus) |
104 | | - selected_gpus = view.selected_gpus |
105 | | - else: |
106 | | - selected_gpus = req.gpus |
107 | | - |
108 | | - selected_gpus = [get_gpu_by_name(gpu) for gpu in selected_gpus] |
| 101 | + req.gpus = view.selected_gpus |
109 | 102 |
|
110 | | - command = self.bot.backend.submit_leaderboard |
111 | | - |
112 | | - user_name = interaction.user.global_name or interaction.user.name |
113 | | - # Create a submission entry in the database |
114 | | - with self.bot.leaderboard_db as db: |
115 | | - sub_id = db.create_submission( |
116 | | - leaderboard=req.leaderboard, |
117 | | - file_name=script.filename, |
118 | | - code=submission_content, |
119 | | - user_id=interaction.user.id, |
120 | | - time=datetime.now(), |
121 | | - user_name=user_name, |
122 | | - ) |
123 | | - |
124 | | - run_msg = f"Submission **{sub_id}**: `{script.filename}` for `{req.leaderboard}`" |
125 | | - reporter = MultiProgressReporter(interaction, run_msg) |
126 | | - try: |
127 | | - tasks = [ |
128 | | - command( |
129 | | - sub_id, |
130 | | - submission_content, |
131 | | - script.filename, |
132 | | - gpu, |
133 | | - reporter.add_run(f"{gpu.name} on {gpu.runner}"), |
134 | | - req.task, |
135 | | - mode, |
136 | | - None, |
137 | | - ) |
138 | | - for gpu in selected_gpus |
139 | | - ] |
140 | | - |
141 | | - # also schedule secret run |
142 | | - if mode == SubmissionMode.LEADERBOARD: |
143 | | - tasks += [ |
144 | | - command( |
145 | | - sub_id, |
146 | | - submission_content, |
147 | | - script.filename, |
148 | | - gpu, |
149 | | - reporter.add_run(f"{gpu.name} on {gpu.runner} (secret)"), |
150 | | - req.task, |
151 | | - SubmissionMode.PRIVATE, |
152 | | - req.secret_seed, |
153 | | - ) |
154 | | - for gpu in selected_gpus |
155 | | - ] |
156 | | - await reporter.show() |
157 | | - await asyncio.gather(*tasks) |
158 | | - finally: |
159 | | - with self.bot.leaderboard_db as db: |
160 | | - db.mark_submission_done(sub_id) |
| 103 | + reporter = MultiProgressReporterDiscord(interaction) |
| 104 | + sub_id, results = await self.bot.backend.submit_full(req, mode, reporter) |
161 | 105 |
|
162 | 106 | if mode == SubmissionMode.LEADERBOARD: |
163 | 107 | await self.post_submit_hook(interaction, sub_id) |
|
0 commit comments