TensorRT
TensorRT is a high-performance deep learning inference optimization SDK released by NVIDIA, built for extreme acceleration on its own GPUs. It compiles a trained model into a highly optimized inference engine (an engine file), typically several times faster than general framework inference on the same GPU, and is the first choice for latency-sensitive scenarios such as autonomous driving, video analytics and large model serving.
Core Principles
TensorRT's workflow is three steps: parse, optimize, serialize. First a parser (the ONNX Parser, Torch-TensorRT and so on) converts the model into an internal network representation; then a series of graph-level and layer-level optimizations are applied: layer fusion (merging Conv, BN and activation into a single kernel), precision calibration (FP32, FP16/INT8), kernel auto-tuning (selecting the fastest implementation for the specific GPU architecture from many candidates), tensor memory reuse (memory planning to reduce allocation overhead) and dynamic shape profiles (pre-compiling optimal plans for different batch sizes or sequence lengths).
The key mechanism is that the Builder stage is bound to a specific GPU: the generated engine is strongly tied to the GPU model, driver version and TensorRT version, and changing the card requires rebuilding. This brings extreme performance and also deployment complexity.
For large language models, TensorRT-LLM wraps capabilities such as KV Cache management, Paged Attention, in-flight batching and quantization (FP8/INT4 AWQ) on top of it, and supports multi-card tensor parallelism.
Key Points
1. Precision modes: FP32, FP16 (almost lossless, about 2 times faster), INT8 (requires calibration or PTQ, 3 to 4 times faster, with accuracy depending on the model), FP8 (Hopper and later architectures), INT4/FP4 (from Blackwell onwards).
2. Dynamic shapes: an optimization profile (min/opt/max, three shapes) must be defined, and an unreasonable profile causes a large performance drop; this is the most common tuning pitfall.
3. Comparison with ONNX Runtime: ORT is cross-hardware and easy to deploy; TensorRT runs only on NVIDIA GPUs but has a clearly higher performance ceiling on NVIDIA hardware, especially when combined with TensorRT-LLM for LLM inference.
4. Comparison with vLLM/TGI: the latter are serving frameworks for LLMs with better ease of use; TensorRT-LLM usually has the strongest performance but a high configuration barrier and strong ecosystem lock-in.
5. Plugin mechanism: unsupported operators can be implemented through custom plugins (such as early implementations of Flash Attention), but this increases maintenance cost.
Common Misconceptions
Misconception one is thinking an engine file can be copied freely; it is bound to the GPU and versions and is often unusable across machines. Misconception two is assuming INT8 always accelerates; small models or memory-bandwidth-limited models may see limited gains. Misconception three is ignoring profile configuration; when one sees "converting to TensorRT makes it slower", it is most often due to improperly set shape ranges or fallback to inefficient kernels. In addition, TensorRT does not train models and is not suited to the rapid iteration of the experimental stage.
Application Scenarios
Perception inference for autonomous driving, real-time video analytics and security, large-scale online LLM serving, real-time medical imaging inference, high-speed industrial visual inspection, robot vision, deployment on edge Jetson devices, and GPU inference cost optimization