Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/libkernelbot/launchers/modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def __init__(self, add_include_dirs: list):
async def run_submission(
self, config: dict, gpu_type: GPU, status: RunProgressReporter
) -> FullResult:
loop = asyncio.get_event_loop()
if config["lang"] == "cu":
config["include_dirs"] = config.get("include_dirs", []) + self.additional_include_dirs
func_name = self._function_name(config, gpu_type)
Expand All @@ -29,10 +28,8 @@ async def run_submission(

await status.push("⏳ Waiting for Modal run to finish...")

result = await loop.run_in_executor(
None,
lambda: modal.Function.from_name("discord-bot-runner", func_name).remote(config=config),
)
function = modal.Function.from_name("discord-bot-runner", func_name)
result = await function.remote.aio(config=config)

await status.update("✅ Waiting for modal run to finish... Done")

Expand Down
22 changes: 21 additions & 1 deletion tests/test_modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from types import SimpleNamespace
from typing import Tuple
from unittest.mock import MagicMock, patch
from unittest.mock import AsyncMock, MagicMock, patch

import pytest

Expand All @@ -29,6 +29,26 @@ async def update(self, message: str):
self.updates.append(message)


@pytest.mark.asyncio
async def test_modal_submission_uses_native_async_api():
launcher = ModalLauncher(add_include_dirs=["/extra/include"])
reporter = MockProgressReporter()
function = MagicMock()
expected = object()
function.remote.aio = AsyncMock(return_value=expected)
config = {"lang": "cu"}

with patch("libkernelbot.launchers.modal.modal.Function.from_name", return_value=function):
result = await launcher.run_submission(config, get_gpu_by_name("B200"), reporter)

assert result is expected
assert config["include_dirs"] == ["/extra/include"]
function.remote.aio.assert_awaited_once_with(config=config)
function.remote.assert_not_called()
assert reporter.messages == ["⏳ Waiting for Modal run to finish..."]
assert reporter.updates == ["✅ Waiting for modal run to finish... Done"]


@pytest.mark.asyncio
async def test_modal_queue_status_uses_function_stats():
launcher = ModalLauncher(add_include_dirs=[])
Expand Down
Loading