envloop-envhub 2.3.1__tar.gz → 2.4.0__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.
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/PKG-INFO +1 -1
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/proto/recipe.py +27 -1
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/supervisor/controller.py +50 -14
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/pyproject.toml +1 -1
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/NOTICE +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/README.pypi.md +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/__init__.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/__init__.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/client/__init__.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/client/download.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/client/materialize.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/client/recipe_package.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/proto/__init__.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/proto/ans.proto +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/proto/errors.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/proto/manifests.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/proto/params.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/proto/schemas.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/proto/tags.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/ans/proto/uri.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/checkpoints/__init__.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/checkpoints/source.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/jobs/__init__.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/jobs/types.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/proxyhub/__init__.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/proxyhub/bundle.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/proxyhub/guest.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/proxyhub/policy.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/proxyhub/services.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/supervisor/__init__.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/supervisor/__main__.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/supervisor/asset_io.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/supervisor/bootstrap.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/supervisor/contract.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/supervisor/declarations.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/supervisor/guest.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/supervisor/outputs.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/supervisor/process.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/supervisor/redaction.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/supervisor/sdk.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/envhub/supervisor/tools.py +0 -0
- {envloop_envhub-2.3.1 → envloop_envhub-2.4.0}/hatch_build.py +0 -0
|
@@ -30,6 +30,7 @@ import re
|
|
|
30
30
|
import tomllib
|
|
31
31
|
from collections.abc import Mapping
|
|
32
32
|
from dataclasses import dataclass, field
|
|
33
|
+
from string import Formatter
|
|
33
34
|
from typing import Any
|
|
34
35
|
|
|
35
36
|
from envhub.ans.proto.errors import InvalidManifest, InvalidURI
|
|
@@ -111,7 +112,7 @@ _INPUT_KINDS = frozenset({'dataset', 'checkpoint', 'artifact'})
|
|
|
111
112
|
_INPUT_ROLES = {'train_dataset': 'dataset', 'eval_dataset': 'dataset',
|
|
112
113
|
'checkpoint': 'checkpoint', 'resume_from_checkpoint': 'checkpoint'}
|
|
113
114
|
_TABLES = frozenset({'schema_version', 'recipe', 'runner', 'source', 'inputs', 'params', 'outputs', 'dependencies',
|
|
114
|
-
'agent', 'inference'})
|
|
115
|
+
'agent', 'inference', 'job'})
|
|
115
116
|
|
|
116
117
|
|
|
117
118
|
class RecipeError(InvalidManifest):
|
|
@@ -155,6 +156,7 @@ class RecipeSpec:
|
|
|
155
156
|
`params.image` (a digest-pinned reference), or None; it is not one of `params`, so it never reaches
|
|
156
157
|
`parameters_schema`, `defaults` or the Recipe's parameter file. `inference` holds an optional
|
|
157
158
|
inference-only v3 interface declaration (operations and packaged example paths); empty is unknown.
|
|
159
|
+
`job` holds an optional declarative Job name template, rendered after parameter merging, never at runtime.
|
|
158
160
|
"""
|
|
159
161
|
|
|
160
162
|
schema: str
|
|
@@ -175,6 +177,7 @@ class RecipeSpec:
|
|
|
175
177
|
image: str | None = None
|
|
176
178
|
source_schema: str | None = None
|
|
177
179
|
inference: dict[str, Any] = field(default_factory=dict)
|
|
180
|
+
job: dict[str, str] = field(default_factory=dict)
|
|
178
181
|
|
|
179
182
|
@property
|
|
180
183
|
def required(self) -> frozenset[str]:
|
|
@@ -191,6 +194,7 @@ def recipe_spec_dict(spec: RecipeSpec) -> dict[str, Any]:
|
|
|
191
194
|
'parameters_schema': spec.parameters_schema, 'defaults': spec.defaults, 'unprojected': spec.unprojected,
|
|
192
195
|
'params_open': spec.params_open, 'required': sorted(spec.required), 'agent': spec.agent,
|
|
193
196
|
**({'inference': spec.inference} if spec.inference else {}),
|
|
197
|
+
**({'job': spec.job} if spec.job else {}),
|
|
194
198
|
**({'image': spec.image} if spec.image is not None else {}),
|
|
195
199
|
**({'source_schema': spec.source_schema} if spec.source_schema is not None else {}),
|
|
196
200
|
}))
|
|
@@ -303,6 +307,27 @@ def _image(params: Any) -> tuple[Any, str | None]:
|
|
|
303
307
|
return rest, value
|
|
304
308
|
|
|
305
309
|
|
|
310
|
+
def _job(value: Any, params: dict[str, dict[str, Any]]) -> dict[str, str]:
|
|
311
|
+
"""A declarative Job name; placeholders cannot access attributes or evaluate code."""
|
|
312
|
+
if value is None:
|
|
313
|
+
return {}
|
|
314
|
+
job = _table(value, {'name'}, {'name'}, 'job')
|
|
315
|
+
name = job['name']
|
|
316
|
+
_require(isinstance(name, str) and 0 < len(name) <= 256 and name.isprintable()
|
|
317
|
+
and name.strip() == name, 'RECIPE_JOB_NAME_INVALID')
|
|
318
|
+
try:
|
|
319
|
+
for _, token, formatting, conversion in Formatter().parse(name):
|
|
320
|
+
if token is None:
|
|
321
|
+
continue
|
|
322
|
+
_require(token in {'model', 'lora'} and not formatting and conversion is None,
|
|
323
|
+
'RECIPE_JOB_NAME_INVALID')
|
|
324
|
+
parameter, kind = ('model', 'string') if token == 'model' else ('lora_rank', 'integer')
|
|
325
|
+
_require(params.get(parameter, {}).get('type') == kind, 'RECIPE_JOB_NAME_INVALID')
|
|
326
|
+
except ValueError:
|
|
327
|
+
raise RecipeError('RECIPE_JOB_NAME_INVALID') from None
|
|
328
|
+
return {'name': name}
|
|
329
|
+
|
|
330
|
+
|
|
306
331
|
def parse_recipe_toml(raw: bytes | str, *, historical: bool = False) -> RecipeSpec:
|
|
307
332
|
"""Parse and validate the text of `recipe.toml` alone."""
|
|
308
333
|
try:
|
|
@@ -354,6 +379,7 @@ def parse_recipe_toml(raw: bytes | str, *, historical: bool = False) -> RecipeSp
|
|
|
354
379
|
parameters_schema=parameters_schema, defaults=defaults, outputs=validate_outputs(value.get('outputs', {}), types),
|
|
355
380
|
agent=agent, image=image, source_schema=LEGACY_SCHEMA if legacy else None,
|
|
356
381
|
inference=_inference(value.get('inference'), types, legacy=legacy),
|
|
382
|
+
job=_job(value.get('job'), params),
|
|
357
383
|
)
|
|
358
384
|
|
|
359
385
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
4
|
import json
|
|
5
|
+
import logging
|
|
5
6
|
import shlex
|
|
6
7
|
import threading
|
|
7
8
|
import time
|
|
@@ -15,6 +16,10 @@ from .asset_io import postflight_diagnostic
|
|
|
15
16
|
from .bootstrap import CLEANUP
|
|
16
17
|
from .guest import INVENTORY, PROBE
|
|
17
18
|
|
|
19
|
+
logger = logging.getLogger(__name__)
|
|
20
|
+
PROBE_FAILURE_LIMIT = 3
|
|
21
|
+
PROBE_TIMEOUT = 10.0
|
|
22
|
+
|
|
18
23
|
|
|
19
24
|
class SupervisorError(RuntimeError):
|
|
20
25
|
def __init__(self, code: str, message: str, *, diagnostic: dict[str, Any] | None = None) -> None:
|
|
@@ -74,17 +79,35 @@ def execute(provider: Any, handle: Any, spec: RunSpec, deadline: float, *,
|
|
|
74
79
|
thread.start()
|
|
75
80
|
observed_exit: int | None = None
|
|
76
81
|
def wait(mode: str, until: float) -> dict[str, Any]:
|
|
82
|
+
interval = 0.25 if mode == 'proof' else 1.0
|
|
83
|
+
failures = 0
|
|
84
|
+
detail = 'deadline reached'
|
|
77
85
|
while time.monotonic() < until:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
try:
|
|
87
|
+
probe = provider.run(handle, [python, '-I', '-S', '-c', PROBE, directory, nonce, mode],
|
|
88
|
+
min(until, time.monotonic() + PROBE_TIMEOUT), cwd='/')
|
|
89
|
+
if probe.exit_code == 0:
|
|
90
|
+
value = json.loads(probe.stdout)
|
|
91
|
+
if isinstance(value, dict):
|
|
92
|
+
return value
|
|
93
|
+
detail = 'invalid probe response'
|
|
94
|
+
elif probe.exit_code == 3:
|
|
95
|
+
failures = 0
|
|
96
|
+
detail = 'evidence unavailable'
|
|
97
|
+
if not thread.is_alive():
|
|
98
|
+
break
|
|
99
|
+
time.sleep(min(interval, max(0.0, until - time.monotonic())))
|
|
100
|
+
continue
|
|
101
|
+
else:
|
|
102
|
+
detail = f'probe exit {probe.exit_code}'
|
|
103
|
+
except Exception as error:
|
|
104
|
+
detail = type(error).__name__
|
|
105
|
+
failures += 1
|
|
106
|
+
if failures >= PROBE_FAILURE_LIMIT or not thread.is_alive():
|
|
85
107
|
break
|
|
86
|
-
time.sleep(.
|
|
87
|
-
raise SupervisorError('WORKER_PROCESS_UNVERIFIED','
|
|
108
|
+
time.sleep(min(interval, max(0.0, until - time.monotonic())))
|
|
109
|
+
raise SupervisorError('WORKER_PROCESS_UNVERIFIED', f'Worker {mode} could not be verified ({detail}).')
|
|
110
|
+
failed = False
|
|
88
111
|
try:
|
|
89
112
|
proof = wait('proof',min(deadline,time.monotonic()+40))
|
|
90
113
|
supervisor = proof['supervisor']
|
|
@@ -134,21 +157,34 @@ def execute(provider: Any, handle: Any, spec: RunSpec, deadline: float, *,
|
|
|
134
157
|
outcome.exit_code=None
|
|
135
158
|
outcome.error='ARTIFACT_OUTPUT_MISSING'
|
|
136
159
|
outcome.publication={'empty':True}
|
|
160
|
+
except BaseException:
|
|
161
|
+
failed = True
|
|
162
|
+
raise
|
|
137
163
|
finally:
|
|
138
164
|
try:
|
|
139
|
-
run(['touch',directory+'/release'])
|
|
165
|
+
run(['touch', directory + '/release'])
|
|
140
166
|
thread.join(timeout=10)
|
|
141
167
|
if thread.is_alive():
|
|
142
|
-
raise SupervisorError('WORKER_NOT_QUIET','Worker supervision did not stop.')
|
|
168
|
+
raise SupervisorError('WORKER_NOT_QUIET', 'Worker supervision did not stop.')
|
|
143
169
|
result = state.get('result')
|
|
144
170
|
if state.get('error') is not None or result is None:
|
|
145
|
-
raise SupervisorError('WORKER_PROCESS_UNVERIFIED','The supervisor completion is unavailable.')
|
|
171
|
+
raise SupervisorError('WORKER_PROCESS_UNVERIFIED', 'The supervisor completion is unavailable.')
|
|
146
172
|
if observed_exit is not None:
|
|
147
173
|
expected = observed_exit if observed_exit >= 0 else 128 - observed_exit
|
|
148
174
|
if result.exit_code != expected:
|
|
149
|
-
raise SupervisorError('WORKER_PROCESS_UNVERIFIED','The supervisor exit status changed.')
|
|
175
|
+
raise SupervisorError('WORKER_PROCESS_UNVERIFIED', 'The supervisor exit status changed.')
|
|
176
|
+
except Exception as error:
|
|
177
|
+
if not failed:
|
|
178
|
+
failed = True
|
|
179
|
+
raise
|
|
180
|
+
logger.warning('supervisor.release_failed error_type=%s', type(error).__name__)
|
|
150
181
|
finally:
|
|
151
|
-
|
|
182
|
+
try:
|
|
183
|
+
run([python, '-I', '-S', '-c', CLEANUP, directory])
|
|
184
|
+
except Exception as error:
|
|
185
|
+
if not failed:
|
|
186
|
+
raise
|
|
187
|
+
logger.warning('supervisor.cleanup_failed error_type=%s', type(error).__name__)
|
|
152
188
|
return outcome
|
|
153
189
|
|
|
154
190
|
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|