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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
BoazWasserman
2026-11-09 09:46:25 -07:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 11f4dd194c
commit b2a7e992c9
2 changed files with 32 additions and 3 deletions
+30
View File
@@ -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."""
+2 -3
View File
@@ -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(