Local preservation snapshot, not a new deployment or simulation acceptance.
61 lines
3.2 KiB
Python
61 lines
3.2 KiB
Python
"""One offline GPU job under a Core simulation reservation, with exact cleanup."""
|
|
|
|
import argparse
|
|
import json
|
|
import subprocess
|
|
import time
|
|
from datetime import UTC, datetime
|
|
from pathlib import Path
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--reservation", type=Path, required=True)
|
|
parser.add_argument("--inputs", type=Path, required=True)
|
|
parser.add_argument("--output", type=Path, required=True)
|
|
parser.add_argument("--root", type=Path, default=Path("D:/NDC_MISSIONCORE/runtime/simulation"))
|
|
args = parser.parse_args()
|
|
receipt = json.loads(args.reservation.read_text())
|
|
assert receipt["state"] == "reserved" and receipt["owner_id"].startswith("airun-")
|
|
assert not (args.root / "state/active.json").exists(), "A rover run is active"
|
|
assert 0 <= (datetime.now(UTC) - datetime.fromisoformat(receipt["utc"])).total_seconds() < 900
|
|
adapter = Path(__file__).parent.resolve()
|
|
descriptor = json.loads((adapter / "model.json").read_text())
|
|
assets = Path(descriptor["existing_asset_path"])
|
|
assert (assets / "model.safetensors").is_file()
|
|
args.output.mkdir(parents=True, exist_ok=False)
|
|
identity = None
|
|
begin = time.monotonic()
|
|
try:
|
|
identity = subprocess.check_output([
|
|
"docker", "run", "-d", "--name", "ndc-eomt-qualification-" + receipt["owner_id"][-8:],
|
|
"--gpus", "all", "--cpus", "3", "--memory", "6g",
|
|
"--label", "com.nodedc.product=mission-core", "--label", "com.nodedc.stack=ai-polygon-qualification",
|
|
"--label", "com.nodedc.role=qualification", "--label", "com.nodedc.managed-by=ai-polygon-qualification",
|
|
"--mount", f"type=bind,source={adapter},target=/adapter,readonly",
|
|
"--mount", f"type=bind,source={assets},target=/assets,readonly",
|
|
"--mount", f"type=bind,source={args.inputs.resolve()},target=/inputs,readonly",
|
|
"--mount", f"type=bind,source={args.output.resolve()},target=/evidence",
|
|
"--mount", "type=bind,source=D:/NDC_MISSIONCORE/runtime/derived/perception-p0-env-v1,target=/opt/env,readonly",
|
|
"--mount", "type=bind,source=D:/NDC_MISSIONCORE/runtime/derived/perception-p0-transformers4576-v1,target=/opt/transformers,readonly",
|
|
"-e", "PYTHONPATH=/opt/transformers:/opt/env",
|
|
"--entrypoint", "python3",
|
|
"sha256:211852dfae4ab1acbd1195d4968a385ea56bd7bd3d0c4241a6be7e02794999b7",
|
|
"-B", "/adapter/qualify.py",
|
|
], text=True).strip()
|
|
result = subprocess.check_output(["docker", "wait", identity], timeout=240, text=True).strip()
|
|
logs = subprocess.check_output(["docker", "logs", identity], stderr=subprocess.STDOUT, text=True)
|
|
(args.output / "execution.log").write_text(logs)
|
|
print(logs[-14000:])
|
|
assert result == "0", "Model qualification failed: exit " + result
|
|
finally:
|
|
released = identity is None or subprocess.run(["docker", "rm", "-f", identity], capture_output=True).returncode == 0
|
|
(args.output / "cleanup.json").write_text(json.dumps(dict(
|
|
owner_id=receipt["owner_id"], released=released, utc=datetime.now(UTC).isoformat(),
|
|
elapsed_seconds=time.monotonic() - begin)))
|
|
assert released
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|