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/cu128

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.8.0.dev (latest nightly)
  • CUDA 12.8 (CUDA 12.6 on Jetson)
  • TensorRT 10.11 (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.8.0-cp313-cp313-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.8.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.8.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.8.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.8.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl (15.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.34+ x86-64

torch_tensorrt-2.8.0-cp39-cp39-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.9Windows x86-64

torch_tensorrt-2.8.0-cp39-cp39-manylinux_2_28_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.8.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl (15.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.27+ x86-64manylinux: glibc 2.34+ x86-64

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 88509127a00fc93c9f83a123d0abf6ff7b56100005866d301d9a0b160ccbaee1
MD5 15ba5d42f128ec673e640752adc938e8
BLAKE2b-256 19d801a65106f9e52ddd3e4d9cf6e6aa99703dc6ec1037b35781d96eb5289471

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 be123e48d6c4549a558e3b6b37640b22a967d8da5db49ae3cf64c743b93fae74
MD5 5a946fdfb69d604bf3d9533d58a3be16
BLAKE2b-256 e45d0dd70645eb720a4bb285c7ac10430248b6ab3bd920af54dc26ee652683bb

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.8.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0df341e72bec335bdf236506cee22530146a3c2a2bcf224e82a8a83e8d2d14f8
MD5 d05799044f25284eb3170ec12e38ef4b
BLAKE2b-256 fc36c91bd9b502c4effe9d6fecffbd8251a04d38264b5289df0f3e011b08ca07

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2712f076e4f61adaaff3eecefea4e14d7ca85065eb5080cee4b5eeb46d27c1d4
MD5 10a5895a192ea80cc38e64bc2ef0934b
BLAKE2b-256 b0bd871d8556fddd36fbe8dbd3eb4a30be4375a21f5b2ed5bfd51f2e0dd843cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 70e6c642a570ba02bbb645d7bbec060528c001af7553b65322a849788e9338d9
MD5 8040d268907a9fa8d54df2b64f92fb65
BLAKE2b-256 a992975eb4b3cc8a29afe81f3a029be1f19d39af46d047336af7d061c8103dfd

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.8.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7a2e7c6984e6c7a4b228bc25bf1bfc96c64ab2913f5477e12967ccdb28ced223
MD5 4c87e879dc014d2153bd791cfb238d9c
BLAKE2b-256 eb7741c4366692f51e974391eddd9b38d24a8b7b48dfa26d92352e629e7cbac9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 890441ac87c9e880c409e7ae42c8d522c6ae69eeaa4125985d6399ada7043840
MD5 bcac92d98185231d8818160044816d1b
BLAKE2b-256 14f9c8e033330605f752caff5932fbb4b5df2f71d1fd9f98efa3cf8068090ed5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 84a2bfb377677ff76463393e3b0a51e6ddac50ee4ba8856c2cdbd6e8cfedd94c
MD5 8df1b3c33a40a580e014b1b22a0cbeb4
BLAKE2b-256 576ad2aec3fae13017a9b32c773d842c828a45b238866d7457c3b8d0e4c5a3b8

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.8.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d6fba1e7fa155f73d157b9207069449a31ad18a075efa81cef8048dac138af9a
MD5 b6459f33668239108e642120d251bad5
BLAKE2b-256 24ff9ddab25fc8bea6537245f86c861f5e0e2c88a26f5e5c7f2dca038af145d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5111fec36da7937b9baf7ef40ae04455f869447072d9c93859e80e19e0a76296
MD5 c715155d01121708a6900e35121c1311
BLAKE2b-256 3c0640ae2dcf8dc650ceb55aa6fad909741292360c4bcb42468f0c190bcbfff2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6adb18682d42af150bdabbf10ac6b5dcbab844574b4fe94ecbb383bc9d5873c5
MD5 371aa54e842e4eb65ea01a29811c6925
BLAKE2b-256 ed8a54a79f2959144d7e3f226fee90b71e9b658d1cdd1eafed60bd472d54d67a

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.8.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e4400ec62674d5884d19dcf437a7c084f3b235632e40d48d55e30be7b707ce31
MD5 a6b6e4c8f3e9254c6e212a40a75d0165
BLAKE2b-256 3ef9cd4d172738a14918bc3e7b415ee0bdf2f9cc953424c54d42bf38da5dc56b

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.8.0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 7958d2ee9060890677d6fa95c43f56fe72b1e0f2c10d4c90ae3297a39f8638ec
MD5 aa87d9e29869e18b1ed8eabfae4b0c2d
BLAKE2b-256 992917c9db7cc488163cd5a8700e1e6abfd5f7ad73d1462b3d5726b069a94fd8

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.8.0-cp39-cp39-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp39-cp39-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cb0d1fc9112672f23d1252c761acdfdd49fe50cd9212bd8eabbcaad57a5439d9
MD5 f7df615f50b66c1858cc787d7c4f3efc
BLAKE2b-256 fbd0e08bd089d8144855e8abc0fe670347ea2d7289b72980560c2f956383f19f

See more details on using hashes here.

File details

Details for the file torch_tensorrt-2.8.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.8.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a2a833079a679c0ca7058950370b484405e809402e9ef82f871c52cee1b8ca15
MD5 d4bffdf2b2acf24e8fc498ef3b766c3d
BLAKE2b-256 de4278c543ed237fa113faac1586ee8cd5521cad1e5e9aa2cd74cc3abd6e8abf

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