|
| 1 | +# Generic launcher POSTs to a specific URL |
| 2 | +import asyncio |
| 3 | +import datetime |
| 4 | +import json |
| 5 | + |
| 6 | +import requests |
| 7 | + |
| 8 | +from consts import GPU, OtherGPU |
| 9 | +from report import RunProgressReporter |
| 10 | +from run_eval import FullResult, CompileResult, RunResult, EvalResult, SystemInfo |
| 11 | +from utils import setup_logging, KernelBotError |
| 12 | + |
| 13 | +from .launcher import Launcher |
| 14 | + |
| 15 | +logger = setup_logging(__name__) |
| 16 | + |
| 17 | + |
| 18 | +class GenericLauncher(Launcher): |
| 19 | + def __init__(self, url: str, token: str): |
| 20 | + super().__init__("Generic", gpus=OtherGPU) |
| 21 | + self.url = url |
| 22 | + self.token = token |
| 23 | + |
| 24 | + async def run_submission( |
| 25 | + self, config: dict, gpu_type: GPU, status: RunProgressReporter |
| 26 | + ) -> FullResult: |
| 27 | + loop = asyncio.get_event_loop() |
| 28 | + logger.info(f"Calling {self.url}") |
| 29 | + |
| 30 | + await status.push("⏳ Waiting for run to finish...") |
| 31 | + result = await loop.run_in_executor( |
| 32 | + None, |
| 33 | + lambda: requests.post(self.url, json={"config": config, "token": self.token}) |
| 34 | + ) |
| 35 | + |
| 36 | + print(result.text) |
| 37 | + |
| 38 | + await status.update("✅ Waiting for run to finish... Done") |
| 39 | + if result.status_code != 200: |
| 40 | + logger.error("Error running submission. Status code %d, Message: %s", result.status_code, result.text) |
| 41 | + raise KernelBotError(f"Error running submission. Status code {result.status_code}") |
| 42 | + |
| 43 | + # TODO: this code is duplicated :( |
| 44 | + data = result.json() |
| 45 | + runs = {} |
| 46 | + # convert json back to EvalResult structures, which requires |
| 47 | + # special handling for datetime and our dataclasses. |
| 48 | + for k, v in data["runs"].items(): |
| 49 | + if "compilation" in v and v["compilation"] is not None: |
| 50 | + comp = CompileResult(**v["compilation"]) |
| 51 | + else: |
| 52 | + comp = None |
| 53 | + run = RunResult(**v["run"]) |
| 54 | + res = EvalResult( |
| 55 | + start=datetime.datetime.fromisoformat(v["start"]), |
| 56 | + end=datetime.datetime.fromisoformat(v["end"]), |
| 57 | + compilation=comp, |
| 58 | + run=run, |
| 59 | + ) |
| 60 | + runs[k] = res |
| 61 | + |
| 62 | + system = SystemInfo(**data.get("system", {})) |
| 63 | + return FullResult(success=True, error="", runs=runs, system=system) |
0 commit comments