Support TensorRT 10 and later in TensorRTEngineHandlerNumPy - #39922
Draft
akshayjadiyanv wants to merge 2 commits into
Draft
Support TensorRT 10 and later in TensorRTEngineHandlerNumPy#39922akshayjadiyanv wants to merge 2 commits into
akshayjadiyanv wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Beam's TensorRT model handler is written against the TensorRT 8.x binding API, which TensorRT 10 removed. Any pipeline using
TensorRTEngineHandlerNumPyon a modern TensorRT container fails immediately at engine load: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:num_bindings/get_binding_*/execute_async_v2.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.cudawas removed in favour ofcuda.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.nvcr.io/nvidia/tensorrt:23.05-py3(TensorRT 8.6, May 2023) to26.06-py3(TensorRT 11.0, CUDA 13.3, Python 3.12). Because that image is Python 3.12, the disabledtensorRTteststask moves from the py310 suite to the py312 suite.test_namespacehas asserted'RunInferenceTensorRT'since the original 2022 TensorRT commit, but the handler returns'BeamML_TensorRT', matching theBeamML_*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:
nvcr.io/nvidia/tensorrt:26.06-py3nvcr.io/nvidia/tensorrt:23.05-py3These 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
.trtfiles undergs://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 theTensorRTEngineHandlerNumPyin this PR:gs://apache-beam-ml/testing/inputs/tensorrt_image_file_names.txtand returns plausible detections (person,person,carat 0.77 / 0.61 / 0.57 on000000289594.jpg). Its I/O tensor order isnum_detections, detection_boxes, detection_scores, detection_classes, which is exactly whatPostProcessorindexes, so no example code change is required.Build environment: TensorRT 11.0.0.114 in
nvcr.io/nvidia/tensorrt:26.06-py3on a Tesla T4 (compute capability 7.5) matching the T4 the integration test requests.I am happy to hand these over.