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-2.12.0-cp313-cp313-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.13Windows x86-64

torch_tensorrt-2.12.0-cp313-cp313-manylinux_2_28_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

torch_tensorrt-2.12.0-cp313-cp313-manylinux_2_28_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.12.0-cp312-cp312-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.12Windows x86-64

torch_tensorrt-2.12.0-cp312-cp312-manylinux_2_28_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

torch_tensorrt-2.12.0-cp312-cp312-manylinux_2_28_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.12.0-cp311-cp311-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.11Windows x86-64

torch_tensorrt-2.12.0-cp311-cp311-manylinux_2_28_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

torch_tensorrt-2.12.0-cp311-cp311-manylinux_2_28_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

torch_tensorrt-2.12.0-cp310-cp310-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.10Windows x86-64

torch_tensorrt-2.12.0-cp310-cp310-manylinux_2_28_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

torch_tensorrt-2.12.0-cp310-cp310-manylinux_2_28_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.12.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d4a7ec34ddc799f51597cfbd9387e0272892af97b7fd6c400700c58ca3370595
MD5 9c259059b31c56be40ae1fc5cebdae0c
BLAKE2b-256 d653c2ba212363b1926e3d306b7bfde7ceed0da91a0d68d12de714f4cd4dfc74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.12.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 732a81e51bcf59b1a1ff93f1e6298dad700b02ccb3d43b8528ecd1961b0c8a4c
MD5 5c3192dde6cf12f3a4d54f461458558a
BLAKE2b-256 099cd8b8dd8124393a214c1c4d59b8d174963c17bffb6d473185ba00e2507f25

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.12.0-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e203c22eca99e287596ea27e01788bd75fe28711218ab5df21f3fc01c71be1ac
MD5 b2174f94cfab065822a90acf1d716803
BLAKE2b-256 52862e9042fb1ab53271c472da682d1dd1002b77ae43b7d35c04ab348d380463

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.12.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a34606276230398dc0a146faee6eb0487c23395a28d9467f66ac4d55bc61656a
MD5 911f4bd37652d087dd8b8a8180672718
BLAKE2b-256 9855e4649953ff9ba9934088afe73e0734a1c4586b9bdace4745daf174ee4cb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.12.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a0c6537219254a9ce41e44674939428b0cdf7859dae3b1e92f96a988bb86e037
MD5 2383db7594a895d2da89f8c5efca39f1
BLAKE2b-256 3ef094b9e54f7b1ed32d79204c1cca086a4c83203ee694ba060ef1efdead9ab2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.12.0-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 74245b399233dfdeaa0b317dfc9a04b3cc77c3c911e7fe681d32ea612fbbdc45
MD5 6ed73c3b9eb7f47f16e7d7270810aaea
BLAKE2b-256 3f0befee74ecbd3463e313f091b47bb7fa1b9ca88f11461d847a0dbf5c869169

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.12.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2d12c18df5f55ab69c4cd482779ade8c50ac6f7e01f5622d85edb40463548c9f
MD5 b7c6dd43c080bebeb852c689206d80e8
BLAKE2b-256 b450e2df95c450b11f25896d6f59894716ba9078e7adb37c2687ebc2b8a8dae8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.12.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 41f9c6e5decaa7a350f0f320b9456f087b5074b3b14f778f7fc7d056234dfa39
MD5 a00c61b9e8814579dbf070416a3550a8
BLAKE2b-256 1f6be071f0f5396d465c63053c528737986929bfcb7c85e0422a44fb69c9af98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.12.0-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b574e11b96203e7a2aaffee3581985d4fd4147d51069f3ef034aa8b363797cec
MD5 038503bf15e121df010847e80585d8c9
BLAKE2b-256 194f5c893caa1569a9b271d6ed277f19504f69d59cff238167003bd3b638b69f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.12.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f2caafc638baf4593c97f112d3346668967e24c263a7076c7a416099f1c7575c
MD5 99028e132a5b88c57c3216a138ad3386
BLAKE2b-256 dd1d595888d78b63069c807a7f1ebb85c3478bad95da1144a6c9a991c4686b09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.12.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4b6336b0e0cdfa48904a3a7aa67c95428f9be0aac8fec1e49ad0ccf342331e2a
MD5 1a417efe7c1f431cb30cd69ac5c66f9c
BLAKE2b-256 673c38b79ab46c2452fd7ac546044f1985fff4c44b5113d5c2522b0b3844c43b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_tensorrt-2.12.0-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 79a751ecc557bdfe5cc619fe0cd04f90ef17561aec6b31e483b11a88bd1431fe
MD5 caae4135ea17ae1b93b3af95189e743e
BLAKE2b-256 9d2ad65a4bb74802cb88ad5345fed97cbf502f000c92ba130ab0b7976a7234cd

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