You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docsrc/getting_started/installation.rst
+98-26Lines changed: 98 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,15 @@
1
1
.. _installation:
2
2
3
3
Installation
4
-
=============
4
+
##################
5
5
6
6
Precompiled Binaries
7
-
*********************
7
+
---------------------
8
8
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/>`_
10
10
11
11
Dependencies
12
-
---------------
12
+
~~~~~~~~~~~~~~
13
13
14
14
You need to have CUDA, PyTorch, and TensorRT (python package is sufficient) installed to use Torch-TensorRT
15
15
@@ -18,16 +18,18 @@ You need to have CUDA, PyTorch, and TensorRT (python package is sufficient) inst
Torch-TensorRT distributed nightlies targeting the PyTorch nightly. These can be installed from the PyTorch nightly package index (separated by CUDA version)
44
46
@@ -51,19 +53,22 @@ Torch-TensorRT distributed nightlies targeting the PyTorch nightly. These can be
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.
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.
@@ -151,7 +185,7 @@ A tarball with the include files and library can then be found in ``bazel-bin``
151
185
.. _build-from-archive-debug:
152
186
153
187
Debug Build
154
-
^^^^^^^^^^^^^^^^^^^^^^^^
188
+
............................
155
189
156
190
To build with debug symbols use the following command
157
191
@@ -162,7 +196,7 @@ To build with debug symbols use the following command
162
196
A tarball with the include files and library can then be found in ``bazel-bin``
163
197
164
198
Pre CXX11 ABI Build
165
-
^^^^^^^^^^^^^^^^^^^^^^^^
199
+
............................
166
200
167
201
To build using the pre-CXX11 ABI use the ``pre_cxx11_abi`` config
168
202
@@ -204,8 +238,45 @@ recommended commands:
204
238
205
239
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
206
240
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``
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.
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)
301
373
@@ -307,4 +379,4 @@ Compile the Python API using the following command from the ``//py`` directory:
307
379
308
380
If you have a build of PyTorch that uses Pre-CXX11 ABI drop the ``--use-cxx11-abi`` flag
309
381
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
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
torch_tensorrt.save(trt_gm, "trt.ep", inputs=inputs) # PyTorch only supports Python runtime for an ExportedProgram. For C++ deployment, use a TorchScript file
0 commit comments