changh95's picture
tt-model push meteor-2-p150 (container)
0f131e7 verified
Raw History Blame Contribute Delete
5.11 kB
# SPDX-License-Identifier: Apache-2.0
"""ASGI serving app of METEOR-2-p150 on one Tenstorrent Blackhole p150: the HTTP contract of the Autoware collection
(vendored ``ttaw.server.app``) bound to :class:`tt_meteor2.api.METEOR2`.
Served by tt-model-manager as ``kind: tt-dit-server``::
python -m uvicorn --host 0.0.0.0 --port <p> --lifespan on tt_meteor2.server.app:app
Routes: ``GET /``, ``/health`` and ``/v1/health`` (always 200: ``ok`` / ``starting`` / ``error``), ``/info``,
``/v1/models`` (stub), ``POST /predict``; errors 400 / 422 / 503 / 500. Everything that touches the device happens in
the lifespan (weights -> device -> graph -> trace capture), so uvicorn's ``Application startup complete`` means warm.
The form is the load-time variant (``METEOR2_VARIANT`` = ``gather`` | ``npu``, the two serve profiles).
METEOR 2's request adds four top-level fields to the common envelope (``images`` + ``calibration``): ``ego_speed``
(m/s, required), ``acc`` (m/s^2), ``ego_hist`` (32 numbers) and ``route`` (13 numbers), the graph's v0 / acc /
ego_hist / route as tt-autoware's ``meteor2_lib.py`` computes them (absent: zeros). Importing this module has no side
effects beyond importing fastapi and pydantic.
"""
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
from typing import Any, Dict, List, Mapping, Optional
from .. import __version__
from ..api import METEOR2
from ..ttaw import io as _tio
from ..ttaw.server.app import PredictRequest, ServerSpec, create_app, parse_mesh_shape # noqa: F401
# The eight cameras of a request are decoded in parallel: each entry goes through the vendored
# ``ttaw.io.decode_cameras`` on its own (same parsing, base64 limits, calibration merge), then the camera-order checks
# of the vendored function are applied to the whole set. 8 JPEG decodes of 768x432 (TIER IV demo frames) take
# 20 ms one after the other and 15-16 ms on the pool on this host: the decode holds the GIL for most of its time.
_SERIAL_DECODE = _tio.decode_cameras
_DECODE_POOL = ThreadPoolExecutor(8, thread_name_prefix="decode")
def decode_cameras_parallel(images, calibration=None, *, order=None, require_calibration=True, max_bytes=None):
images = list(images or [])
if len(images) < 2 or any(not isinstance(e, Mapping) or not e.get("camera") for e in images):
return _SERIAL_DECODE(images, calibration, order=order, require_calibration=require_calibration,
max_bytes=max_bytes)
out = list(_DECODE_POOL.map(lambda e: _SERIAL_DECODE([e], calibration, order=None,
require_calibration=require_calibration,
max_bytes=max_bytes)[0], images))
if order:
by_name = {c.name: c for c in out}
if len(by_name) != len(out):
raise _tio.InputError("duplicate camera names in images[]")
missing = [n for n in order if n not in by_name]
extra = [n for n in by_name if n not in order]
if missing or extra:
raise _tio.InputError(f"cameras must be exactly {list(order)}; missing {missing}, unexpected {extra}")
out = [by_name[n] for n in order]
return out
_tio.decode_cameras = decode_cameras_parallel
__all__ = ["SPEC", "app", "Meteor2Request", "parse_mesh_shape"]
class Meteor2Request(PredictRequest):
"""``POST /predict`` of METEOR 2: the common envelope + the ego inputs."""
ego_speed: Optional[float] = None
acc: Optional[float] = None
ego_hist: Optional[List[float]] = None
route: Optional[List[float]] = None
def decode_extra(req: Meteor2Request, kwargs: Dict[str, Any], max_bytes: int) -> None:
for name in ("ego_speed", "acc", "ego_hist", "route"):
value = getattr(req, name)
if value is not None:
kwargs[name] = value
SPEC = ServerSpec(
model_name=METEOR2.MODEL_NAME,
env_prefix=METEOR2.ENV_PREFIX,
model_cls=METEOR2,
task="multi-camera multi-task driving perception and end-to-end planning (METEOR 2)",
default_weights=METEOR2.DEFAULT_REPO,
owner="changh95",
io="eight surround-view camera images (16:9, e.g. 768x432 or 1152x648 RGB) with intrinsics and camera extrinsics, "
"the ego speed, acceleration, ego-motion history and route in; 3D boxes (vehicle / pedestrian) with parked "
"flags and 3-mode futures, a BEV lane map, 3D semantic occupancy, the ego-relevant traffic light and three ego "
"paths (3 s and 6 s) with steer / accel / brake out",
autoware={"package": "none (METEOR 2 has no Autoware node; tier4/METEOR is the upstream code)"},
source={"repo": "https://huggingface.co/changh95/METEOR-2-p150", "license": "Apache-2.0"},
calib_dir=Path(__file__).resolve().parents[1] / "calib",
version=__version__,
description="METEOR 2 (TIER IV, AutowareFoundation/meteor2 v1.0) on one Tenstorrent Blackhole p150, both "
"released forms (gather, npu). Not an OpenAI-compatible API.",
request_model=Meteor2Request,
decode_extra=decode_extra,
)
app = create_app(SPEC)