Registry / ai-ml / tensorrt

tensorrt

JSON →
library11.0.0.114pypypiunverified

NVIDIA TensorRT is a Python library and C++ SDK for high-performance deep learning inference. It optimizes trained neural networks for deployment on NVIDIA GPUs, focusing on throughput, latency, and memory efficiency. The current version is 10.16.1.11. NVIDIA typically releases minor updates to TensorRT frequently, often monthly or bi-monthly, with major versions released annually.

pip install tensorrt numpy cuda-python
INSTALL
IMPORT
SIG · TENSORRT
T
tensorrt
ai-mlpythonv11.0.0.114
Install
64.3s avg
Import
600ms
Disk
4526MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v11.0.0.114 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
installs and imports cleanly · install 64.3s · import 0.600s · 4505.6MB
4526MB installed
● package 4526MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tensorrt
import tensorrt as trt
Standard alias for brevity.
Logger
from tensorrt import Logger
Accessing the main logger class.
cudart
from cuda import cudart
For CUDA Runtime API calls, using the 'cuda-python' library.
Builder
trt.Builder
Used to create and configure TensorRT engines.
NetworkDefinitionCreationFlag
trt.NetworkDefinitionCreationFlag
Enum for network creation flags, e.g., EXPLICIT_BATCH.

This quickstart demonstrates how to build a simple TensorRT engine for an identity operation. It uses the `cuda-python` library for CUDA memory management, reflecting modern TensorRT usage. The process involves creating a logger, builder, network definition, configuration, defining input/output tensors, building the engine, and then performing a basic inference with device memory management.

import tensorrt as trt import numpy as np from cuda import cudart # Using cuda-python as per release notes # 1. Create Logger TRT_LOGGER = trt.Logger(trt.Logger.WARNING) def build_engine(): # 2. Create Builder builder = trt.Builder(TRT_LOGGER) # 3. Create NetworkDefinition # EXPLICIT_BATCH is required for dynamic shapes or when batch size is a dimension network = builder.create_network(1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)) # 4. Create BuilderConfig config = builder.create_builder_config() config.max_workspace_size = 1 << 20 # 1 MiB # Define input tensor (e.g., a simple 1x3x16x16 input) input_tensor = network.add_input(name="input_tensor", dtype=trt.float32, shape=(1, 3, 16, 16)) # Add an identity layer (input -> output directly) output_tensor = network.add_identity(input_tensor).get_output(0) # 6. Mark output network.mark_output(output_tensor) output_tensor.name = "output_tensor" # Build and return the engine engine = builder.build_engine(network, config) if not engine: raise RuntimeError("Failed to build TensorRT engine") return engine def main(): engine = None runtime = None context = None device_input = None device_output = None try: engine = build_engine() print("TensorRT engine built successfully!") # Create runtime and execution context runtime = trt.Runtime(TRT_LOGGER) # For demonstration, we use the already built engine. In real apps, you might deserialize. context = engine.create_execution_context() # Prepare input data host_input = np.random.rand(1, 3, 16, 16).astype(np.float32) host_output = np.empty_like(host_input) # Output shape is same as input for identity # Allocate device memory _, device_input = cudart.cudaMalloc(host_input.nbytes) _, device_output = cudart.cudaMalloc(host_output.nbytes) # Copy input to device cudart.cudaMemcpy(device_input, host_input.ctypes.data, host_input.nbytes, cudart.cudaMemcpyKind.cudaMemcpyHostToDevice) # Execute inference # The execute_v2 takes an iterable of device pointers in the order of inputs and outputs bindings = [int(device_input), int(device_output)] context.execute_v2(bindings) # Copy output back to host cudart.cudaMemcpy(host_output.ctypes.data, device_output, host_output.nbytes, cudart.cudaMemcpyKind.cudaMemcpyDeviceToHost) print(f"Input shape: {host_input.shape}") print(f"Output shape: {host_output.shape}") print(f"Input (first 5 elements): {host_input.flatten()[:5]}") print(f"Output (first 5 elements): {host_output.flatten()[:5]}") except Exception as e: print(f"An error occurred: {e}") finally: # Clean up resources if device_input: cudart.cudaFree(device_input) if device_output: cudart.cudaFree(device_output) if context: del context if engine: del engine if runtime: del runtime if __name__ == "__main__": main()
Debug
Known issues
breakingTensorRT 10.13.2 and later dropped support for CUDA 11.x, Ubuntu 20.04, and Python versions older than 3.10. Ensure your environment meets the minimum requirements.
fix
Upgrade your CUDA toolkit to 12.x or later, your OS to Ubuntu 22.04 or later, and your Python environment to 3.10 or later.
affects: >=10.13.2
breakingStarting with TensorRT 10.14, samples are no longer bundled with the Python packages and are instead available exclusively in the NVIDIA/TensorRT GitHub repository. Additionally, usage of `pycuda` has been replaced by `cuda-python` for CUDA API interactions.
fix
Refer to the official NVIDIA/TensorRT GitHub repository for samples. Update your code to use `cuda-python` (e.g., `from cuda import cudart`) instead of `pycuda` for CUDA memory management and operations.
affects: >=10.14
deprecatedSeveral `IPluginV2` plugins (e.g., `cropAndResizeDynamic`, `DecodeBbox3DPlugin`, `modulatedDeformConvPlugin`) have been deprecated and migrated to `IPluginV3` versions. While `IPluginV2` versions might still work, they are slated for removal in future releases.
fix
Review plugin usage and migrate to the corresponding `IPluginV3` versions where available to ensure future compatibility. Consult TensorRT release notes for specific plugin migrations.
affects: >=10.12
gotchaThe `pip install tensorrt` command installs the Python bindings, but core TensorRT shared libraries (`libnvinfer.so`, `libnvinfer_plugin.so`, etc.) require a system-level installation of the TensorRT SDK, which must be compatible with your NVIDIA GPU driver, CUDA Toolkit, and cuDNN versions. Mismatched versions are a frequent source of errors.
fix
Follow the official NVIDIA TensorRT Installation Guide, ensuring you install the TensorRT SDK (via tarball, debian package, or Docker) with versions compatible with your system's CUDA, cuDNN, and GPU driver before running `pip install tensorrt`.
affects: All versions
Upgrade
Version history
11.0.0.114latest on PyPI · released May 27, 2026
Audit
Dependencies
nvidia-tensorrtrequiredCore TensorRT Python bindings, pulled by 'tensorrt' metapackage.
numpyrequiredRequired for array manipulation and data handling.
cuda-pythonrequiredRecommended for CUDA API interactions (e.g., memory management) instead of pycuda since TensorRT 10.14.
Agent activity
43 hits · last 30 days
node
42
OpenAI (training)
1
Resources