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.12.0.dev (latest nightly)
  • CUDA 13.0 (CUDA 12.6 on Jetson)
  • TensorRT 10.15.1.29 (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_rtx-2.12.1-cp313-cp313-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.13Windows x86-64

torch_tensorrt_rtx-2.12.1-cp313-cp313-manylinux_2_28_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

torch_tensorrt_rtx-2.12.1-cp312-cp312-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.12Windows x86-64

torch_tensorrt_rtx-2.12.1-cp312-cp312-manylinux_2_28_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

torch_tensorrt_rtx-2.12.1-cp311-cp311-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.11Windows x86-64

torch_tensorrt_rtx-2.12.1-cp311-cp311-manylinux_2_28_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

torch_tensorrt_rtx-2.12.1-cp310-cp310-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.10Windows x86-64

torch_tensorrt_rtx-2.12.1-cp310-cp310-manylinux_2_28_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

File details

Details for the file torch_tensorrt_rtx-2.12.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for torch_tensorrt_rtx-2.12.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 cefc4503600f2006e89fc953fff00e60235d99402181155e7cf4971de3bba829
MD5 9fdab724292fa89414f52b1b2ac492bd
BLAKE2b-256 1b4b1765059c4daa56cca23d314c117c3cacb7901327f7dbcdeb54fcacf08319

See more details on using hashes here.

File details

Details for the file torch_tensorrt_rtx-2.12.1-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torch_tensorrt_rtx-2.12.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 181f745edfa217d8ded6628a2b949fb4ab5eefe9e2de3fc02110bd6b5734b657
MD5 f5e1911abee1897c4f884c1a91f7c4f9
BLAKE2b-256 0a30d25cce1d0509576c594a51d07fcf58eec291ea0340b4332bf90a9a1936cb

See more details on using hashes here.

File details

Details for the file torch_tensorrt_rtx-2.12.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for torch_tensorrt_rtx-2.12.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 77fca7700095c65070b897dcf7fcac86fb74791fdb2cd3fddfc1a8302c2055e0
MD5 0b9814a0ebda86481379d38128f60f9b
BLAKE2b-256 52d4c294862173bc5138874834f7e9b2ea965127ca989a4d474c7aac19bb2dd6

See more details on using hashes here.

File details

Details for the file torch_tensorrt_rtx-2.12.1-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torch_tensorrt_rtx-2.12.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6f40bf9268d795dbf60e3f166b2f3edd6961bce3f393765ecfd93c7077e9aeee
MD5 76c5f6a53006ed3c16c49df1b737c5bb
BLAKE2b-256 e77942070ae6c7dd2559c314387a0e6847acd86670a8d59c4e63f33d8c5030e1

See more details on using hashes here.

File details

Details for the file torch_tensorrt_rtx-2.12.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for torch_tensorrt_rtx-2.12.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d42b6f21447bf34812b52ec50ab65e6838fa08b1b315c8318dc9efc61a67612b
MD5 6119e5fd77d0c7dee7ea8953eddf28ff
BLAKE2b-256 0b8335ae85355a59dedca8f8d49f0eaae0113c54a334558228e51b802911430f

See more details on using hashes here.

File details

Details for the file torch_tensorrt_rtx-2.12.1-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torch_tensorrt_rtx-2.12.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4fabda5962791fd4ea4faa83e735ee8abf9d18da1769c6e6755cccd9711708da
MD5 6e0ee0722e4d81d64bc928344cc41fe6
BLAKE2b-256 bf991c069506fcde39eb18e519f3d149bf9b1334a3a096859446daee7706c127

See more details on using hashes here.

File details

Details for the file torch_tensorrt_rtx-2.12.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for torch_tensorrt_rtx-2.12.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f515ce989aa717549fbf5c1f41d4bd0827bc50fff6b9e18680a831886ae894df
MD5 001e2936941920a22f0b0f54a46d63ba
BLAKE2b-256 9341288103d19d6a1793d0b98559e521b51d73366ba0066dc72bcf32bdd4216b

See more details on using hashes here.

File details

Details for the file torch_tensorrt_rtx-2.12.1-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torch_tensorrt_rtx-2.12.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6a3f95825c7f63849df06d8999f23039b978c3ea3db033055f639e28c07701df
MD5 593fd15ea7f7b52becc282a82938d285
BLAKE2b-256 2d49f2a047384f08757da47e8d755e90492022427356c5f3383f0bba5c7d4652

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