Skip to content

Commit 953d600

Browse files
authored
Merge pull request #733 from jaybdub/torch2trt_plugins
- adds torch2trt_plugins library - adds native group_norm converter
2 parents 952d665 + 99e4c45 commit 953d600

24 files changed

+1690
-49
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [Master]
44

5+
- Added converter for ``torch.nn.functional.group_norm`` using native TensorRT layers
6+
- Added converter for ``torch.nn.ReflectionPad2d`` using plugin layer
7+
- Added torch2trt_plugins library
58
- Added support for Deep Learning Accelerator (DLA)
69
- Added support for explicit batch
710
- Added support for TensorRT 8

CMakeLists.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
cmake_minimum_required(VERSION 3.0.0)
2+
project(torch2trt_plugins VERSION 0.1.0)
3+
4+
# VARIABLES
5+
set(CUDA_ARCHITECTURES 53 62 72 87)
6+
7+
# BUILD PLUGINS LIBRARY
8+
find_package(CUDA REQUIRED)
9+
10+
enable_language(CUDA)
11+
12+
include_directories("${CUDA_INCLUDE_DIRS}")
13+
14+
add_library(torch2trt_plugins SHARED
15+
plugins/src/example_plugin.cu
16+
plugins/src/reflection_pad_2d_plugin.cu
17+
)
18+
set_property(TARGET torch2trt_plugins PROPERTY CUDA_ARCHITECTURES ${CUDA_ARCHITECTURES})
19+
20+
target_link_libraries(
21+
torch2trt_plugins
22+
nvinfer
23+
${CUDA_LIBRARIES}
24+
)
25+
26+
install (TARGETS torch2trt_plugins
27+
LIBRARY DESTINATION lib)
28+
29+
# BUILD TESTS
30+
find_package(Catch2 QUIET)
31+
32+
if(Catch2_FOUND)
33+
include(CTest)
34+
include(CPack)
35+
include(Catch)
36+
enable_testing()
37+
38+
add_executable(torch2trt_plugins_test
39+
plugins/src/tests.cpp
40+
plugins/src/example_plugin_test.cpp
41+
plugins/src/reflection_pad_2d_plugin_test.cpp
42+
)
43+
44+
set_property(TARGET torch2trt_plugins_test PROPERTY CUDA_ARCHITECTURES ${CUDA_ARCHITECTURES})
45+
46+
target_link_libraries(torch2trt_plugins_test
47+
PRIVATE
48+
Catch2::Catch2WithMain
49+
torch2trt_plugins
50+
nvinfer
51+
${CUDA_LIBRARIES}
52+
)
53+
54+
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
55+
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
56+
catch_discover_tests(torch2trt_plugins_test)
57+
endif()

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,31 @@ We tested the converter against these models using the [test.sh](test.sh) script
103103

104104
## Setup
105105

106-
> torch2trt depends on the TensorRT Python API. On Jetson, this is included with the latest JetPack. For desktop, please follow the [TensorRT Installation Guide](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html). You may also try installing torch2trt inside one of the NGC PyTorch docker containers for [Desktop](https://ngc.nvidia.com/catalog/containers/nvidia:pytorch) or [Jetson](https://ngc.nvidia.com/catalog/containers/nvidia:l4t-pytorch).
106+
> Note: torch2trt depends on the TensorRT Python API. On Jetson, this is included with the latest JetPack. For desktop, please follow the [TensorRT Installation Guide](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html). You may also try installing torch2trt inside one of the NGC PyTorch docker containers for [Desktop](https://ngc.nvidia.com/catalog/containers/nvidia:pytorch) or [Jetson](https://ngc.nvidia.com/catalog/containers/nvidia:l4t-pytorch).
107107
108-
### Option 1 - Without plugins
108+
### Step 1 - Install the torch2trt Python library
109109

110-
To install without compiling plugins, call the following
110+
To install the torch2trt Python library, call the following
111111

112112
```bash
113113
git clone https://github.com/NVIDIA-AI-IOT/torch2trt
114114
cd torch2trt
115115
python setup.py install
116116
```
117117

118-
### Option 2 - With plugins
118+
### Step 2 (optional) - Install the torch2trt plugins library
119119

120-
To install with plugins to support some operations in PyTorch that are not natviely supported with TensorRT, call the following
121-
122-
> Please note, this currently only includes the interpolate plugin. This plugin requires PyTorch 1.3+ for serialization.
120+
To install the torch2trt plugins library, call the following
123121

124122
```bash
125-
git clone https://github.com/NVIDIA-AI-IOT/torch2trt
126-
cd torch2trt
127-
sudo python setup.py install --plugins
123+
cmake -B build . && cmake --build build --target install && ldconfig
128124
```
129125

130-
### Option 3 - With support for experimental community contributed features
126+
This includes support for some layers which may not be supported natively by TensorRT. Once this library is found in the system, the associated layer converters in torch2trt are implicitly enabled.
127+
128+
> Note: torch2trt now maintains plugins as an independent library compiled with CMake. This makes compiled TensorRT engines more portable. If needed, the deprecated plugins (which depend on PyTorch) may still be installed by calling ``python setup.py install --plugins``.
129+
130+
### Step 3 (optional) - Install experimental community contributed features
131131

132132
To install torch2trt with experimental community contributed features under ``torch2trt.contrib``, like Quantization Aware Training (QAT)(`requires TensorRT>=7.0`), call the following,
133133

docker/21-06/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
FROM nvcr.io/nvidia/pytorch:21.06-py3
22

33

4-
RUN pip3 install termcolor
4+
RUN pip3 install termcolor
5+
6+
RUN git clone https://github.com/catchorg/Catch2.git && \
7+
cd Catch2 && \
8+
cmake -Bbuild -H. -DBUILD_TESTING=OFF && \
9+
cmake --build build/ --target install

docker/21-08/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM nvcr.io/nvidia/pytorch:21.08-py3
2+
3+
4+
RUN pip3 install termcolor
5+
6+
RUN git clone https://github.com/catchorg/Catch2.git && \
7+
cd Catch2 && \
8+
cmake -Bbuild -H. -DBUILD_TESTING=OFF && \
9+
cmake --build build/ --target install

docker/21-08/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
docker build -t torch2trt:21-08 -f $(pwd)/docker/21-08/Dockerfile .

docker/21-08/run.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
4+
docker run --gpus all -it -d --rm -v $(pwd):/torch2trt torch2trt:21-08

docker/21-09/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
FROM nvcr.io/nvidia/pytorch:21.09-py3
22

33

4-
RUN pip3 install termcolor
4+
RUN pip3 install termcolor
5+
6+
RUN git clone https://github.com/catchorg/Catch2.git && \
7+
cd Catch2 && \
8+
cmake -Bbuild -H. -DBUILD_TESTING=OFF && \
9+
cmake --build build/ --target install

docker/21-09/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22

33

4-
docker run --gpus all -it --rm -v $(pwd):/torch2trt torch2trt:21-09
4+
docker run --gpus all -it -d --rm -v $(pwd):/torch2trt torch2trt:21-09

0 commit comments

Comments
 (0)