Skip to content

Commit cf5cc93

Browse files
committed
refactor: Address some issues with enums and overhaul documentation
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
1 parent 2a6dda9 commit cf5cc93

29 files changed

+1125
-227
lines changed

dev_dep_versions.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
__version__: "2.5.0.dev0"
21
__cuda_version__: "12.4"
32
__tensorrt_version__: "10.0.1"

docsrc/conf.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# -- Project information -----------------------------------------------------
2626

2727
project = "Torch-TensorRT"
28-
copyright = "2022, NVIDIA Corporation"
28+
copyright = "2024, NVIDIA Corporation"
2929
author = "NVIDIA Corporation"
3030

3131
version = f"v{torch_tensorrt.__version__}"
@@ -151,6 +151,9 @@
151151
"master_doc": True,
152152
"version_info": {
153153
"main": "https://pytorch.org/TensorRT/",
154+
"v2.3.0": "https://pytorch.org/TensorRT/v2.3.0",
155+
"v2.2.0": "https://pytorch.org/TensorRT/v2.2.0",
156+
"v2.1.0": "https://pytorch.org/TensorRT/v2.1.0",
154157
"v1.4.0": "https://pytorch.org/TensorRT/v1.4.0",
155158
"v1.3.0": "https://pytorch.org/TensorRT/v1.3.0",
156159
"v1.2.0": "https://pytorch.org/TensorRT/v1.2.0",
@@ -186,6 +189,8 @@
186189

187190
nbsphinx_execute = "never"
188191

192+
autodoc_member_order = "groupwise"
193+
189194
# -- A patch that prevents Sphinx from cross-referencing ivar tags -------
190195
# See http://stackoverflow.com/a/41184353/3343043
191196

docsrc/getting_started/getting_started_with_windows.rst

Lines changed: 0 additions & 34 deletions
This file was deleted.

docsrc/getting_started/installation.rst

Lines changed: 98 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
.. _installation:
22

33
Installation
4-
=============
4+
##################
55

66
Precompiled Binaries
7-
*********************
7+
---------------------
88

9-
Torch-TensorRT 2.x is centered primarily around Python. As such, precompiled releases can be found on pypi.org
9+
Torch-TensorRT 2.x is centered primarily around Python. As such, precompiled releases can be found on `pypi.org <https://pypi.org/project/torch-tensorrt/>`_
1010

1111
Dependencies
12-
---------------
12+
~~~~~~~~~~~~~~
1313

1414
You need to have CUDA, PyTorch, and TensorRT (python package is sufficient) installed to use Torch-TensorRT
1515

@@ -18,16 +18,18 @@ You need to have CUDA, PyTorch, and TensorRT (python package is sufficient) inst
1818

1919

2020
Installing Torch-TensorRT
21-
---------------------------
21+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2222

2323
You can install the python package using
2424

2525
.. code-block:: sh
2626
2727
python -m pip install torch torch-tensorrt tensorrt
2828
29+
Packages are uploaded for Linux on x86 and Windows
30+
2931
Installing Torch-TensorRT for a specific CUDA version
30-
--------------------------------------------------------
32+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3133

3234
Similar to PyTorch, Torch-TensorRT has builds compiled for different versions of CUDA. These are distributed on PyTorch's package index
3335

@@ -38,7 +40,7 @@ For example CUDA 11.8
3840
python -m pip install torch torch-tensorrt tensorrt --extra-index-url https://download.pytorch.org/whl/cu118
3941
4042
Installing Nightly Builds
41-
---------------------------
43+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4244

4345
Torch-TensorRT distributed nightlies targeting the PyTorch nightly. These can be installed from the PyTorch nightly package index (separated by CUDA version)
4446

@@ -51,19 +53,22 @@ Torch-TensorRT distributed nightlies targeting the PyTorch nightly. These can be
5153
.. _bin-dist:
5254

5355
C++ Precompiled Binaries (TorchScript Only)
54-
--------------------------------------------------
56+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5557

5658
Precompiled tarballs for releases are provided here: https://github.com/pytorch/TensorRT/releases
5759

5860
.. _compile-from-source:
5961

6062
Compiling From Source
61-
******************************************
63+
------------------------
64+
65+
Building on Linux
66+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
6267

6368
.. _installing-deps:
6469

65-
Dependencies for Compilation
66-
-------------------------------
70+
Dependencies
71+
^^^^^^^^^^^^^^
6772

6873
* Torch-TensorRT is built with **Bazel**, so begin by installing it.
6974

@@ -120,7 +125,7 @@ If you have a local version of TensorRT installed, this can be used as well by c
120125

121126

122127
Building the Package
123-
---------------------
128+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124129

125130
Once the WORKSPACE has been configured properly, all that is required to build torch-tensorrt is the following command
126131

@@ -135,12 +140,41 @@ To build the wheel file
135140
136141
python -m pip wheel --no-deps --pre . --extra-index-url https://download.pytorch.org/whl/nightly/cu124 -w dist
137142
143+
Additional Build Options
144+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
145+
146+
Some features in the library are optional and allow builds to be lighter or more portable.
147+
148+
Python Only Distribution
149+
............................
150+
151+
There are multiple features of the library which require C++ components to be enabled. This includes both the TorchScript frontend which accepts TorchScript modules for compilation
152+
and the Torch-TensorRT runtime, the default executor for modules compiled with Torch-TensorRT, be it with the TorchScript or Dynamo frontend.
153+
154+
In the case you may want a build which does not require C++ you can disable these features and avoid building these compoents. As a result, the only available runtime will be the Python based on
155+
which has implications for features like serialization.
156+
157+
.. code-block:: sh
158+
159+
PYTHON_ONLY=1 python -m pip install --pre . --extra-index-url https://download.pytorch.org/whl/nightly/cu124
160+
161+
162+
No TorchScript Frontend
163+
............................
164+
165+
The TorchScript frontend is a legacy feature of Torch-TensorRT which is now in maintance as TorchDynamo has become the prefered compiler technology for this project. It contains quite a bit
166+
of C++ code that is no longer necessary for most users. Therefore you can exclude this component from your build to speed up build times. The C++ based runtime will still be available to use.
167+
168+
.. code-block:: sh
169+
170+
NO_TORCHSCRIPT=1 python -m pip install --pre . --extra-index-url https://download.pytorch.org/whl/nightly/cu124
171+
138172
139-
Building the C++ Library (TorchScript Only)
140-
------------------------------
173+
Building the C++ Library Standalone (TorchScript Only)
174+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
141175

142176
Release Build
143-
^^^^^^^^^^^^^^^^^^^^^^^^
177+
............................
144178

145179
.. code-block:: shell
146180
@@ -151,7 +185,7 @@ A tarball with the include files and library can then be found in ``bazel-bin``
151185
.. _build-from-archive-debug:
152186

153187
Debug Build
154-
^^^^^^^^^^^^^^^^^^^^^^^^
188+
............................
155189

156190
To build with debug symbols use the following command
157191

@@ -162,7 +196,7 @@ To build with debug symbols use the following command
162196
A tarball with the include files and library can then be found in ``bazel-bin``
163197

164198
Pre CXX11 ABI Build
165-
^^^^^^^^^^^^^^^^^^^^^^^^
199+
............................
166200

167201
To build using the pre-CXX11 ABI use the ``pre_cxx11_abi`` config
168202

@@ -204,8 +238,45 @@ recommended commands:
204238

205239
NOTE: For all of the above cases you must correctly declare the source of PyTorch you intend to use in your WORKSPACE file for both Python and C++ builds. See below for more information
206240

207-
**Building with CMake** (TorchScript Only)
208-
-------------------------------------------
241+
242+
243+
Building on Windows
244+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
245+
246+
247+
* Microsoft VS 2022 Tools
248+
* Bazelisk
249+
* CUDA
250+
251+
252+
Build steps
253+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
254+
255+
* Open the app "x64 Native Tools Command Prompt for VS 2022" - note that Admin priveleges may be necessary
256+
* Ensure Bazelisk (Bazel launcher) is installed on your machine and available from the command line. Package installers such as Chocolatey can be used to install Bazelisk
257+
* Install latest version of Torch (i.e. with ``pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu124``)
258+
* Clone the Torch-TensorRT repository and navigate to its root directory
259+
* Run ``pip install ninja wheel setuptools``
260+
* Run ``pip install --pre -r py/requirements.txt``
261+
* Run ``set DISTUTILS_USE_SDK=1``
262+
* Run ``python setup.py bdist_wheel``
263+
* Run ``pip install dist/*.whl``
264+
265+
Advanced setup and Troubleshooting
266+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
267+
268+
In the ``WORKSPACE`` file, the ``cuda_win``, ``libtorch_win``, and ``tensorrt_win`` are Windows-specific modules which can be customized. For instance, if you would like to build with a different version of CUDA, or your CUDA installation is in a non-standard location, update the `path` in the `cuda_win` module.
269+
270+
Similarly, if you would like to use a different version of pytorch or tensorrt, customize the `urls` in the ``libtorch_win`` and ``tensorrt_win`` modules, respectively.
271+
272+
Local versions of these packages can also be used on Windows. See ``toolchains\\ci_workspaces\\WORKSPACE.win.release.tmpl`` for an example of using a local version of TensorRT on Windows.
273+
274+
275+
Alternative Build Systems
276+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
277+
278+
Building with CMake (TorchScript Only)
279+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
209280

210281
It is possible to build the API libraries (in cpp/) and the torchtrtc executable using CMake instead of Bazel.
211282
Currently, the python API and the tests cannot be built with CMake.
@@ -233,11 +304,12 @@ A few useful CMake options include:
233304
[-DCMAKE_BUILD_TYPE=Debug|Release]
234305
cmake --build <build directory>
235306
236-
**Building Natively on aarch64 (Jetson)**
237-
-------------------------------------------
307+
308+
Building Natively on aarch64 (Jetson)
309+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
238310

239311
Prerequisites
240-
^^^^^^^^^^^^^^
312+
............................
241313

242314
Install or compile a build of PyTorch/LibTorch for aarch64
243315

@@ -247,7 +319,7 @@ NVIDIA hosts builds the latest release branch for Jetson here:
247319

248320

249321
Enviorment Setup
250-
^^^^^^^^^^^^^^^^^
322+
............................
251323

252324
To build natively on aarch64-linux-gnu platform, configure the ``WORKSPACE`` with local available dependencies.
253325

@@ -279,7 +351,7 @@ use that library, set the paths to the same path but when you compile make sure
279351
280352
281353
Compile C++ Library and Compiler CLI
282-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
354+
........................................................
283355

284356
NOTE: Due to shifting dependency locations between Jetpack 4.5 and 4.6 there is a now a flag to inform bazel of the Jetpack version
285357

@@ -295,7 +367,7 @@ Compile Torch-TensorRT library using bazel command:
295367
bazel build //:libtorchtrt --platforms //toolchains:jetpack_5.0
296368
297369
Compile Python API
298-
^^^^^^^^^^^^^^^^^^^^
370+
............................
299371

300372
NOTE: Due to shifting dependencies locations between Jetpack 4.5 and newer Jetpack verisons there is now a flag for ``setup.py`` which sets the jetpack version (default: 5.0)
301373

@@ -307,4 +379,4 @@ Compile the Python API using the following command from the ``//py`` directory:
307379
308380
If you have a build of PyTorch that uses Pre-CXX11 ABI drop the ``--use-cxx11-abi`` flag
309381

310-
If you are building for Jetpack 4.5 add the ``--jetpack-version 5.0`` flag
382+
If you are building for Jetpack 4.5 add the ``--jetpack-version 5.0`` flag
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
.. _quick_start:
2+
3+
Quick Start
4+
##################
5+
6+
Option 1: torch.compile
7+
-------------------------
8+
9+
You can use Torch-TensorRT anywhere you use torch.compile:
10+
11+
.. code-block:: py
12+
13+
import torch
14+
import torch_tensorrt
15+
16+
model = MyModel().eval().cuda() # define your model here
17+
x = torch.randn((1, 3, 224, 224)).cuda() # define what the inputs to the model will look like
18+
19+
optimized_model = torch.compile(model, backend="tensorrt")
20+
optimized_model(x) # compiled on first run
21+
22+
optimized_model(x) # this will be fast!
23+
24+
25+
Option 2: Export
26+
-------------------------
27+
28+
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).
29+
30+
Step 1: Optimize + serialize
31+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32+
33+
.. code-block:: py
34+
35+
import torch
36+
import torch_tensorrt
37+
38+
model = MyModel().eval().cuda() # define your model here
39+
inputs = [torch.randn((1, 3, 224, 224)).cuda()] # define a list of representative inputs here
40+
41+
trt_gm = torch_tensorrt.compile(model, ir="dynamo", inputs)
42+
torch_tensorrt.save(trt_gm, "trt.ep", inputs=inputs) # PyTorch only supports Python runtime for an ExportedProgram. For C++ deployment, use a TorchScript file
43+
torch_tensorrt.save(trt_gm, "trt.ts", output_format="torchscript", inputs=inputs)
44+
45+
Step 2: Deploy
46+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47+
48+
Deployment in Python:
49+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
51+
52+
.. code-block:: py
53+
54+
import torch
55+
import torch_tensorrt
56+
57+
inputs = [torch.randn((1, 3, 224, 224)).cuda()] # your inputs go here
58+
59+
# You can run this in a new python session!
60+
model = torch.export.load("trt.ep").module()
61+
# model = torch_tensorrt.load("trt.ep").module() # this also works
62+
model(*inputs)
63+
64+
Deployment in C++:
65+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66+
67+
.. code-block:: c++
68+
69+
#include "torch/script.h"
70+
#include "torch_tensorrt/torch_tensorrt.h"
71+
72+
auto trt_mod = torch::jit::load("trt.ts");
73+
auto input_tensor = [...]; // fill this with your inputs
74+
auto results = trt_mod.forward({input_tensor});

0 commit comments

Comments
 (0)