Speeding Up Deep Learning Inference Using NVIDIA TensorRT (Updated)

This post was updated July 20, 2021 to reflect NVIDIA TensorRT 8.0 updates. NVIDIA TensorRT is an SDK for deep learning inference. TensorRT provides APIs and…

Overview

The article provides an updated guide on using NVIDIA TensorRT 8.0 for speeding up deep learning inference. It covers the process of deploying a deep learning application on a GPU, converting models from PyTorch to ONNX, and optimizing them for high-performance inference in various environments.

What You'll Learn

1

How to convert a PyTorch model into ONNX format for TensorRT

2

How to optimize deep learning models for inference using TensorRT

3

How to perform inference on a GPU with TensorRT

Prerequisites & Requirements

  • Installation of TensorRT and a CUDA-capable GPU
  • Basic understanding of deep learning frameworks like PyTorch

Key Questions Answered

How can I speed up deep learning inference using NVIDIA TensorRT?
You can speed up deep learning inference by using NVIDIA TensorRT to optimize your models for deployment. This involves converting your trained models from frameworks like PyTorch to ONNX format, importing them into TensorRT, applying optimizations, and generating a high-performance runtime engine for inference on GPUs.
What are the requirements for using TensorRT?
To use TensorRT, you need a computer with a CUDA-capable GPU or a cloud instance with GPUs, along with an installation of TensorRT. The article recommends using a specific PyTorch container with TensorRT integration for optimal results.
What steps are involved in the TensorRT optimization process?
The optimization process involves converting a pretrained model into ONNX format, importing the ONNX model into TensorRT, applying optimizations, and generating an optimized engine for inference. This process ensures that the model runs efficiently on the target hardware.
How does batching inputs improve performance in TensorRT?
Batching inputs allows multiple images to be processed simultaneously, which improves GPU utilization and reduces overall inference time. Larger batch sizes can lead to more efficient computations, especially on supported hardware like Volta and Turing GPUs.

Key Statistics & Figures

Inference batch size average time
2.21147ms
This is the average time taken for inference with a batch size of 1 over 10 runs.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Key Actionable Insights

1
Utilize the ONNX format for model interoperability between frameworks.
Using ONNX allows you to easily transfer models between different deep learning frameworks, enhancing flexibility in your workflow.
2
Experiment with mixed precision to enhance performance.
By using FP16 or INT8 precision, you can significantly reduce memory usage and increase inference speed without a substantial loss in accuracy.
3
Profile your application to identify performance bottlenecks.
Measuring latency and throughput can help you understand where optimizations are needed, allowing you to make informed decisions on resource allocation and model adjustments.

Common Pitfalls

1
Neglecting to optimize the workspace size can lead to suboptimal performance.
If the workspace size is set too low, TensorRT may not be able to select the best algorithms for your model, leading to slower inference times.
2
Not utilizing batching effectively can waste GPU resources.
Failing to batch inputs can lead to underutilization of GPU capabilities, resulting in longer inference times and reduced throughput.

Related Concepts

Deep Learning Optimization
Model Conversion Techniques
Performance Profiling In Cuda