From b2a7e992c9eefb92c0d54195e46f4bd608bf28e0 Mon Sep 17 00:00:00 2001 From: BoazWasserman <49598618+boazwasserman@users.noreply.github.com> Date: Mon, 9 Nov 2026 18:46:25 +0200 Subject: [PATCH] Request FP16 TensorRT engine for ONNX detector with device Tensorrt (#24923) * Request FP16 TensorRT engine for ONNX detector with device Tensorrt get_ort_providers only enables trt_fp16_enable when requires_fp16 is passed, and the ONNX detector never passed it, so device: Tensorrt always built an FP32 engine. USE_FP16=False still disables FP16. Co-Authored-By: Claude Opus 5.5 * Make TensorRT FP16 opt-in via USE_FP16 only Drop the unused requires_fp16 parameter from get_ort_providers and decide trt_fp16_enable from the USE_FP16 environment variable alone, defaulting to false. Revert the ONNX detector change and document USE_FP16=true for device: Tensorrt. Co-Authored-By: Claude Opus 5.5 * Drop the TensorRT docs line The stock image ships only the TensorRT runtime, not the builder libraries needed to create engines, so the instructions were misleading. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- frigate/test/test_runner_devices.py | 30 +++++++++++++++++++++++++++++ frigate/util/model.py | 5 ++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/frigate/test/test_runner_devices.py b/frigate/test/test_runner_devices.py index aaee9f7ad5..cd6c76c69d 100644 --- a/frigate/test/test_runner_devices.py +++ b/frigate/test/test_runner_devices.py @@ -321,6 +321,36 @@ class TestLighterANE(unittest.TestCase): ane.assert_not_called() +class TestTensorRTProvider(unittest.TestCase): + def _trt_options(self, env): + with ( + patch.object( + model_util.ort, + "get_available_providers", + return_value=["TensorrtExecutionProvider", "CPUExecutionProvider"], + ), + patch.object(model_util.os, "makedirs"), + patch.dict(os.environ, env, clear=False), + ): + if "USE_FP16" not in env: + os.environ.pop("USE_FP16", None) + providers, options = model_util.get_ort_providers(device="Tensorrt") + + return options[providers.index("TensorrtExecutionProvider")] + + def test_fp16_is_disabled_by_default(self): + self.assertFalse(self._trt_options({})["trt_fp16_enable"]) + + def test_use_fp16_enables_fp16(self): + for value in ("true", "True", "TRUE"): + with self.subTest(value=value): + options = self._trt_options({"USE_FP16": value}) + self.assertTrue(options["trt_fp16_enable"]) + + def test_use_fp16_false_keeps_fp16_disabled(self): + self.assertFalse(self._trt_options({"USE_FP16": "False"})["trt_fp16_enable"]) + + class TestMIGraphX(unittest.TestCase): """AMD's MIGraphX plugin provider, selected through its devices in the ROCm image.""" diff --git a/frigate/util/model.py b/frigate/util/model.py index 8d34d422a5..fbf21ae432 100644 --- a/frigate/util/model.py +++ b/frigate/util/model.py @@ -318,7 +318,6 @@ def post_process_yolox( def get_ort_providers( force_cpu: bool = False, device: str | None = "AUTO", - requires_fp16: bool = False, ) -> tuple[list[str], list[dict[str, Any]]]: if force_cpu: return ( @@ -357,8 +356,8 @@ def get_ort_providers( options.append( { "device_id": device_id, - "trt_fp16_enable": requires_fp16 - and os.environ.get("USE_FP16", "True") != "False", + "trt_fp16_enable": os.environ.get("USE_FP16", "False").lower() + == "true", "trt_timing_cache_enable": True, "trt_engine_cache_enable": True, "trt_timing_cache_path": os.path.join(