# SPDX-License-Identifier: Apache-2.0 """Runtime valid-frame count through DepthPro2Device(engine="enc=mk"): one T = max_frames program per bucket serves every n <= T clip (n frames of clip4_240x320 vs the float32 reference of the same n-frame clip), and the model compiles only T in {max_frames, 1}. bin/devrun -t 1800 -- python -u bundles/depthpro2/code/tt_depthpro2/tests/mk_enc_vf_e2e.py --size S """ from __future__ import annotations import argparse import json import os import sys import torch sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))) from tt_depthpro2.reference import model as ref # noqa: E402 from tt_depthpro2.tests import baseline_helpers as BH # noqa: E402 def main(): ap = argparse.ArgumentParser() ap.add_argument("--size", default="S") ap.add_argument("--case", default="clip4_240x320") args = ap.parse_args() import ttnn from tt_depthpro2.tt.model import DepthPro2Device, planned_frames g, _ = BH.load_golden(args.case, args.size) x = g["x_norm"].float() T, _, h, w = x.shape wts = ref.load_safetensors(os.path.join(BH.size_dir(args.size), "model.safetensors")) cpu = ref.DepthPro2Reference(args.size, wts) dev = ttnn.open_device(device_id=0, dispatch_core_config=ttnn.DispatchCoreConfig(ttnn.DispatchCoreType.ETH), l1_small_size=BH.L1_SMALL_SIZE, trace_region_size=BH.TRACE_REGION_SIZE) ok = True try: xp = ref.pad_to_multiple(x) m = DepthPro2Device(dev, args.size, wts, None, buckets=[tuple(xp.shape[-2:])], max_frames=T, frames=(1,), engine="enc=mk") print("planned T:", planned_frames(T, (1,), clip_lengths="all", engine="enc=mk"), "compiled:", m.configurations()["depth"], flush=True) for n in range(1, T + 1): inv = m.inverse_depth(xp[:n])[:, :h, :w] with torch.no_grad(): r = cpu.inverse_depth(x[:n]) met = BH.drift_metrics(inv, r) good = met["pcc"] >= 0.999 and met["absrel_valid"] <= 0.01 ok = ok and good print(json.dumps({"size": args.size, "case": args.case, "n": n, "T_program": T if n > 1 else 1, "pcc_vs_fp32_ref": met["pcc"], "absrel_vs_fp32_ref": met["absrel_valid"], "passed": good}), flush=True) print("compiled after the n = 1..T calls:", m.configurations()["depth"], flush=True) m.close() finally: ttnn.close_device(dev) print("VF E2E PASS" if ok else "VF E2E FAIL", flush=True) if __name__ == "__main__": main()