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.10.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.10.0-cp313-cp313-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.13Windows x86-64

torch_tensorrt-2.10.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.10.0-cp313-cp313-manylinux_2_28_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.12Windows x86-64

torch_tensorrt-2.10.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.10.0-cp312-cp312-manylinux_2_28_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.11Windows x86-64

torch_tensorrt-2.10.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.10.0-cp311-cp311-manylinux_2_28_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.10Windows x86-64

torch_tensorrt-2.10.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.10.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.10.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.10.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 54713eea3a4e56b171ca28651ecb1df75c1783ef877b3fa129467ee6aa347ac2
MD5 267701455cf046fc67ddb41bea6385eb
BLAKE2b-256 2a5362277352da7761e74e8178c2756a206ad0b8d323bd9a3d55c0253feb47cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.10.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 778d0c7485464e319f9822ab99798c75ed5a29ce7598d84ff668da2d19b11ebc
MD5 eefd1abc81b3a3ec435ec8465f883731
BLAKE2b-256 a80e8352437ae6ec23d1922f0250d4e19456173f0d09ae5adca5e14c2b2a91d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.10.0-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 90e67a89c33a640003809d58f5f557a0bedc3d9d0adbaa9fb01ebfef59fc3b26
MD5 c3a9b577ced5d326a1a80145c73cf957
BLAKE2b-256 2cc1c54d91e92a17007f2e60d4b0755690476afd7fb65a88839371d43eb6588b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.10.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 074f9ceb7d16bc939ef19c5a51d632bf4d7feed42270caba55002eab3ce1832d
MD5 9542f24529b9786d2d76d8a0b863e389
BLAKE2b-256 1439084654ccc03cf197656862cc19166f9093d5b7fa854dc593e0ccba537cd5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.10.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 10f8c6bbeeaedff02be219cc4fcbc8b07b8ff3f290bb8369efdb00f51fd93038
MD5 2e7ea5d67440a47089e40baad2f4bd3a
BLAKE2b-256 86fbb1a4247e067cb7c1d68c9d8f0ce48d5069bce22d9b39bcd21ae9d055a8fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.10.0-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b402ce13cccfbe297f6a15d17388c4bb3b5aca98d789543edb1b9c367ab408fe
MD5 40352b3a621830e968d87318e8abdd56
BLAKE2b-256 6a7d6c92816ebbf28172158532b169fe19c3bd0d3ef9415b2857f861d507c655

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.10.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 60df0fa50e0cf62748e5e5ddec8acd82e61d501633901b1aeb21b9c765e1b431
MD5 8a127375e30d205f78d46868934398d1
BLAKE2b-256 b94d03a93226142e5a49aa651ddc674114757c56166cd2815774e818dc655688

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.10.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b64450453b5d06bf91d17b082eb78b0f250f18a1bb6f3f2ae3965deca0f2a22f
MD5 846805bd6122625ce9dab550a9530a55
BLAKE2b-256 d99de9ba4bcb943c11193c5b40f7da45be03ef43494cfff72566a2ea8e7e4a8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.10.0-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6286158add6c5103633db6d419e66c01dbe6eb878a4acc4569922ed8b8cdf585
MD5 93b21b819bcb1d25eb03e17d474ffc99
BLAKE2b-256 0410a390c3366cc47a82a3dccf29226e41d0a20a2ff765b26e80c31c2dbb0de5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.10.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c7fdb42d2fd8f0d0127761125472f935ff37aca3cad101d70ebfe2d08aad718f
MD5 4f500ec15f9c467e4bfe56b417831596
BLAKE2b-256 21eab79a62fb28f2685eea6344afb26a77b5f5f09ddd6337fccd638eb4b9ee0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.10.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 07836763a3280a5ebc5aed5e265112491486dd48b79cf86db868abc7fac3f344
MD5 559da321aff3a466719ba5fdbbbb1dbc
BLAKE2b-256 49d06c89f30abd44f4f9572fb86bb7a964a9e1bdb627a3314381d1b0c1db6a93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.10.0-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b9387ded4832a2ad7e8aff11c8381b388d3a373bb03fbf8b87aedc56a2024ef1
MD5 82e2444bb113722c340c215ff0eb03ca
BLAKE2b-256 31f8ef4c3d0b13716f504ccd801cba3228d531171246fff9ebcb15cc21d133c6

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