Skip to main content

Torch-TensorRT is a package which allows users to automatically compile PyTorch and TorchScript modules to TensorRT while remaining in PyTorch

Project description

Torch-TensorRT

Easily achieve the best inference performance for any PyTorch model on the NVIDIA platform.

Documentation pytorch cuda trt license Linux x86-64 Nightly Wheels Linux SBSA Nightly Wheels Windows Nightly Wheels


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

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

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.9.0.dev (latest nightly)
  • CUDA 12.8 (CUDA 12.6 on Jetson)
  • TensorRT 10.13.2.6 (TensorRT 10.3 on Jetson)

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

torch_tensorrt-2.9.0-cp313-cp313-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.13Windows x86-64

torch_tensorrt-2.9.0-cp313-cp313-manylinux_2_28_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

torch_tensorrt-2.9.0-cp313-cp313-manylinux_2_28_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.9.0-cp312-cp312-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.12Windows x86-64

torch_tensorrt-2.9.0-cp312-cp312-manylinux_2_28_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

torch_tensorrt-2.9.0-cp312-cp312-manylinux_2_28_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.9.0-cp311-cp311-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.11Windows x86-64

torch_tensorrt-2.9.0-cp311-cp311-manylinux_2_28_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

torch_tensorrt-2.9.0-cp311-cp311-manylinux_2_28_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.9.0-cp310-cp310-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.10Windows x86-64

torch_tensorrt-2.9.0-cp310-cp310-manylinux_2_28_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

torch_tensorrt-2.9.0-cp310-cp310-manylinux_2_28_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

File details

Details for the file torch_tensorrt-2.9.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.9.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a6260abc2ea69a3367d052269f2b5490916ef8fc420a1ae069789a6352209a57
MD5 60f1319b210a31af7854d72ae6102347
BLAKE2b-256 2f4cbcb69b2a595866f341ae1467d42003925c09176d40e95d72e1199213cc5c

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.9.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.9.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d1dc2b02191e9eb29134959d2a769512e3f3ff2dcfcefa6f1c0481b3c2e913f8
MD5 622d5343775ae4d90a83ec21c9e012c9
BLAKE2b-256 63b72585d676af729341a1ab1025def13a27b65efa2e068f2544ed311e569597

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.9.0-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.9.0-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2116c0acf35c8cfda27078bb7bdca0af09821474555e702144d01e8af0fb4819
MD5 f9f34980c718f6e247026bbb396b1106
BLAKE2b-256 6f4dfad05b26bfaae5ede0942d9ca9703d6177b422126d2ac3e455e502d77ed5

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.9.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.9.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a264e0cf572137f04544fc6ea5ced7a28400ba19dfb38f514813b58a0749adb0
MD5 6f46c3ad2934047ba131bf3c36cd1161
BLAKE2b-256 def68e66a6182650b44d584dfff59ac3de721ac85cc38508ffae94069373496c

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.9.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.9.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 21130e26912375683f79e2451205eed164b83d80b64f2f1b628fea1b093a7916
MD5 0c047e27c61b863e78ee54ae8c640253
BLAKE2b-256 850e2ca188facac997c21ae323d3e0d94ab86074a8af459244b3c80d4becef54

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.9.0-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.9.0-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f7a4c96977cba879d27608220ba18d9aa85a9283688fd8c57f53ee0f8d35e0cf
MD5 38c514967b798a9b1cafc951463c0412
BLAKE2b-256 00a16e699a58fec31a6f068e558fb66b4c2a162ea5ea9aac352e861191ce79cc

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.9.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.9.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 280c43404251e4052a11e0c93c03388b6a216115d5cc5f10a7561ab2d59941e3
MD5 30a939f77b86b66e1b4cc1c101e7587a
BLAKE2b-256 707c506a6cb5db2dc47a38e4b2476611b414e774f3d2c5182abdb50444857854

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.9.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.9.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3e543b55c7336a6cf92a94bba0de51274b8fd8592a1bb6c01b536b7170a3bc3a
MD5 ad0128747fbff5855faf9d4ad9f84f07
BLAKE2b-256 9654395977175f28c84f4fc97763bd0d39acc3ea2c5cf27686ad20c37aad424a

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.9.0-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.9.0-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 60de8744df02bedcb040e3a1d4d2dae920d6a4fc17171cba808fb3b1f423c9cb
MD5 926f4744b17102b5961e20e282858dc6
BLAKE2b-256 8a7890fe32b3a2c75d20aebca0aa20228f45e1a6c689fe163fb8f5b9561a5243

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.9.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.9.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8991b63e3aa079898fa2aafa45deca122610c2c930094e6fa26d7321b890335c
MD5 0485f876897d3433a726531930475a33
BLAKE2b-256 2966b700f75b28d10c9e16de29eae36867fd2abf4d2e6e2851f54a81ad0162f9

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.9.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.9.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6efc22b123e187cff868c75c7f41e3518ebe7b54bb0008e77e9d5982709290e4
MD5 56408663d0a73bfc898c374a55269b8d
BLAKE2b-256 62c232dda81a2c12df31abc9d87fb4112e10f004a138797ea315de6bef689a1e

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.9.0-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.9.0-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e8057245fec36ed1f04ad89ee92e242d86b5da8910498772bb8f289db0856fd1
MD5 2579e2ff2fb0fb52a6892016c3561986
BLAKE2b-256 510c201f9c6c91973d94d2fb551574144b385d760002a0325958e081b1e1d2e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page