|
7 | 7 | import importlib.util |
8 | 8 | import io |
9 | 9 | import json |
| 10 | +import math |
10 | 11 | import os |
11 | 12 | import secrets |
12 | 13 | import sys |
13 | 14 | import tarfile |
14 | 15 | from pathlib import Path |
| 16 | +from types import ModuleType |
| 17 | + |
| 18 | +# ponytail: mission bandwidth floor (Mbit/s) lives here, not in the signed profile; move it into |
| 19 | +# profile["admission"] when the profile schema is next re-signed. |
| 20 | +MIN_INET_MBPS = 800 |
| 21 | + |
| 22 | + |
| 23 | +def fast_link(value: object) -> bool: |
| 24 | + return ( |
| 25 | + isinstance(value, (int, float)) |
| 26 | + and not isinstance(value, bool) |
| 27 | + and math.isfinite(value) |
| 28 | + and value >= MIN_INET_MBPS |
| 29 | + ) |
15 | 30 |
|
16 | 31 |
|
17 | 32 | def digest(path: Path) -> str: |
@@ -227,9 +242,158 @@ def candidate_freeze(original: Path, destination: Path, candidates: list[str]) - |
227 | 242 | return destination / "freeze.json" |
228 | 243 |
|
229 | 244 |
|
| 245 | +def prepare_qualification_base( |
| 246 | + freeze: dict, |
| 247 | + tree: Path, |
| 248 | + maps: dict, |
| 249 | + controller: ModuleType, |
| 250 | + output: Path, |
| 251 | + out: Path, |
| 252 | + job_dir: Path, |
| 253 | + ownership: Path, |
| 254 | + registry: Path, |
| 255 | + platform: Path, |
| 256 | +) -> dict: |
| 257 | + """prune_rescued qualification base only: reuses the generated V2 manifest/job/objects and the |
| 258 | + task-4 hosts by reference. No synthetic roles, joins, genesis, relay, TLS or services: the real |
| 259 | + uid247 join and seed context are signed at run time with the existing keys.""" |
| 260 | + profile_path, job_path = out / "profile.json", job_dir / "job.json" |
| 261 | + profile = json.loads(profile_path.read_bytes()) |
| 262 | + job = json.loads(job_path.read_bytes()) |
| 263 | + if profile["artifacts"].get("remote_retention") != "prune_rescued": |
| 264 | + raise ValueError("qualification base requires the generated prune_rescued profile") |
| 265 | + if "sha256:" + digest(registry) != profile["runtime"]["image_digest"]: |
| 266 | + raise ValueError("registry index must be the pinned image digest") |
| 267 | + controller.registry_layers(json.loads(registry.read_bytes()), platform) |
| 268 | + objects = {key: job_dir / rel for key, rel in job["object_paths"].items()} |
| 269 | + from hypertrain.gpu_ops import network_qualification |
| 270 | + |
| 271 | + # Exactly what reviewed_launch recomputes: raw tree map with the qualification profile |
| 272 | + # overlaid at experiments/gpu_network_v2/profile.json (the remote check sees the same tree). |
| 273 | + overlay, bundle_bytes = controller.effective_bundle(network_qualification, tree, profile_path) |
| 274 | + source = json.loads(ownership.read_bytes()) |
| 275 | + if isinstance(source, list): |
| 276 | + # Fresh admit: the measured GET offer rows select two distinct exact-shape machines. |
| 277 | + limits = controller.admission_limits(profile) |
| 278 | + if len(source) != 2 or not all(isinstance(o, dict) for o in source): |
| 279 | + raise ValueError("fresh offers must be two distinct exact-shape pinned-driver machines") |
| 280 | + hosts = [ |
| 281 | + {"role": r, "machine_id": o.get("machine_id")} |
| 282 | + for r, o in zip(("h0", "h1"), source, strict=True) |
| 283 | + ] |
| 284 | + if ( |
| 285 | + any(type(h["machine_id"]) is not int for h in hosts) |
| 286 | + or len({h["machine_id"] for h in hosts}) != 2 |
| 287 | + or any( |
| 288 | + type(o.get("id")) is not int |
| 289 | + or o.get("num_gpus") != limits["gpus"] |
| 290 | + or o.get("gpu_name") != limits["gpu_name"] |
| 291 | + or o.get("driver_version") not in profile["runtime"]["driver_allowlist"] |
| 292 | + or not fast_link(o.get("inet_up")) |
| 293 | + or not fast_link(o.get("inet_down")) |
| 294 | + for o in source |
| 295 | + ) |
| 296 | + ): |
| 297 | + raise ValueError("fresh offers must be two distinct exact-shape pinned-driver machines") |
| 298 | + else: |
| 299 | + hosts = [ |
| 300 | + {"role": role, "machine_id": source["api_lookup"][s]["machine_id"]} |
| 301 | + for role, s in (("h0", "hostA"), ("h1", "hostB")) |
| 302 | + ] |
| 303 | + if any(type(h["machine_id"]) is not int for h in hosts): |
| 304 | + raise ValueError("task-4 ownership must name hostA/hostB machine ids") |
| 305 | + output.mkdir(mode=0o700) |
| 306 | + private, public = output / "private", output / "public" |
| 307 | + save(public / "qualification-sources.json", overlay) |
| 308 | + bundle = public / "qualification-source.tar" |
| 309 | + save(bundle, bundle_bytes) |
| 310 | + save( |
| 311 | + private / "lifecycle-config.json", |
| 312 | + { |
| 313 | + "hosts": hosts, |
| 314 | + "cleanup_contract": "network-v2", |
| 315 | + "tree": str(tree), |
| 316 | + "network_profile_file": str(profile_path), |
| 317 | + "image": freeze["image_candidate"]["ref"], |
| 318 | + "remote_python": profile["runtime"]["remote_python"], |
| 319 | + "disk_gb": controller.admission_limits(profile)["disk_gb"], |
| 320 | + "hard_deadline_seconds": controller.lifecycle_timing(profile)["horizon"], |
| 321 | + "hard_grace_seconds": 0, |
| 322 | + "base_url": "https://console.vast.ai", |
| 323 | + "boot_timeout_seconds": 300, |
| 324 | + "keyscan_attempts": 1, |
| 325 | + "create_margin_seconds": 600, |
| 326 | + # ponytail: fixed remote layout; prepare_record adds key_file + cleanup_deadline_unix. |
| 327 | + "remote_root": "/data/hypertrain-{role}", |
| 328 | + "evidence_path": str(output / "private/evidence-run.json"), |
| 329 | + }, |
| 330 | + True, |
| 331 | + ) |
| 332 | + save( |
| 333 | + public / "lifecycle-hashes.json", |
| 334 | + { |
| 335 | + name: maps["qualification-sources.json"][name] |
| 336 | + for name in ( |
| 337 | + "src/hypertrain/gpu_ops/launcher.py", |
| 338 | + "src/hypertrain/gpu_ops/supervisor.py", |
| 339 | + ) |
| 340 | + }, |
| 341 | + ) |
| 342 | + paths = { |
| 343 | + "config": private / "lifecycle-config.json", |
| 344 | + "profile": profile_path, |
| 345 | + "sources": public / "qualification-sources.json", |
| 346 | + "bundle": bundle, |
| 347 | + "manifest": out / "manifest-envelope.json", |
| 348 | + "lifecycle_hashes": public / "lifecycle-hashes.json", |
| 349 | + "registry": registry, |
| 350 | + "registry_platform": platform, |
| 351 | + "ownership": ownership, |
| 352 | + "job": job_path, |
| 353 | + **{"object_" + key: path for key, path in objects.items()}, |
| 354 | + } |
| 355 | + staged = sum(p.stat().st_size for p in [bundle, job_path, *objects.values()]) |
| 356 | + record = { |
| 357 | + "tree": str(tree), |
| 358 | + "files": {name: {"path": str(p), "sha256": digest(p)} for name, p in sorted(paths.items())}, |
| 359 | + "quota": controller.execution_quota(profile), |
| 360 | + "staging_bytes": staged, |
| 361 | + "public_dataset_reviewed": True, |
| 362 | + "full_genesis_reviewed": True, |
| 363 | + "preparation_only": True, |
| 364 | + # Per-role join/seed_context (one real uid247 identity on both hosts) and every fresh |
| 365 | + # provider/authority file are added by scripts/prepare_record.py at run time. |
| 366 | + "role_inputs": { |
| 367 | + "job": "job", |
| 368 | + "objects": {key: "object_" + key for key in objects}, |
| 369 | + }, |
| 370 | + "remaining": ["roles", "action", "owner", "parent_pid", "cutoff_unix", "admitted_unix"], |
| 371 | + } |
| 372 | + save(private / "review-base.json", {"record": record}, True) |
| 373 | + result = { |
| 374 | + "status": "QUALIFICATION_BASE_NOT_LAUNCHABLE", |
| 375 | + "run_id": job["run_id"], |
| 376 | + "review_base": str(private / "review-base.json"), |
| 377 | + "review_base_sha256": digest(private / "review-base.json"), |
| 378 | + "staging_bytes": staged, |
| 379 | + "quota": record["quota"], |
| 380 | + "kernels_executed": 0, |
| 381 | + "provider_calls": 0, |
| 382 | + } |
| 383 | + save(output / "prepared.json", result) |
| 384 | + return result |
| 385 | + |
| 386 | + |
230 | 387 | def prepare( |
231 | | - freeze_path: Path, output: Path, genesis: int, candidates: list[str] | None = None |
| 388 | + freeze_path: Path, |
| 389 | + output: Path, |
| 390 | + genesis: int, |
| 391 | + candidates: list[str] | None = None, |
| 392 | + qualification: tuple[Path, Path, Path, Path, Path] | None = None, |
232 | 393 | ) -> dict: |
| 394 | + if qualification is not None: |
| 395 | + freeze, tree, maps, _, _, controller = load_frozen(freeze_path) |
| 396 | + return prepare_qualification_base(freeze, tree, maps, controller, output, *qualification) |
233 | 397 | if output.exists() or genesis < 1: |
234 | 398 | raise ValueError("new output and positive deterministic CPU genesis required") |
235 | 399 | if candidates is not None and candidates != ["580.95.05", "580.159.03"]: |
@@ -627,6 +791,13 @@ def main() -> None: |
627 | 791 | parser.add_argument("--output", type=Path, required=True) |
628 | 792 | parser.add_argument("--cpu-genesis-unix", type=int, required=True) |
629 | 793 | parser.add_argument("--candidate-driver", action="append") |
| 794 | + parser.add_argument( |
| 795 | + "--qualification-base", |
| 796 | + nargs=5, |
| 797 | + type=Path, |
| 798 | + metavar=("OUT_DIR", "JOB_DIR", "OWNERSHIP", "REGISTRY_INDEX", "REGISTRY_PLATFORM"), |
| 799 | + help="prune_rescued qualification-only base from generated V2 assets", |
| 800 | + ) |
630 | 801 | args = parser.parse_args() |
631 | 802 | os.umask(0o077) |
632 | 803 | print( |
@@ -636,6 +807,9 @@ def main() -> None: |
636 | 807 | args.output.resolve(), |
637 | 808 | args.cpu_genesis_unix, |
638 | 809 | args.candidate_driver, |
| 810 | + tuple(p.resolve() for p in args.qualification_base) |
| 811 | + if args.qualification_base |
| 812 | + else None, |
639 | 813 | ), |
640 | 814 | sort_keys=True, |
641 | 815 | ) |
|