Torch-TensorRT
Easily achieve the best inference performance for any PyTorch model on the NVIDIA platform.
Torch-TensorRT brings the power of TensorRT to PyTorch. Accelerate inference latency by up to 5x compared to eager execution in just one line of code.
Installation
Stable versions of Torch-TensorRT are published on PyPI
pip install torch-tensorrt
Nightly versions of Torch-TensorRT are published on the PyTorch package index
pip install --pre torch-tensorrt --index-url https://download.pytorch.org/whl/nightly/cu130 --extra-index-url https://pypi.org/simple
Torch-TensorRT is also distributed in the ready-to-run NVIDIA NGC PyTorch Container which has all dependencies with the proper versions and example notebooks included.
For more advanced installation methods, please see here
Quickstart
Option 1: torch.compile
You can use Torch-TensorRT anywhere you use torch.compile:
import torch
import torch_tensorrt
model = MyModel().eval().cuda() # define your model here
x = torch.randn((1, 3, 224, 224)).cuda() # define what the inputs to the model will look like
optimized_model = torch.compile(model, backend="tensorrt")
optimized_model(x) # compiled on first run
optimized_model(x) # this will be fast!
Option 2: Export
If you want to optimize your model ahead-of-time and/or deploy in a C++ environment, Torch-TensorRT provides an export-style workflow that serializes an optimized module. This module can be deployed in PyTorch or with libtorch (i.e. without a Python dependency).
Step 1: Optimize + serialize
import torch
import torch_tensorrt
model = MyModel().eval().cuda() # define your model here
inputs = [torch.randn((1, 3, 224, 224)).cuda()] # define a list of representative inputs here
trt_gm = torch_tensorrt.compile(model, ir="dynamo", inputs=inputs)
torch_tensorrt.save(trt_gm, "trt.ep", inputs=inputs) # PyTorch only supports Python runtime for an ExportedProgram. For C++ deployment, use a TorchScript file
torch_tensorrt.save(trt_gm, "trt.ts", output_format="torchscript", inputs=inputs)
Step 2: Deploy
Deployment in PyTorch:
import torch
import torch_tensorrt
inputs = [torch.randn((1, 3, 224, 224)).cuda()] # your inputs go here
# You can run this in a new python session!
model = torch.export.load("trt.ep").module()
# model = torch_tensorrt.load("trt.ep").module() # this also works
model(*inputs)
Deployment in C++:
#include "torch/script.h"
#include "torch_tensorrt/torch_tensorrt.h"
auto trt_mod = torch::jit::load("trt.ts");
auto input_tensor = [...]; // fill this with your inputs
auto results = trt_mod.forward({input_tensor});
Further resources
- Double PyTorch Inference Speed for Diffusion Models Using Torch-TensorRT
- Up to 50% faster Stable Diffusion inference with one line of code
- Optimize LLMs from Hugging Face with Torch-TensorRT
- Run your model in FP8 with Torch-TensorRT
- Accelerated Inference in PyTorch 2.X with Torch-TensorRT
- Tools to resolve graph breaks and boost performance [coming soon]
- Tech Talk (GTC '23)
- Documentation
Platform Support
| Platform | Support |
|---|---|
| Linux AMD64 / GPU | Supported |
| Linux SBSA / GPU | Supported |
| Windows / GPU | Supported (Dynamo only) |
| Linux Jetson / GPU | Source Compilation Supported on JetPack-4.4+ |
| Linux Jetson / DLA | Source Compilation Supported on JetPack-4.4+ |
| Linux ppc64le / GPU | Not supported |
Note: Refer NVIDIA L4T PyTorch NGC container for PyTorch libraries on JetPack.
Dependencies
These are the following dependencies used to verify the testcases. Torch-TensorRT can work with other versions, but the tests are not guaranteed to pass.
- Bazel 8.1.1
- Libtorch 2.14.0.dev (latest nightly)
- CUDA 13.2
- TensorRT 11.1.0.106
Deprecation Policy
Deprecation is used to inform developers that some APIs and tools are no longer recommended for use. Beginning with version 2.3, Torch-TensorRT has the following deprecation policy:
Deprecation notices are communicated in the Release Notes. Deprecated API functions will have a statement in the source documenting when they were deprecated. Deprecated methods and classes will issue deprecation warnings at runtime, if they are used. Torch-TensorRT provides a 6-month migration period after the deprecation. APIs and tools continue to work during the migration period. After the migration period ends, APIs and tools are removed in a manner consistent with semantic versioning.
Contributing
Take a look at the CONTRIBUTING.md
License
The Torch-TensorRT license can be found in the LICENSE file. It is licensed with a BSD Style licence
Release files for torch-tensorrt 2.14.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 53.7 MB
Release files / torch_tensorrt-2.14.0-cp314-cp314-win_amd64.whl
| Download URL | torch_tensorrt-2.14.0-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
2e9c47af74cbd0e0dfd22d37903a6dd2ac36b27ea03133f704ddccfc0bfb6965
|
|
BLAKE2b-256 checksum How to use checksums |
0c0f3e48917613f0b6a854578ed845a3a0acc24aaa444d37c41e39ef682f0555
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp314-cp314-manylinux_2_28_x86_64.whl
| Download URL | torch_tensorrt-2.14.0-cp314-cp314-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.14 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
636f7547c07a6ee105b1e9f1135f162b208f7e2e1a48a81b12f5fbf2f12add5f
|
|
BLAKE2b-256 checksum How to use checksums |
f7a1253f6f2fa451e9ae179289c12bc57b6107dca5a090560b2bc8494b789964
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp314-cp314-manylinux_2_28_aarch64.whl
| Download URL | torch_tensorrt-2.14.0-cp314-cp314-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 4.2 MB |
| Tags | CPython 3.14 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
7b33749c8f2918f6c214e57d34851b43077ed12d64aed20e727b8e8c924025e2
|
|
BLAKE2b-256 checksum How to use checksums |
4a8220805ba658494b89f8cebaa95d25697a09c313bc7c438d43a459bacfb58a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp313-cp313-win_amd64.whl
| Download URL | torch_tensorrt-2.14.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
b2adde69b858a3df64d8cb8e908a3dabea0377bc7529b24e8dc5ff54c41652a3
|
|
BLAKE2b-256 checksum How to use checksums |
69ca6307c07774ab00ff8a837e6b66edb8149b1158568ebeca1ce5aebd1a3ce6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | torch_tensorrt-2.14.0-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
c0c67f6b62b8028064e2ef54bddc8ea05f1fac9f46c17fb45ad66a078cece5f1
|
|
BLAKE2b-256 checksum How to use checksums |
dff6107a081f7dbec9f89cd18ddf14f64d28296cfe6781184e7e9b8a285194e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp313-cp313-manylinux_2_28_aarch64.whl
| Download URL | torch_tensorrt-2.14.0-cp313-cp313-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 4.2 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
93cf2c4e8e467359a5d66578f07a2eca5e2439ccda53ed39b5cbe546ed156702
|
|
BLAKE2b-256 checksum How to use checksums |
7a6ae43307494e7b7e3018524906b2000bc3198e060010e34d5dbe1518f49a0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp312-cp312-win_amd64.whl
| Download URL | torch_tensorrt-2.14.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
70683e7ab38b96afd5ecac68c0dc918d54db055920761dd9f4b5697316bd390c
|
|
BLAKE2b-256 checksum How to use checksums |
4d5ecb00646d4ea6a77d8bc98b26da117794dccd744302077a9bfcabc195eafa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | torch_tensorrt-2.14.0-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
2c03ae5f26a513fd5213a4e20d857b3cff13627b916e251987ca213ac873fa57
|
|
BLAKE2b-256 checksum How to use checksums |
1514a9700b69d626bf6c087927f27a8992083ce509b02e4dd82596481228787c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp312-cp312-manylinux_2_28_aarch64.whl
| Download URL | torch_tensorrt-2.14.0-cp312-cp312-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 4.2 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
15c1481225c28e0d3a300b247b4eb10b217765e617f983bf740b870267d63ece
|
|
BLAKE2b-256 checksum How to use checksums |
d6ffb661b1fdf84a71005888413827971ca416bca225ae508b7b0af86d320db5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp311-cp311-win_amd64.whl
| Download URL | torch_tensorrt-2.14.0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
e909b56a0036fc1cbef1ef0a6e0502c51626d00c25be1e8829c0c6fba74ec72d
|
|
BLAKE2b-256 checksum How to use checksums |
a0ce2053673bade076739ccb8e145e8c71ba432cee42f4fd640c6ff92d0e988c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | torch_tensorrt-2.14.0-cp311-cp311-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
12756addfacb326d0ff99aa9f35c1534954d73afaea8492472d95b389101d707
|
|
BLAKE2b-256 checksum How to use checksums |
f219c6322d714de39948a369efe9d2d9158b03a5f7a82f9a4153a200b58375ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp311-cp311-manylinux_2_28_aarch64.whl
| Download URL | torch_tensorrt-2.14.0-cp311-cp311-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 4.2 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
d0a5c217670e8ad129cf82d2b2ba930ae50b896310b16fb90d5e1e1f235d5b94
|
|
BLAKE2b-256 checksum How to use checksums |
0c9d3c92e50602668523679a9f71dd8648fa76adbe70fc192a6d771fdee48af6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp310-cp310-win_amd64.whl
| Download URL | torch_tensorrt-2.14.0-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
d897656662bf3aa280bc452fa46b3e2c0de76e10dc484898f7c031c0af38c85b
|
|
BLAKE2b-256 checksum How to use checksums |
8947046bc90b5c9ed0e4befad27a7cf2fcde7e4ef11dad0e99c0973734998766
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp310-cp310-manylinux_2_28_x86_64.whl
| Download URL | torch_tensorrt-2.14.0-cp310-cp310-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
b441a8025952f1341e7f183d801938706c38cd89f094264d5ecb6bf920ba71e8
|
|
BLAKE2b-256 checksum How to use checksums |
8a3612ba521b4f26f59ef07c61bcd3dde074e3e4a95b6ca4ffb95f519799833a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / torch_tensorrt-2.14.0-cp310-cp310-manylinux_2_28_aarch64.whl
| Download URL | torch_tensorrt-2.14.0-cp310-cp310-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 4.2 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
307831518b21a100c0c3cc37e2740f790a47854a63ca48962d01296fe3dfa4ac
|
|
BLAKE2b-256 checksum How to use checksums |
7971532268a98b9a1dc8b197a2184f8d59b3b8bb1c9745802e70a5324047d758
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|