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
Metadata
Release files for torch-tensorrt-rtx 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: 29.6 MB
Release files / torch_tensorrt_rtx-2.14.0-cp314-cp314-win_amd64.whl
| Download URL | torch_tensorrt_rtx-2.14.0-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
7bf7341df1bd8eddd3ff05052fdc6bc98911ed83fe6f3b118c5fac255c175f90
|
|
BLAKE2b-256 checksum How to use checksums |
75ae638ac98ad9a5242de4a6d806cc756c129cc0ff9eac50f34272c6988ff773
|
| 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_rtx-2.14.0-cp314-cp314-manylinux_2_28_x86_64.whl
| Download URL | torch_tensorrt_rtx-2.14.0-cp314-cp314-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 3.9 MB |
| Tags | CPython 3.14 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
4a8420ba086021367bb9569f57942b138198afb03d7c72b29dde5d01657c8994
|
|
BLAKE2b-256 checksum How to use checksums |
701797f4d2eb537aa0ae7f00abe3694bb88331988605171c6a336e17431cb434
|
| 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_rtx-2.14.0-cp313-cp313-win_amd64.whl
| Download URL | torch_tensorrt_rtx-2.14.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
9b9878281b1a24f957d2974a0e6ff438b31ca8dc065dcf62d2b00ee08e9e8281
|
|
BLAKE2b-256 checksum How to use checksums |
02bec93d8d2d13c8f56ba969537847a647319560fb05bfb205a69f817dc3af3c
|
| 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_rtx-2.14.0-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | torch_tensorrt_rtx-2.14.0-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 3.9 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
e97603be4498fb00b0343a6bb295198bb78956cf8cd02b56ddb3552d6a07dde8
|
|
BLAKE2b-256 checksum How to use checksums |
6bf382a8b04aef6b891c0e7e080e80525afbc3d4a01ce65d7f337507284f84bf
|
| 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_rtx-2.14.0-cp312-cp312-win_amd64.whl
| Download URL | torch_tensorrt_rtx-2.14.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
4ef42d92bdfe897b45b9672cc6073fd98e4d3ca7588e31b977e90e3d7fcde432
|
|
BLAKE2b-256 checksum How to use checksums |
1286ca36586de16eccdfe4502487c897d271fdb95770ed39e7004c983e114e40
|
| 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_rtx-2.14.0-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | torch_tensorrt_rtx-2.14.0-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 3.9 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
e9976d0b7a7372cc941849dc5dcc33cb3e2de76aa07b883dadbb1f1c2ca0e021
|
|
BLAKE2b-256 checksum How to use checksums |
bd9e0d7fd32b9c1c5ab8d72dee2f4bc591fa35d4df5cf5e8887b61185865c421
|
| 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_rtx-2.14.0-cp311-cp311-win_amd64.whl
| Download URL | torch_tensorrt_rtx-2.14.0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
0fe097dc1865c58ede4bafc68eaea8559757e635e28b126f0092b43b984a94d8
|
|
BLAKE2b-256 checksum How to use checksums |
ca3cd18ca3ef1264f12f2f8c4fe3377505e7e6110ea97917fc0c5e4e49598ede
|
| 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_rtx-2.14.0-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | torch_tensorrt_rtx-2.14.0-cp311-cp311-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 3.9 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
5943a22ae8a2d87c7330844f303750618d106caba100b000418d3dabde8d8a94
|
|
BLAKE2b-256 checksum How to use checksums |
4583bd56931e0cc71877e5b9a4c51a77dc229d1b9bacf084083d083f74468cad
|
| 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_rtx-2.14.0-cp310-cp310-win_amd64.whl
| Download URL | torch_tensorrt_rtx-2.14.0-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
035b709ebd7072a12fc765c7ccb8bf2188a5e7bdd4da62886a7a136b5329d4b0
|
|
BLAKE2b-256 checksum How to use checksums |
e5789fc0a306c236044c548970c82484d7d9e1edc4e57e9f9dea433b6c1794f3
|
| 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_rtx-2.14.0-cp310-cp310-manylinux_2_28_x86_64.whl
| Download URL | torch_tensorrt_rtx-2.14.0-cp310-cp310-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 3.9 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
44bf3190137df8584b56df2ad37de5d9a1b200b3e803dff8f63b42424689a73c
|
|
BLAKE2b-256 checksum How to use checksums |
09abbf84ec777472e40addcff3a3be7d80f7835ba16407990fbd281d71645b8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|