mimiry 0.2.2__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mimiry-0.2.2 → mimiry-0.2.3}/PKG-INFO +1 -1
- {mimiry-0.2.2 → mimiry-0.2.3}/pyproject.toml +1 -1
- {mimiry-0.2.2 → mimiry-0.2.3}/src/Mimiry.egg-info/PKG-INFO +1 -1
- {mimiry-0.2.2 → mimiry-0.2.3}/src/Mimiry.egg-info/SOURCES.txt +4 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/__init__.py +1 -1
- mimiry-0.2.3/src/mimiry/_availability.py +96 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/_serialization.py +8 -2
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/_session.py +50 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/function.py +11 -2
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/image.py +9 -1
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/run.py +14 -2
- mimiry-0.2.3/tests/test_availability.py +114 -0
- mimiry-0.2.3/tests/test_bootstrap.py +54 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/tests/test_config.py +0 -1
- mimiry-0.2.3/tests/test_session.py +61 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/README.md +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/setup.cfg +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/Mimiry.egg-info/dependency_links.txt +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/Mimiry.egg-info/entry_points.txt +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/Mimiry.egg-info/requires.txt +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/Mimiry.egg-info/top_level.txt +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/__main__.py +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/_auth.py +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/_cli.py +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/_client.py +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/_config.py +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/_setup.py +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/_ssh.py +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/src/mimiry/exceptions.py +0 -0
- {mimiry-0.2.2 → mimiry-0.2.3}/tests/test_setup.py +0 -0
|
@@ -9,6 +9,7 @@ src/Mimiry.egg-info/top_level.txt
|
|
|
9
9
|
src/mimiry/__init__.py
|
|
10
10
|
src/mimiry/__main__.py
|
|
11
11
|
src/mimiry/_auth.py
|
|
12
|
+
src/mimiry/_availability.py
|
|
12
13
|
src/mimiry/_cli.py
|
|
13
14
|
src/mimiry/_client.py
|
|
14
15
|
src/mimiry/_config.py
|
|
@@ -20,5 +21,8 @@ src/mimiry/exceptions.py
|
|
|
20
21
|
src/mimiry/function.py
|
|
21
22
|
src/mimiry/image.py
|
|
22
23
|
src/mimiry/run.py
|
|
24
|
+
tests/test_availability.py
|
|
25
|
+
tests/test_bootstrap.py
|
|
23
26
|
tests/test_config.py
|
|
27
|
+
tests/test_session.py
|
|
24
28
|
tests/test_setup.py
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Pre-create validation of the requested GPU/provider/location.
|
|
2
|
+
|
|
3
|
+
The scheduler rejects an impossible ``gpu``/``provider`` pairing only *after*
|
|
4
|
+
a session is created — e.g. asking for a ``T4`` from ``verda`` (which doesn't
|
|
5
|
+
carry it) fails the session with ``unsupported GPU type "T4"`` after a
|
|
6
|
+
provisioning round-trip. This module catches that locally, before the POST,
|
|
7
|
+
and turns it into an actionable error that names the providers which *do*
|
|
8
|
+
offer the GPU.
|
|
9
|
+
|
|
10
|
+
Design: the check is **best-effort**. A definitive mismatch (the GPU isn't
|
|
11
|
+
offered, or not by the requested provider/location) raises ``SessionError``.
|
|
12
|
+
But any failure to *consult* availability — network error, malformed payload,
|
|
13
|
+
empty list — is swallowed: a flaky availability endpoint must never block an
|
|
14
|
+
otherwise-valid job. The API stays the source of truth; this is just a fast,
|
|
15
|
+
friendly pre-flight.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
from mimiry.exceptions import SessionError
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def check_gpu_offered(
|
|
26
|
+
models: list[dict],
|
|
27
|
+
gpu: str,
|
|
28
|
+
provider: str | None,
|
|
29
|
+
location: str | None,
|
|
30
|
+
) -> None:
|
|
31
|
+
"""Raise ``SessionError`` if ``gpu`` (optionally pinned to ``provider`` /
|
|
32
|
+
``location``) isn't offered according to the availability ``models`` list.
|
|
33
|
+
|
|
34
|
+
``gpu`` matches either a model ``name`` (e.g. ``"H100_SXM"``) or ``family``
|
|
35
|
+
(e.g. ``"H100"``). Returns ``None`` when the request is satisfiable.
|
|
36
|
+
"""
|
|
37
|
+
matches = [m for m in models if m.get("name") == gpu or m.get("family") == gpu]
|
|
38
|
+
if not matches:
|
|
39
|
+
offered = sorted({m.get("name") for m in models if m.get("name")})
|
|
40
|
+
raise SessionError(
|
|
41
|
+
f"GPU type {gpu!r} is not offered. Available types: "
|
|
42
|
+
f"{', '.join(offered) or 'none'}."
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
available = [m for m in matches if m.get("available")]
|
|
46
|
+
if not available:
|
|
47
|
+
raise SessionError(f"GPU type {gpu!r} is currently unavailable on all providers.")
|
|
48
|
+
|
|
49
|
+
if provider is None:
|
|
50
|
+
return # available somewhere; let the scheduler pick a provider
|
|
51
|
+
|
|
52
|
+
# Collapse the available matches into provider → set(locations).
|
|
53
|
+
prov_locs: dict[str, set[str]] = {}
|
|
54
|
+
for m in available:
|
|
55
|
+
for p in m.get("providers", []):
|
|
56
|
+
name = p.get("provider")
|
|
57
|
+
if name:
|
|
58
|
+
prov_locs.setdefault(name, set()).update(p.get("locations") or [])
|
|
59
|
+
|
|
60
|
+
if provider not in prov_locs:
|
|
61
|
+
offerers = ", ".join(sorted(prov_locs)) or "none"
|
|
62
|
+
raise SessionError(
|
|
63
|
+
f"GPU {gpu!r} is not offered by provider {provider!r}. "
|
|
64
|
+
f"Available providers for {gpu}: {offerers}. "
|
|
65
|
+
f"Pass provider=<one of those>, or omit the provider hint to let "
|
|
66
|
+
f"Mimiry choose."
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
if location is not None and location not in prov_locs[provider]:
|
|
70
|
+
locs = ", ".join(sorted(prov_locs[provider])) or "none"
|
|
71
|
+
raise SessionError(
|
|
72
|
+
f"Provider {provider!r} offers {gpu} but not in location {location!r}. "
|
|
73
|
+
f"Available locations: {locs}."
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def preflight_gpu_availability(
|
|
78
|
+
client: Any,
|
|
79
|
+
gpu: str,
|
|
80
|
+
provider: str | None,
|
|
81
|
+
location: str | None = None,
|
|
82
|
+
) -> None:
|
|
83
|
+
"""Best-effort pre-create check. Raises ``SessionError`` on a definitive
|
|
84
|
+
mismatch; silently returns if availability can't be consulted.
|
|
85
|
+
|
|
86
|
+
``client`` only needs a ``get_availability()`` method (see
|
|
87
|
+
:class:`mimiry._client.MimiryClient`).
|
|
88
|
+
"""
|
|
89
|
+
try:
|
|
90
|
+
data = client.get_availability()
|
|
91
|
+
except Exception:
|
|
92
|
+
return # never block submission on an availability-endpoint hiccup
|
|
93
|
+
models = data.get("gpu_models") if isinstance(data, dict) else None
|
|
94
|
+
if not models:
|
|
95
|
+
return # nothing to validate against — defer to the API
|
|
96
|
+
check_gpu_offered(models, gpu, provider, location)
|
|
@@ -163,8 +163,11 @@ def build_bootstrap_script(image_install_prefix: str = "") -> str:
|
|
|
163
163
|
# this is a single-purpose container with a fresh root filesystem — there's
|
|
164
164
|
# no system Python to break.
|
|
165
165
|
parts: list[str] = ["set -e"]
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
# Ensure python3 + pip FIRST — before the image's install prefix, which often
|
|
167
|
+
# needs pip (e.g. Image.pip_install renders ``python3 -m pip install ...``).
|
|
168
|
+
# Running the prefix before this defeats the whole purpose: on a minimal image
|
|
169
|
+
# (nvidia/cuda runtime) the prefix's pip wouldn't exist yet and `set -e` would
|
|
170
|
+
# abort the container with exit 127 before anything else ran.
|
|
168
171
|
parts.append(
|
|
169
172
|
'if ! command -v python3 >/dev/null 2>&1; then '
|
|
170
173
|
'DEBIAN_FRONTEND=noninteractive apt-get update -qq && '
|
|
@@ -180,6 +183,9 @@ def build_bootstrap_script(image_install_prefix: str = "") -> str:
|
|
|
180
183
|
'--no-install-recommends python3-pip >/dev/null 2>&1; '
|
|
181
184
|
'fi'
|
|
182
185
|
)
|
|
186
|
+
# Now the image's own deps (apt/pip) — pip is guaranteed to exist by here.
|
|
187
|
+
if image_install_prefix:
|
|
188
|
+
parts.append(image_install_prefix)
|
|
183
189
|
# Install cloudpickle eagerly in the shell so we can fail fast with apt-cache
|
|
184
190
|
# already warm. ``--break-system-packages`` is harmless on older Ubuntu (pip
|
|
185
191
|
# ignores it) and required on 24.04+.
|
|
@@ -197,3 +197,53 @@ def raise_if_failed(session_payload: dict, client: MimiryClient | None = None) -
|
|
|
197
197
|
stop_reason=session_payload.get("stop_reason"),
|
|
198
198
|
events=events,
|
|
199
199
|
)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def raise_if_ended_before_result(
|
|
203
|
+
session_payload: dict, client: MimiryClient | None = None
|
|
204
|
+
) -> None:
|
|
205
|
+
"""Raise SessionFailed if the session reached **any** terminal state at a point
|
|
206
|
+
where the container was expected to still be running (e.g. blocking on the
|
|
207
|
+
result/done flag).
|
|
208
|
+
|
|
209
|
+
In v1 the container writes its result and then blocks until the SDK signals
|
|
210
|
+
done, so reaching ``terminated``/``completed``/``failed`` at the just-started
|
|
211
|
+
checkpoint means the command exited prematurely — almost always a bootstrap
|
|
212
|
+
failure (bad image, failed pip install, etc.). We surface the tail of the
|
|
213
|
+
container logs so the caller sees *why* instead of timing out on SSH.
|
|
214
|
+
"""
|
|
215
|
+
state = _extract_state(session_payload)
|
|
216
|
+
if state not in TERMINAL_STATES:
|
|
217
|
+
return
|
|
218
|
+
|
|
219
|
+
session_id = session_payload.get("id", "?")
|
|
220
|
+
stop_reason = session_payload.get("stop_reason")
|
|
221
|
+
|
|
222
|
+
tail = ""
|
|
223
|
+
events = None
|
|
224
|
+
if client is not None:
|
|
225
|
+
try:
|
|
226
|
+
resp = client.get_logs(session_id, tail=50)
|
|
227
|
+
if resp.get("_status") == 200:
|
|
228
|
+
tail = (resp.get("logs") or "").strip()
|
|
229
|
+
except Exception:
|
|
230
|
+
pass
|
|
231
|
+
try:
|
|
232
|
+
events = fetch_events(client, session_id)
|
|
233
|
+
except Exception:
|
|
234
|
+
events = None
|
|
235
|
+
|
|
236
|
+
msg = (
|
|
237
|
+
f"session {session_id} ended in state={state} (stop_reason={stop_reason}) "
|
|
238
|
+
f"before the container produced a result — the command likely failed during "
|
|
239
|
+
f"startup"
|
|
240
|
+
)
|
|
241
|
+
if tail:
|
|
242
|
+
msg += f". Last container logs:\n{tail}"
|
|
243
|
+
raise SessionFailed(
|
|
244
|
+
msg,
|
|
245
|
+
session_id=session_id,
|
|
246
|
+
state=state,
|
|
247
|
+
stop_reason=stop_reason,
|
|
248
|
+
events=events,
|
|
249
|
+
)
|
|
@@ -21,6 +21,7 @@ from pathlib import Path
|
|
|
21
21
|
from typing import Any, Callable, Iterable
|
|
22
22
|
|
|
23
23
|
from mimiry._auth import get_token
|
|
24
|
+
from mimiry._availability import preflight_gpu_availability
|
|
24
25
|
from mimiry._client import MimiryClient
|
|
25
26
|
from mimiry._config import get_config
|
|
26
27
|
from mimiry._serialization import (
|
|
@@ -30,6 +31,7 @@ from mimiry._serialization import (
|
|
|
30
31
|
payload_env_var,
|
|
31
32
|
)
|
|
32
33
|
from mimiry._session import (
|
|
34
|
+
raise_if_ended_before_result,
|
|
33
35
|
raise_if_failed,
|
|
34
36
|
wait_for_ssh_ready,
|
|
35
37
|
wait_for_started_or_terminal,
|
|
@@ -215,6 +217,11 @@ def _run_remote(fn: Callable, cfg: FunctionConfig, args: tuple, kwargs: dict) ->
|
|
|
215
217
|
print(f"[mimiry] {msg}", file=sys.stderr, flush=True)
|
|
216
218
|
|
|
217
219
|
with MimiryClient(token) as client:
|
|
220
|
+
# Fail fast on an impossible gpu/provider combo before paying for a
|
|
221
|
+
# provisioning round-trip. Best-effort — a flaky availability endpoint
|
|
222
|
+
# won't block submission. See _availability.py.
|
|
223
|
+
preflight_gpu_availability(client, cfg.gpu, cfg.provider, cfg.location)
|
|
224
|
+
|
|
218
225
|
session = client.create_session(session_payload)
|
|
219
226
|
session_id = session["id"]
|
|
220
227
|
_log(f"session {session_id} submitted")
|
|
@@ -223,7 +230,9 @@ def _run_remote(fn: Callable, cfg: FunctionConfig, args: tuple, kwargs: dict) ->
|
|
|
223
230
|
ran_payload, _ = wait_for_started_or_terminal(
|
|
224
231
|
client, session_id, run_config, on_state_change=lambda s: _log(f"state={s}")
|
|
225
232
|
)
|
|
226
|
-
|
|
233
|
+
# If the container ended before we could attach, surface its logs now
|
|
234
|
+
# instead of blundering into a 300s SSH timeout.
|
|
235
|
+
raise_if_ended_before_result(ran_payload, client=client)
|
|
227
236
|
|
|
228
237
|
_log("waiting for ssh.host to be populated")
|
|
229
238
|
ssh_ready = wait_for_ssh_ready(client, session_id, run_config)
|
|
@@ -270,7 +279,7 @@ def _run_remote(fn: Callable, cfg: FunctionConfig, args: tuple, kwargs: dict) ->
|
|
|
270
279
|
return parse_result(raw)
|
|
271
280
|
except ResultParseError as e:
|
|
272
281
|
raise ResultParseError(f"{e} (session {session_id})") from e
|
|
273
|
-
except Exception
|
|
282
|
+
except Exception:
|
|
274
283
|
# Pull events for the failure narrative.
|
|
275
284
|
try:
|
|
276
285
|
final = client.get_session(session_id, events_tail=-1)
|
|
@@ -57,7 +57,15 @@ class Image:
|
|
|
57
57
|
parts.append(f"apt-get update -qq && apt-get install -y -q {quoted} >/dev/null")
|
|
58
58
|
if self._pip_packages:
|
|
59
59
|
quoted = " ".join(shlex.quote(p) for p in self._pip_packages)
|
|
60
|
-
|
|
60
|
+
# Invoke pip via ``python3 -m pip`` (a bare ``pip`` is often absent on
|
|
61
|
+
# minimal images, e.g. nvidia/cuda runtimes). ``--break-system-packages``
|
|
62
|
+
# is required on Ubuntu 24.04+ (PEP 668) and ignored by older pip — the
|
|
63
|
+
# bootstrap installs into a single-purpose container, so there's no
|
|
64
|
+
# system Python to protect. The bootstrap guarantees python3 + pip exist
|
|
65
|
+
# before this prefix runs (see build_bootstrap_script ordering).
|
|
66
|
+
parts.append(
|
|
67
|
+
f"python3 -m pip install --break-system-packages --quiet --no-input {quoted}"
|
|
68
|
+
)
|
|
61
69
|
return " && ".join(parts)
|
|
62
70
|
|
|
63
71
|
@property
|
|
@@ -17,9 +17,15 @@ from datetime import datetime
|
|
|
17
17
|
from pathlib import Path
|
|
18
18
|
|
|
19
19
|
from mimiry._auth import get_token
|
|
20
|
+
from mimiry._availability import preflight_gpu_availability
|
|
20
21
|
from mimiry._client import MimiryClient
|
|
21
22
|
from mimiry._config import Config, get_config
|
|
22
|
-
from mimiry._session import
|
|
23
|
+
from mimiry._session import (
|
|
24
|
+
raise_if_ended_before_result,
|
|
25
|
+
raise_if_failed,
|
|
26
|
+
wait_for_ssh_ready,
|
|
27
|
+
wait_for_started_or_terminal,
|
|
28
|
+
)
|
|
23
29
|
from mimiry._ssh import (
|
|
24
30
|
CONTAINER_HOLD_TIMEOUT_SECONDS,
|
|
25
31
|
DONE_FLAG,
|
|
@@ -146,6 +152,10 @@ def run(
|
|
|
146
152
|
print(f"[mimiry] {msg}", file=sys.stderr, flush=True)
|
|
147
153
|
|
|
148
154
|
with MimiryClient(token) as client:
|
|
155
|
+
# Fail fast on an impossible gpu/provider combo before provisioning.
|
|
156
|
+
# Best-effort — see _availability.py.
|
|
157
|
+
preflight_gpu_availability(client, gpu, provider, location)
|
|
158
|
+
|
|
149
159
|
session = client.create_session(payload)
|
|
150
160
|
session_id = session["id"]
|
|
151
161
|
_log(f"session {session_id} submitted")
|
|
@@ -154,7 +164,9 @@ def run(
|
|
|
154
164
|
ran_payload, _ = wait_for_started_or_terminal(
|
|
155
165
|
client, session_id, run_config, on_state_change=lambda s: _log(f"state={s}")
|
|
156
166
|
)
|
|
157
|
-
|
|
167
|
+
# Surface a premature container exit (bad image / failed install) with
|
|
168
|
+
# its logs, rather than timing out on SSH afterwards.
|
|
169
|
+
raise_if_ended_before_result(ran_payload, client=client)
|
|
158
170
|
|
|
159
171
|
_log("waiting for ssh.host to be populated")
|
|
160
172
|
ssh_ready = wait_for_ssh_ready(client, session_id, run_config)
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Tests for pre-create GPU/provider/location validation against /availability."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from mimiry._availability import check_gpu_offered, preflight_gpu_availability
|
|
8
|
+
from mimiry.exceptions import SessionError
|
|
9
|
+
|
|
10
|
+
# Mirrors the shape of GET /api/compute/v1/availability (abbreviated).
|
|
11
|
+
SAMPLE = {
|
|
12
|
+
"gpu_models": [
|
|
13
|
+
{
|
|
14
|
+
"name": "T4", "family": "T4", "available": True, "currency": "EUR",
|
|
15
|
+
"providers": [{"provider": "gcp", "hourly_rate": 0.36, "locations": ["europe-west4-a"]}],
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "H100_SXM", "family": "H100", "available": True, "currency": "EUR",
|
|
19
|
+
"providers": [
|
|
20
|
+
{"provider": "verda", "hourly_rate": 2.1, "locations": ["FIN-01"]},
|
|
21
|
+
{"provider": "acme", "hourly_rate": 2.5, "locations": ["US-EAST-1"]},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "A100", "family": "A100", "available": False, "currency": "EUR",
|
|
26
|
+
"providers": [{"provider": "verda", "hourly_rate": 1.2, "locations": ["FIN-01"]}],
|
|
27
|
+
},
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
MODELS = SAMPLE["gpu_models"]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# ────────────────────────── check_gpu_offered (pure) ──────────────────────────
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_ok_when_gpu_and_provider_match():
|
|
37
|
+
check_gpu_offered(MODELS, "T4", "gcp", None) # no raise
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_ok_when_no_provider_hint():
|
|
41
|
+
check_gpu_offered(MODELS, "T4", None, None) # available somewhere → fine
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_raises_when_provider_does_not_offer_gpu():
|
|
45
|
+
# The real bug: T4 requested from verda, which only offers H100/A100.
|
|
46
|
+
with pytest.raises(SessionError, match="not offered by provider 'verda'") as exc:
|
|
47
|
+
check_gpu_offered(MODELS, "T4", "verda", None)
|
|
48
|
+
# The error must point the user at the provider that *does* offer it.
|
|
49
|
+
assert "gcp" in str(exc.value)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_raises_when_gpu_type_unknown():
|
|
53
|
+
with pytest.raises(SessionError, match="not offered"):
|
|
54
|
+
check_gpu_offered(MODELS, "B200", None, None)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_raises_when_gpu_unavailable_everywhere():
|
|
58
|
+
with pytest.raises(SessionError, match="currently unavailable"):
|
|
59
|
+
check_gpu_offered(MODELS, "A100", None, None)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_ok_matching_by_family_name():
|
|
63
|
+
# "H100" is a family; the offered model name is "H100_SXM".
|
|
64
|
+
check_gpu_offered(MODELS, "H100", "acme", None)
|
|
65
|
+
check_gpu_offered(MODELS, "H100_SXM", "verda", None)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_ok_when_location_matches():
|
|
69
|
+
check_gpu_offered(MODELS, "T4", "gcp", "europe-west4-a")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_raises_when_location_not_offered_by_provider():
|
|
73
|
+
with pytest.raises(SessionError, match="not in location 'us-central1'") as exc:
|
|
74
|
+
check_gpu_offered(MODELS, "T4", "gcp", "us-central1")
|
|
75
|
+
assert "europe-west4-a" in str(exc.value)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# ────────────────────────── preflight wrapper (I/O, best-effort) ──────────────────────────
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class _FakeClient:
|
|
82
|
+
def __init__(self, *, data=None, raises: Exception | None = None):
|
|
83
|
+
self._data = data
|
|
84
|
+
self._raises = raises
|
|
85
|
+
self.calls = 0
|
|
86
|
+
|
|
87
|
+
def get_availability(self, **params):
|
|
88
|
+
self.calls += 1
|
|
89
|
+
if self._raises is not None:
|
|
90
|
+
raise self._raises
|
|
91
|
+
return self._data
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_preflight_propagates_definitive_mismatch():
|
|
95
|
+
client = _FakeClient(data=SAMPLE)
|
|
96
|
+
with pytest.raises(SessionError, match="not offered by provider 'verda'"):
|
|
97
|
+
preflight_gpu_availability(client, "T4", "verda", None)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_preflight_passes_through_on_valid_combo():
|
|
101
|
+
client = _FakeClient(data=SAMPLE)
|
|
102
|
+
preflight_gpu_availability(client, "T4", "gcp", None) # no raise
|
|
103
|
+
assert client.calls == 1
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_preflight_is_silent_when_availability_fetch_fails():
|
|
107
|
+
"""A flaky availability endpoint must NOT block a job submission."""
|
|
108
|
+
client = _FakeClient(raises=RuntimeError("network down"))
|
|
109
|
+
preflight_gpu_availability(client, "T4", "verda", None) # swallowed, no raise
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def test_preflight_is_silent_when_payload_has_no_models():
|
|
113
|
+
client = _FakeClient(data={}) # malformed/empty → nothing to validate against
|
|
114
|
+
preflight_gpu_availability(client, "T4", "verda", None) # no raise
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Tests for image install-prefix rendering and bootstrap command ordering.
|
|
2
|
+
|
|
3
|
+
Regression cover for the `pip: command not found` (exit 127) failure: a bare
|
|
4
|
+
`pip` ran on a minimal CUDA image *before* the bootstrap installed python/pip.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from mimiry._serialization import build_bootstrap_script
|
|
10
|
+
from mimiry.image import Image
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# ────────────────────────── Image.install_prefix ──────────────────────────
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_pip_install_uses_python3_m_pip_with_break_system_packages():
|
|
17
|
+
pfx = Image.from_registry("x").pip_install("torch", "numpy").install_prefix()
|
|
18
|
+
# Must go through `python3 -m pip` (bare `pip` is often absent) and pass
|
|
19
|
+
# --break-system-packages (PEP 668 on Ubuntu 24.04+).
|
|
20
|
+
assert "python3 -m pip install --break-system-packages" in pfx
|
|
21
|
+
assert "torch" in pfx and "numpy" in pfx
|
|
22
|
+
# Must NOT be a bare `pip install ...`.
|
|
23
|
+
assert "pip install" not in pfx.replace("python3 -m pip install", "")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_apt_install_still_rendered():
|
|
27
|
+
pfx = Image.from_registry("x").apt_install("ffmpeg", "git").install_prefix()
|
|
28
|
+
assert "apt-get install -y -q ffmpeg git" in pfx
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_empty_install_prefix_is_blank():
|
|
32
|
+
assert Image.from_registry("x").install_prefix() == ""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_apt_before_pip_in_prefix():
|
|
36
|
+
pfx = Image.from_registry("x").apt_install("libsndfile1").pip_install("torch").install_prefix()
|
|
37
|
+
assert pfx.index("apt-get") < pfx.index("python3 -m pip")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# ────────────────────────── bootstrap ordering ──────────────────────────
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_install_prefix_runs_after_python_and_pip_are_ensured():
|
|
44
|
+
s = build_bootstrap_script(image_install_prefix="MARKER_INSTALL")
|
|
45
|
+
assert "MARKER_INSTALL" in s
|
|
46
|
+
# The regression: python3 + pip must be ensured BEFORE the image's pip install.
|
|
47
|
+
assert s.index("command -v python3") < s.index("MARKER_INSTALL")
|
|
48
|
+
assert s.index("python3 -m pip --version") < s.index("MARKER_INSTALL")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_bootstrap_without_prefix_is_still_wrapped_and_ensures_python():
|
|
52
|
+
s = build_bootstrap_script()
|
|
53
|
+
assert s.startswith("bash -c ")
|
|
54
|
+
assert "command -v python3" in s
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Tests for terminal-state failure surfacing (raise_if_ended_before_result)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from mimiry._session import raise_if_ended_before_result
|
|
8
|
+
from mimiry.exceptions import SessionFailed
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class _FakeClient:
|
|
12
|
+
"""Minimal client stub: returns canned logs/events for a terminated session."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, logs: str | None = None):
|
|
15
|
+
self._logs = logs
|
|
16
|
+
|
|
17
|
+
def get_logs(self, session_id, *, tail: int = 50, timestamps: bool = False):
|
|
18
|
+
if self._logs is None:
|
|
19
|
+
return {"_status": 409} # logs window gone
|
|
20
|
+
return {"_status": 200, "logs": self._logs}
|
|
21
|
+
|
|
22
|
+
def get_session(self, session_id, *, events_tail=None):
|
|
23
|
+
return {"events": []}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_no_raise_when_session_still_running():
|
|
27
|
+
raise_if_ended_before_result({"id": "s", "state": "started"}) # no raise
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_no_raise_when_provisioning():
|
|
31
|
+
raise_if_ended_before_result({"id": "s", "state": "provisioned"}) # no raise
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_raises_on_terminated_with_container_logs():
|
|
35
|
+
# The exact failure we debugged: container exits 127 during bootstrap.
|
|
36
|
+
client = _FakeClient(logs="bash: line 1: pip: command not found")
|
|
37
|
+
with pytest.raises(SessionFailed) as exc:
|
|
38
|
+
raise_if_ended_before_result(
|
|
39
|
+
{"id": "s1", "state": "terminated", "stop_reason": "CONTAINER_EXITED"},
|
|
40
|
+
client=client,
|
|
41
|
+
)
|
|
42
|
+
err = exc.value
|
|
43
|
+
assert err.state == "terminated"
|
|
44
|
+
assert err.stop_reason == "CONTAINER_EXITED"
|
|
45
|
+
# The container's logs must be in the message so the user sees *why*.
|
|
46
|
+
assert "pip: command not found" in str(err)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_raises_on_completed_even_without_client():
|
|
50
|
+
# Any terminal state at this checkpoint means premature exit.
|
|
51
|
+
with pytest.raises(SessionFailed):
|
|
52
|
+
raise_if_ended_before_result({"id": "s", "state": "completed"})
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_raises_gracefully_when_logs_unavailable():
|
|
56
|
+
client = _FakeClient(logs=None) # get_logs returns 409
|
|
57
|
+
with pytest.raises(SessionFailed) as exc:
|
|
58
|
+
raise_if_ended_before_result(
|
|
59
|
+
{"id": "s2", "state": "stopped", "stop_reason": "timed_out"}, client=client
|
|
60
|
+
)
|
|
61
|
+
assert exc.value.state == "stopped" # still raises, just without a log tail
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|