|
14 | 14 | from tqdm import tqdm |
15 | 15 |
|
16 | 16 | from dstack import version |
17 | | -from dstack.core.job import Job, JobStatus, Requirements |
| 17 | +from dstack.core.job import Job |
18 | 18 | from dstack.core.request import RequestHead, RequestStatus |
19 | 19 | from dstack.core.runners import Gpu, Resources, Runner |
20 | 20 |
|
21 | | -CREATE_INSTANCE_RETRY_RATE_SECS = 3 |
22 | | - |
23 | | - |
24 | | -def _matches(resources: Resources, requirements: Optional[Requirements]) -> bool: |
25 | | - if not requirements: |
26 | | - return True |
27 | | - if requirements.cpus and requirements.cpus > resources.cpus: |
28 | | - return False |
29 | | - if requirements.memory_mib and requirements.memory_mib > resources.memory_mib: |
30 | | - return False |
31 | | - if requirements.gpus: |
32 | | - gpu_count = requirements.gpus.count or 1 |
33 | | - if gpu_count > len(resources.gpus or []): |
34 | | - return False |
35 | | - if requirements.gpus.name and gpu_count > len( |
36 | | - list(filter(lambda gpu: gpu.name == requirements.gpus.name, resources.gpus or [])) |
37 | | - ): |
38 | | - return False |
39 | | - if requirements.gpus.memory_mib and gpu_count > len( |
40 | | - list( |
41 | | - filter( |
42 | | - lambda gpu: gpu.memory_mib >= requirements.gpus.memory_mib, |
43 | | - resources.gpus or [], |
44 | | - ) |
45 | | - ) |
46 | | - ): |
47 | | - return False |
48 | | - if requirements.interruptible and not resources.interruptible: |
49 | | - return False |
50 | | - return True |
51 | | - |
52 | 21 |
|
53 | 22 | def start_runner_process(runner_id: str) -> str: |
54 | 23 | _install_runner_if_necessary() |
@@ -114,14 +83,15 @@ def _install_runner_if_necessary(): |
114 | 83 | _download_runner(_runner_url(), runner_path) |
115 | 84 |
|
116 | 85 |
|
117 | | -def _download_runner(url: str, path: str): |
| 86 | +def _download_runner(url: str, path: Path): |
| 87 | + runner_download_path = path.parent / "runner-download" |
118 | 88 | with requests.get(url, stream=True) as r: |
119 | 89 | total_length = int(r.headers.get("Content-Length")) |
120 | | - |
121 | 90 | with tqdm.wrapattr(r.raw, "read", total=total_length, desc=f"Downloading runner") as raw: |
122 | | - with open(path, "wb") as output: |
| 91 | + with open(runner_download_path, "wb") as output: |
123 | 92 | shutil.copyfileobj(raw, output) |
124 | | - os.chmod(path, 0o755) |
| 93 | + shutil.move(runner_download_path, path) |
| 94 | + os.chmod(path, 0o755) |
125 | 95 |
|
126 | 96 |
|
127 | 97 | def _runner_url() -> str: |
|
0 commit comments