Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"repository": "tue-mps/cityscapes_semantic_eomt_large_1024",
|
||||
"revision": "8d6b6d1a3f7b50d441afd7d247c2ed10db186e8f",
|
||||
"existing_asset_path": "D:/NDC_MISSIONCORE/runtime/assets/observatory-portable/eomt-model-cache-cityscapes-large-1024-v1/huggingface/models--tue-mps--cityscapes_semantic_eomt_large_1024/snapshots/8d6b6d1a3f7b50d441afd7d247c2ed10db186e8f",
|
||||
"files": {
|
||||
"config.json": "7f4aa94fa4e43c0dbd79a5420edb511120aef62bd82bfbcbcece79948286a650",
|
||||
"preprocessor_config.json": "97e2fbf7f0bdba2cfc90251c5133bae9c27ddc9c4410509f40670be2332854e7",
|
||||
"model.safetensors": "c265da9a74f58f5c3f4826d23ca4ca78beac0b106cca5842beca61580de5b782"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
"""Pinned OneFormer comparison on recorded views; no rover commands."""
|
||||
import hashlib
|
||||
import json
|
||||
import time
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
from PIL import Image
|
||||
from transformers import AutoImageProcessor, EomtForUniversalSegmentation
|
||||
|
||||
|
||||
def sha(path):
|
||||
digest = hashlib.sha256()
|
||||
with path.open('rb') as stream:
|
||||
for chunk in iter(lambda: stream.read(1024*1024), b''):
|
||||
digest.update(chunk)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def main():
|
||||
torch.set_num_threads(3)
|
||||
assets = Path('/assets')
|
||||
descriptor = json.loads(Path('/adapter/model.json').read_text())
|
||||
for name, expected in descriptor['files'].items():
|
||||
assert sha(assets/name) == expected, name
|
||||
processor = AutoImageProcessor.from_pretrained(assets, local_files_only=True, use_fast=True)
|
||||
model, loading = EomtForUniversalSegmentation.from_pretrained(assets, local_files_only=True, output_loading_info=True)
|
||||
assert not any(loading[k] for k in ('missing_keys','unexpected_keys','mismatched_keys','error_msgs')), loading
|
||||
model.to(device='cuda', dtype=torch.float16).eval()
|
||||
rows=[]
|
||||
output=Path('/evidence')
|
||||
for source in json.loads(Path('/inputs/manifest.json').read_text()):
|
||||
path=Path('/inputs')/source['file']
|
||||
assert sha(path)==source['sha256']
|
||||
original=Image.open(path).convert('RGB')
|
||||
for crop in (True,False):
|
||||
side=min(original.size);x=(original.width-side)//2;y=(original.height-side)//2
|
||||
image=original.crop((x,y,x+side,y+side)) if crop else original
|
||||
inputs=processor(images=image,return_tensors='pt').to(device='cuda', dtype=torch.float16)
|
||||
torch.cuda.synchronize();begin=time.monotonic()
|
||||
with torch.inference_mode():
|
||||
prediction=model(**inputs)
|
||||
labels=processor.post_process_semantic_segmentation(prediction,target_sizes=[(image.height,image.width)])[0].cpu().numpy().astype(np.uint8)
|
||||
torch.cuda.synchronize();elapsed=time.monotonic()-begin
|
||||
name=path.stem+('-crop' if crop else '-full')
|
||||
Image.fromarray(labels).save(output/(name+'.labels.png'))
|
||||
colors=np.zeros((*labels.shape,3),dtype=np.uint8)
|
||||
colors[(labels==1)]=[20,220,170];colors[labels==0]=[220,40,50]
|
||||
Image.blend(image,Image.fromarray(colors),.45).save(output/(name+'.jpg'))
|
||||
ids,counts=np.unique(labels,return_counts=True)
|
||||
row=dict(case=name,source=source,utc=datetime.now(timezone.utc).isoformat(),monotonic=time.monotonic(),inference_seconds=elapsed,
|
||||
sidewalk_fraction=float((labels==1).mean()),road_fraction=float((labels==0).mean()),
|
||||
classes={model.config.id2label[int(i)]:int(n) for i,n in zip(ids,counts)})
|
||||
rows.append(row);(output/'results.json').write_text(json.dumps(rows,indent=2))
|
||||
print(json.dumps(row),flush=True)
|
||||
(output/'artifact-sha256.json').write_text(json.dumps({p.name:sha(p) for p in output.iterdir() if p.is_file()},indent=2))
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
@@ -0,0 +1,60 @@
|
||||
"""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()
|
||||
Reference in New Issue
Block a user