# SPDX-License-Identifier: Apache-2.0 """Host tests of the API wiring (no device): identity and runtime parameters, the host half of the hooks (``_build_host``, ``_prepare``, ``_postprocess``) against the stored CPU reference of the samples (the shipped ``test_pcd.npz`` and the staged PandaSet sample; compared with the container smoke's own comparator, ``ttaw.server.smoke``). ``from_pretrained`` on the fake ttnn (graph and runner built) is in ``test_tt_host.py``; the structured host knobs are in ``test_params_host.py``. TT_VISIBLE_DEVICES=none python -m pytest -q -p fake_ttnn_plugin code/tt_centerpoint/tests/test_api_host.py """ from __future__ import annotations import json import sys import numpy as np import pytest from tt_centerpoint import io as tio from tt_centerpoint.api import CenterPoint from tt_centerpoint.host.postprocess import RUNTIME_PARAMS from tt_centerpoint.reference.config import COMMON_PARAMS from tt_centerpoint.tests import _data from tt_centerpoint.ttaw.decode import AUTOWARE_LABELS from tt_centerpoint.ttaw.server import smoke def test_identity_and_runtime_params(): assert tuple(CenterPoint.VARIANTS) == ("base", "tiny") and CenterPoint.DEFAULT_VARIANT == "base" assert tuple(CenterPoint.LABELS) == AUTOWARE_LABELS and CenterPoint.LABELS[7] == "PEDESTRIAN" assert CenterPoint.RUNTIME_PARAMS is RUNTIME_PARAMS p = CenterPoint.validate_params({}) assert p["score_threshold"] is None and p["remap_classes"] is True and p["max_detections"] is None for k in ("circle_nms_dist_threshold", "iou_nms_threshold", "iou_nms_search_distance_2d"): assert p[k] == COMMON_PARAMS[k] # Autoware's defaults assert CenterPoint.validate_params({"score_threshold": "0.5"})["score_threshold"] == 0.5 for bad in ({"score_threshold": 1.0}, {"remap_classes": 1}, {"max_detections": 0}, {"iou_nms_threshold": 1.5}): with pytest.raises(tio.InputError): CenterPoint.validate_params(bad) def _host_model(variant: str) -> CenterPoint: m = CenterPoint.__new__(CenterPoint) # no device: the host half only m.weights_path = _data.weights_dir() m.variant = variant m._build_host() return m @pytest.mark.parametrize("variant,sample", [("tiny", "test_pcd"), ("base", "test_pcd"), ("tiny", "pandaset_019_f40")]) def test_hooks_reproduce_the_stored_reference(variant, sample): torch = pytest.importorskip("torch") from tt_centerpoint.reference.model import CenterPointTorch from tt_centerpoint.reference.weights import load_weights torch.set_num_threads(2) m = _host_model(variant) prep = m._prepare(points=_data.sample_path(f"{sample}.npz")) net = CenterPointTorch(load_weights(m.weights_path, variant), threads=2) heads = net.forward(prep.features, prep.coords, prep.num_pillars, m.config.grid_x, m.config.grid_y) out = m._postprocess(heads, prep, m.validate_params({})) body = out.to_dict() ref = json.loads(_data.sample_path(f"{sample}.{variant}.reference.json").read_text()) metrics, fails = smoke.compare_with_reference(body, ref, gates={"max_center_dist": 0.01, "min_recall": 1.0, "min_precision": 1.0, "max_score_err": 1e-4}) assert fails == [], (fails, metrics) assert body["meta"]["counts"] == ref["meta"]["counts"] and body["meta"]["variant"] == variant assert body["meta"]["num_pillars"] == ref["meta"]["num_pillars"] assert len(body["meta"]["orientation_availability"]) == body["num_detections"] def test_prepare_refuses_images_and_missing_points(): m = _host_model("tiny") with pytest.raises(tio.InputError): m._prepare(points=None) with pytest.raises(tio.InputError, match="point cloud only"): m._prepare(points=np.zeros((3, 3), np.float32), images=[{"camera": "front"}])