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.11.0.dev (latest nightly)
  • CUDA 13.0 (CUDA 12.6 on Jetson)
  • TensorRT 10.14.1.48 (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.11.0-cp313-cp313-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.13Windows x86-64

torch_tensorrt-2.11.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.11.0-cp313-cp313-manylinux_2_28_aarch64.whl (3.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.11.0-cp312-cp312-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.12Windows x86-64

torch_tensorrt-2.11.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.11.0-cp312-cp312-manylinux_2_28_aarch64.whl (3.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.11.0-cp311-cp311-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.11Windows x86-64

torch_tensorrt-2.11.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.11.0-cp311-cp311-manylinux_2_28_aarch64.whl (3.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.11.0-cp310-cp310-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10Windows x86-64

torch_tensorrt-2.11.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.11.0-cp310-cp310-manylinux_2_28_aarch64.whl (3.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.11.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 534796fd17691633f59d101a8efe4941c87d1e1024354d5625c486d1a48132c4
MD5 8580a27d04f9872907ba9da51d397de5
BLAKE2b-256 7ec062edba921c643cb9dd329c76ab9bdfaf90ad26c5b7b0fbdb63c6f6898f78

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.11.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a2695d0defdd9b9b55bde9e3fbd5be4bfa612a957956ae8b60c8a9b71e274cfb
MD5 e97aea089c2ffafb0b7640d5a6d545ec
BLAKE2b-256 51317759bca784c5d5e79daac122ae1de10369a124d8fe1d967ee8f723d72cc4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.11.0-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ca829e19b53f907ee2d5f4b079c3d9679370468a52309a5d113a2adbcfa43dd8
MD5 18520f052631e03a751291f181a10fc1
BLAKE2b-256 02b82a4fca4d1361980a6050f6d1410838d58eb1948a08afcac9318960c12957

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.11.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 15cc6fb6c235f0b145c8b99a2bb2c28fea04b0e3ba5a682b7c005afdaedff623
MD5 f632fee9707722ff0fa651e259b706cf
BLAKE2b-256 ff4164945e521001f108f33b276e1f32abcca11c65bf070e8b9db768038b19f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.11.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ddc6242e302bde876700df4310efa261afd189dc13920e60784e76e03f52aae0
MD5 1951762b30c00eee59a5ac5f19244923
BLAKE2b-256 9959b687552451a4fa9b930de1cf2c6f70142857155e534940265dd2888b31f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.11.0-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3bcf816375e3cf1ebbbd166b08182f0592f0b12230c8db2956bbfd877e972fa4
MD5 1cd0902c5b0749c818ce8c883ddbc1cf
BLAKE2b-256 7c9bb096fbe63e3bfb166a0a20cb8b5aa29684159349f7d9e15aa3d376802034

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.11.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3f76f5c644b1561e0372170e5809aee653f78e39c3b267d0a7718956faeebfdd
MD5 6192299f74ee742c7dc8ac976e5a0c86
BLAKE2b-256 4f43c3f7c2772c2d88554958408b5de54bdb6836020b648bceed5f8787549319

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.11.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ba45f3420ab3978e39346a0b40fb0da9e539869676e5242519f95d58909c0901
MD5 ceeb8b2c138518ece942c4cf87cd9a47
BLAKE2b-256 a8f228786c02cce73becde75e58884c5562249406f9fa0ea7ff8fe76137e4e87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.11.0-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 861c2461664c8e569401605f65325e6c0cb13a5535256ac4369bf6e3b32d830b
MD5 c54c2fd75fab2fe7c467351b233e098a
BLAKE2b-256 603e0eb791d7eb2b54e7c4a804e4d162e191116d177bd60f73bbec9636ead060

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.11.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bf8749f12c4cf088811bfa2f3188b0718b586da458791dbaae8976eaefef6356
MD5 94c2d6623e72b90bb442b36054455f19
BLAKE2b-256 11d793023ca34b3fa0f9bd1fdbc28e19cc42149b057da274f364f4777ca7442b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.11.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ca6dfcfa2d01b7f8bb66265ee8388476d33635a8d7eda22271659e0b0023cf99
MD5 346adf664efaade1edb1e1f288d459be
BLAKE2b-256 ee3bb83f5fe4ce115e48941f287572b8c0ff746b16af109e19d0226ed6356015

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.11.0-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 89297d9c63b3ed51ad50db0b7baf5a1b0a72cb69825719985fa9227b2214a367
MD5 289270a528f62fc0d4da1ee7d7a43208
BLAKE2b-256 27c5abcf8dfa462b642d09842917baaaa7f071fdb5d3c7067876bd06f08a889f

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