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_tests windows_tests


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

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
Windows / GPU Supported (Dynamo only)
Linux aarch64 / GPU Native Compilation Supported on JetPack-4.4+ (use v1.0.0 for the time being)
Linux aarch64 / DLA Native Compilation Supported on JetPack-4.4+ (use v1.0.0 for the time being)
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 6.3.2
  • Libtorch 2.7.0.dev (latest nightly) (built with CUDA 12.8)
  • CUDA 12.8
  • TensorRT 10.9.0.43

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

torch_tensorrt-2.7.0-cp313-cp313-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.13Windows x86-64

torch_tensorrt-2.7.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl (16.3 MB view details)

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

torch_tensorrt-2.7.0-cp312-cp312-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.12Windows x86-64

torch_tensorrt-2.7.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl (16.3 MB view details)

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

torch_tensorrt-2.7.0-cp311-cp311-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.11Windows x86-64

torch_tensorrt-2.7.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl (16.3 MB view details)

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

torch_tensorrt-2.7.0-cp310-cp310-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.10Windows x86-64

torch_tensorrt-2.7.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl (16.2 MB view details)

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

torch_tensorrt-2.7.0-cp39-cp39-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.9Windows x86-64

torch_tensorrt-2.7.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl (16.2 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.7.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for torch_tensorrt-2.7.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 0e79c7548f26ee416db94f56000566ab833bbebac2c658f86a5fe88d890d5dfb
MD5 97ccdf303bb95411524d80c798c7b110
BLAKE2b-256 cd0ab911f73d91770b9d77c846ba034986a55878b2d86777c9053651febe8f1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.7.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 67a3aeba91920b0267d6f2babe3fd63a4276ab7cb1ef6cf22454f78eebe6a049
MD5 406e9b0f723e35e84c26fbb42ecc940b
BLAKE2b-256 5511de0afa91b6a564dac888078ffd54b6c338ec54b7a7065f34d1104a26b7dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.7.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 924d86ee9e1b5b99dc574b15a8fb704b6aa5b8ae7ecf2e3f0cf8e53630ba13f0
MD5 fd21b42fd49e80308e4b419dbffe0645
BLAKE2b-256 435e60ded91ca4865997a0e347ed64e4e53695967f9a9ddac6686407ad24b984

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.7.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 10f99c89b8e22ba5e45840133483b28c92010aa8561c0c561801182fb8ee8305
MD5 7aa35e46e1affda2aea931b1377e7e61
BLAKE2b-256 0659c1baced6d138ae551f0cf0d8608ac27904fdd44521087f023b89a6a5e1eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.7.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 076dfbe5c7bd7f5cdeef833b245e3d5514d61483fd5de27c0fe3ad724815b0fe
MD5 9fef9b10f1fa11bed0658cc58cb642ad
BLAKE2b-256 d5932e43bc29b2a03fc34486c884bef101c2db3c460305381feabe2b7cec46b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.7.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d0581a8dbe2ebd687157e23a6c79bacd6f4d57442a69af3d3c321b7ef4c46b18
MD5 62accd2fe78600d4751839810e360b81
BLAKE2b-256 c7bcf05c2eaf9983ecfa4ac66c6711bd62fa7036f0e07cbbf4c1d025b42061f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.7.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c5097a7f685bb7f2cc27397477740937e0ba4a35bd175f5eb5e895f1226853ee
MD5 27454e21b65002ea1db4e0106be8485d
BLAKE2b-256 3166ec6499e4b06fe6bf197d33ded141c1300fdeb0c8c5f12af79063dd44c0a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.7.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 56f53981099dea5a3fa846b3b04ead3bed209f1f94efcec46af1a10fb6ecb273
MD5 6f59e5d091be6caf8db6271333b06ac3
BLAKE2b-256 d3d81778d3b361bb7ab18321602b31d8c8a3e40fd6bed693dd739c27abf664ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.7.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 5b374ece7ab85097d04e223db1520e27b374e115082cdad8b13e00c035c9f2d5
MD5 a8043674a4b6092103faa4ceedfc3edc
BLAKE2b-256 4b560cb65d45c8b4b40cbdd54b50863b2f79a698c35ece97c7bd52e090bd91da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.7.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 675f22c434dac125177bc41b61d3b498576e3930d298a9c56fabfd9710e8fe65
MD5 4c67ed612a69617ae4ebc9a9b09ae1f9
BLAKE2b-256 3aa5384df1fecd601e12cbd95fe461fd2e397db79253360d9a784e5eaa49f39d

See more details on using hashes here.

Supported by

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