Skip to content

Support TensorRT 10 and later in TensorRTEngineHandlerNumPy - #39922

Draft
akshayjadiyanv wants to merge 2 commits into
apache:masterfrom
akshayjadiyanv:tensorrt-version-compat
Draft

Support TensorRT 10 and later in TensorRTEngineHandlerNumPy#39922
akshayjadiyanv wants to merge 2 commits into
apache:masterfrom
akshayjadiyanv:tensorrt-version-compat

Conversation

@akshayjadiyanv

Copy link
Copy Markdown
Contributor

Beam's TensorRT model handler is written against the TensorRT 8.x binding API, which TensorRT 10 removed. Any pipeline using TensorRTEngineHandlerNumPy on a modern TensorRT container fails immediately at engine load:

AttributeError: 'tensorrt.tensorrt.ICudaEngine' object has no attribute 'num_bindings'

Two users have reported this, and both reports were closed as stale without a fix: addresses #36306 and addresses #33946.

Approach: support both APIs, rather than upgrading

This PR selects the API at runtime from the TensorRT major version instead. _trt_major_version() is the single switch:

  • TensorRT 8.x keeps num_bindings / get_binding_* / execute_async_v2.
  • TensorRT 10 and later use num_io_tensors / get_tensor_* / set_tensor_address / execute_async_v3.

No currently supported GPU loses support, and Blackwell works for the first time.

Also included

  • cuda-python 13 compatibility. cuda.cuda was removed in favour of cuda.bindings.driver. _import_cuda_driver() handles both. The new container ships cuda-python 13, so without this the upgrade fails for a second, unrelated reason.
  • Test container bumped from nvcr.io/nvidia/tensorrt:23.05-py3 (TensorRT 8.6, May 2023) to 26.06-py3 (TensorRT 11.0, CUDA 13.3, Python 3.12). Because that image is Python 3.12, the disabled tensorRTtests task moves from the py310 suite to the py312 suite.
  • Two guard tests so the version check cannot silently drift from the API it selects.
  • A pre-existing test bug, in its own commit. test_namespace has asserted 'RunInferenceTensorRT' since the original 2022 TensorRT commit, but the handler returns 'BeamML_TensorRT', matching the BeamML_* prefix every other handler uses. It has been wrong for three years and nobody noticed, which is itself a sign of how long this area has gone unexercised.

Testing

Run on a real T4 GPU on GCE in both containers:

Container TensorRT Result
nvcr.io/nvidia/tensorrt:26.06-py3 11.0.0 (new path) 7 / 7 pass
nvcr.io/nvidia/tensorrt:23.05-py3 8.6.1 (old path) 7 / 7 pass

These are the tests that build engines in process. The tests that read pre-built engines from gs://apache-beam-ml/ were not run - see below.

What this PR does not fix

The Dataflow integration test (tensorRTtests) stays disabled in this PR, and #33078 stays open. But the missing piece now exists and only needs a committer to stage it.

A serialized TensorRT engine can only be deserialized by the major version that built it. All three .trt files under gs://apache-beam-ml/models/ were built with TensorRT 8.x in 2022, so none of them load on the new container regardless of this change. Staging replacements needs write access to that bucket, which I do not have.

I have rebuilt and verified all three, and can pass them on to whoever picks up #33078.

Each was rebuilt from the ONNX source already staged in gs://apache-beam-ml/models/ — no new model sources are needed — and verified by loading it through the TensorRTEngineHandlerNumPy in this PR:

  • The two small engines return the exact values the unit tests assert.
  • The SSD MobileNet engine was run against both COCO images in gs://apache-beam-ml/testing/inputs/tensorrt_image_file_names.txt and returns plausible detections (person, person, car at 0.77 / 0.61 / 0.57 on 000000289594.jpg). Its I/O tensor order is num_detections, detection_boxes, detection_scores, detection_classes, which is exactly what PostProcessor indexes, so no example code change is required.

Build environment: TensorRT 11.0.0.114 in nvcr.io/nvidia/tensorrt:26.06-py3 on a Tesla T4 (compute capability 7.5) matching the T4 the integration test requests.

I am happy to hand these over.

test_namespace has asserted 'RunInferenceTensorRT' since the original
TensorRT commit (a8ca305). The handler was later changed to return
'BeamML_TensorRT' in f477b85, matching the BeamML_* prefix that every
other model handler uses, but the test was never updated.

The mismatch went unnoticed because the TensorRT suite does not run in any
active CI job.
TensorRT 10 removed the index based binding API that the handler was written
against, so RunInference fails at engine load time with:

  AttributeError: 'ICudaEngine' object has no attribute 'num_bindings'

Select the API at runtime from the TensorRT major version rather than picking
one of them. TensorRT 8.x keeps the binding API and execute_async_v2, while
TensorRT 10 and later use the name based tensor API and execute_async_v3. No
currently supported GPU loses support.

Supporting both versions is necessary rather than merely convenient. Dataflow
now offers Blackwell GPUs (RTX Pro 6000, compute capability 12.0) that no
TensorRT 8.x release can target, while TensorRT 10 and later require compute
capability 7.5 or higher and so cannot target the Pascal and Volta GPUs that
Dataflow still offers. No single TensorRT version covers the whole range.

Also handle cuda-python 13, which removed the cuda.cuda alias in favour of
cuda.bindings.driver, and move the test container to
nvcr.io/nvidia/tensorrt:26.06-py3 (TensorRT 11.0, CUDA 13.3, Python 3.12).
Because that image is Python 3.12, the disabled tensorRTtests task moves from
the py310 suite to the py312 suite.

The Dataflow integration test stays disabled. Every .trt engine staged under
gs://apache-beam-ml/models/ was built with TensorRT 8.x, and a serialized
engine can only be read by the major version that built it. Rebuilt and
verified replacements are available, but staging them needs write access to
that bucket; see the pull request description.

Verified on a T4 GPU on GCE: 7/7 tests pass under TensorRT 11.0
(nvcr.io/nvidia/tensorrt:26.06-py3) and 7/7 under TensorRT 8.6.1 (23.05-py3).

Addresses apache#36306
Addresses apache#33946
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant