TensorRT Optimization on Jetson Orin

A practical guide to squeezing maximum inference performance from Jetson Orin using NVIDIA TensorRT — model conversion, INT8 calibration, layer fusion, and real benchmarks.

Why TensorRT Matters

Running models on Jetson Orin AI hardware through standard frameworks like ONNX Runtime or even llama.cpp gives you good performance. But TensorRT — NVIDIA's dedicated inference optimizer and runtime — can take that performance to an entirely different level. We've measured 2–4× throughput improvements for vision models and 30–50% latency reductions for LLMs after TensorRT optimization, with no change to model architecture.

The magic comes from several optimizations that TensorRT applies automatically: layer fusion (combining consecutive operations into single kernels), precision calibration (INT8 without accuracy loss), kernel auto-tuning (selecting optimal implementations for the specific GPU architecture), and memory optimization (minimizing tensor allocations and data movement). For Orin desktop AI setup users who want the fastest possible inference, TensorRT is the key unlock.

Before diving into TensorRT, make sure your Jetson Orin hardware is running at MAXN power mode — TensorRT optimizations shine brightest when the full GPU is available.

Performance Impact (AGX 64GB, MAXN): YOLOv8-medium: 32 FPS (ONNX) → 78 FPS (TensorRT FP16). Whisper large-v3: 2.8× realtime (ONNX) → 4.6× realtime (TensorRT FP16). Llama 3.1 8B: 21.8 tok/s (llama.cpp Q4) → 28.3 tok/s (TensorRT-LLM FP8). These are real, measured improvements.

TensorRT Pipeline Overview

The TensorRT workflow follows a consistent pattern regardless of model type:

  1. Export your trained model to ONNX format (the universal interchange format)
  2. Parse the ONNX model with TensorRT to create a network definition
  3. Optimize by selecting precision (FP32, FP16, INT8), applying layer fusion, and tuning kernels
  4. Build a serialized TensorRT engine — an optimized, platform-specific binary
  5. Deploy the engine and run inference with the TensorRT runtime API

For Jetson private AI deployments where every watt and millisecond counts, the engine build step is done once (on the target hardware, since TensorRT engines are architecture-specific) and the resulting binary is deployed to production. Engine builds can take 5–30 minutes depending on model complexity, but inference is dramatically faster.

Converting a Vision Model (YOLOv8)

Let's walk through a complete TensorRT optimization for YOLOv8 — one of the most common vision models deployed on Jetson Orin.

# Step 1: Export YOLOv8 to ONNX
$ pip install ultralytics onnx onnxruntime
$ python3 -c "
from ultralytics import YOLO
model = YOLO('yolov8m.pt')
model.export(format='onnx', imgsz=640, opset=17, simplify=True)
"

# Step 2: Convert ONNX to TensorRT engine (FP16)
$ /usr/src/tensorrt/bin/trtexec \
  --onnx=yolov8m.onnx \
  --fp16 \
  --saveEngine=yolov8m_fp16.engine \
  --workspace=4096

# Step 3: Benchmark
$ /usr/src/tensorrt/bin/trtexec \
  --loadEngine=yolov8m_fp16.engine \
  --iterations=1000
# Output: Throughput: 78.3 qps | Latency: 12.8 ms (batch=1)

INT8 Calibration for Maximum Speed

INT8 precision can double throughput again compared to FP16 — but it requires calibration to avoid accuracy loss. Calibration feeds representative data through the model, measuring activation ranges so TensorRT can scale values into the narrower INT8 range with minimal quantization error.

# INT8 calibration script (Python)
import tensorrt as trt
import pycuda.driver as cuda

# Build with INT8 calibration
config = builder.create_builder_config()
config.set_flag(trt.BuilderFlag.INT8)
config.set_flag(trt.BuilderFlag.FP16) # Fallback for non-INT8 layers
config.int8_calibrator = MyCalibrator(calibration_data)

# Calibrator feeds ~500 representative images through the network
# Measuring activation distributions per-layer for optimal quantization

Calibration Data Tip: You only need 200–1000 representative samples for good INT8 calibration — not your entire training set. The samples should cover the diversity of real-world inputs (different lighting conditions, object scales, backgrounds for vision models). For NLP models, a diverse set of 500–1000 text samples from your target domain works well.

TensorRT-LLM for Large Language Models

TensorRT-LLM is NVIDIA's specialized framework for optimizing LLM inference. Unlike the general TensorRT workflow, TensorRT-LLM understands transformer architectures natively and applies LLM-specific optimizations: KV-cache management, in-flight batching, paged attention, and tensor parallelism across multiple GPUs (relevant for multi-Orin clusters).

# Build TensorRT-LLM engine for Llama 3.1 8B
$ python3 convert_checkpoint.py \
  --model_dir ./Llama-3.1-8B \
  --output_dir ./trt_checkpoint \
  --dtype float16

$ trtllm-build \
  --checkpoint_dir ./trt_checkpoint \
  --output_dir ./trt_engine \
  --gemm_plugin float16 \
  --max_batch_size 8 \
  --max_input_len 4096 \
  --max_output_len 2048

# Run inference:
$ python3 run.py --engine_dir ./trt_engine --max_output_len 512

On Orin AGX, TensorRT-LLM with FP16 precision achieves approximately 28 tokens/second with Llama 3.1 8B — a 30% improvement over llama.cpp Q4_K_M. The trade-off is that TensorRT-LLM engines are larger (13 GB vs 5.2 GB for Q4) and the build process is more complex. For Orin self-hosted AI servers where throughput matters more than storage efficiency, TensorRT-LLM is the clear winner.

Performance Benchmarks: Before and After TensorRT

ModelFramework (Before)ThroughputTensorRT (After)ThroughputSpeedup
YOLOv8-nanoONNX Runtime95 FPSTensorRT FP16187 FPS1.97×
YOLOv8-mediumONNX Runtime32 FPSTensorRT FP1678 FPS2.44×
ResNet-50PyTorch215 img/sTensorRT INT8620 img/s2.88×
Whisper large-v3ONNX Runtime2.8× RTTensorRT FP164.6× RT1.64×
Llama 3.1 8Bllama.cpp Q421.8 tok/sTRT-LLM FP1628.3 tok/s1.30×
BERT-baseONNX Runtime125 seq/sTensorRT FP16380 seq/s3.04×

When NOT to Use TensorRT

TensorRT is powerful but not always the right choice. The engine build process is time-consuming and hardware-specific — you can't build an engine on x86 and deploy to Orin (aarch64). For rapid prototyping where you're iterating on models frequently, the build overhead outweighs the inference speedup. Similarly, for one-off inference tasks where the model runs once and you move on, TensorRT's build cost isn't justified.

For most Orin persistent server deployments where models run continuously, the build cost is amortized over millions of inferences, making TensorRT optimization a clear win. The Jetson Orin guide series includes decision flowcharts to help you determine when TensorRT optimization is worth the investment for your specific use case.

Integration with Existing Infrastructure

TensorRT engines integrate cleanly with Triton Inference Server — NVIDIA's production-grade model serving framework. Triton handles dynamic batching, model versioning, health checks, and Prometheus metrics export, while TensorRT engines provide the raw inference performance. For Orin AI server builds, the Triton + TensorRT combination is the gold standard for production vision and NLP pipelines.

ClawBox users benefit from this optimization automatically — the ClawBox vs Jetson Orin comparison for TensorRT is straightforward: ClawBox pre-builds optimized engines for popular models, saving you the build time but limiting you to their curated model selection. Raw Orin users doing ClawBox Orin comparison get full control over which models get TensorRT-optimized, at the cost of hands-on build effort. The NVIDIA Orin developer documentation covers TensorRT internals in depth for those who need to understand every optimization pass.