Skip to content

Commit

Permalink
fix: Update notebooks with new library name Torch-TensorRT
Browse files Browse the repository at this point in the history
Signed-off-by: Dheeraj Peri <[email protected]>
  • Loading branch information
peri044 committed Oct 22, 2021
1 parent 65ffaef commit 8274fd9
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 96 deletions.
16 changes: 8 additions & 8 deletions notebooks/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Jupyter demo notebooks
This folder contains demo notebooks for TRTorch.
This folder contains demo notebooks for Torch-TensorRT.

## 1. Requirements

Expand All @@ -8,19 +8,19 @@ The most convenient way to run these notebooks is via a docker container, which
First, clone the repository:

```
git clone https://github.com/NVIDIA/TRTorch
git clone https://github.com/NVIDIA/Torch-TensorRT
```

Next, build the NVIDIA TRTorch container (from repo root):
Next, build the NVIDIA Torch-TensorRT container (from repo root):

```
docker build -t trtorch -f ./docker/Dockerfile.21.06 .
docker build -t torch_tensorrt -f ./docker/Dockerfile.21.06 .
```

Then launch the container with:

```
docker run --runtime=nvidia -it --rm --ipc=host --net=host trtorch
docker run --runtime=nvidia -it --rm --ipc=host --net=host torch_tensorrt
```

Within the docker interactive bash session, start Jupyter with
Expand All @@ -38,14 +38,14 @@ in, for example:
```http://[host machine]:8888/?token=aae96ae9387cd28151868fee318c3b3581a2d794f3b25c6b```


Within the container, the notebooks themselves are located at `/workspace/TRTorch/notebooks`.
Within the container, the notebooks themselves are located at `/workspace/Torch-TensorRT/notebooks`.

## 2. Notebook list

- [lenet-getting-started.ipynb](lenet-getting-started.ipynb): simple example on a LeNet network.
- [ssd-object-detection-demo.ipynb](ssd-object-detection-demo.ipynb): demo for compiling a pretrained SSD model using TRTorch.
- [ssd-object-detection-demo.ipynb](ssd-object-detection-demo.ipynb): demo for compiling a pretrained SSD model using Torch-TensorRT.
- [Resnet50-example.ipynb](Resnet50-example.ipynb): demo on the ResNet-50 network.
- [vgg-qat.ipynb](vgg-qat.ipynb): Quantization Aware Trained models in INT8 using TRTorch
- [vgg-qat.ipynb](vgg-qat.ipynb): Quantization Aware Trained models in INT8 using Torch-TensorRT

```python

Expand Down
43 changes: 18 additions & 25 deletions notebooks/Resnet50-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"source": [
"<img src=\"http://developer.download.nvidia.com/compute/machine-learning/frameworks/nvidia_logo.png\" style=\"width: 90px; float: right;\">\n",
"\n",
"# TRTorch Getting Started - ResNet 50"
"# Torch-TensorRT Getting Started - ResNet 50"
]
},
{
Expand All @@ -41,7 +41,7 @@
"\n",
"When deploying on NVIDIA GPUs TensorRT, NVIDIA's Deep Learning Optimization SDK and Runtime is able to take models from any major framework and specifically tune them to perform better on specific target hardware in the NVIDIA family be it an A100, TITAN V, Jetson Xavier or NVIDIA's Deep Learning Accelerator. TensorRT performs a couple sets of optimizations to achieve this. TensorRT fuses layers and tensors in the model graph, it then uses a large kernel library to select implementations that perform best on the target GPU. TensorRT also has strong support for reduced operating precision execution which allows users to leverage the Tensor Cores on Volta and newer GPUs as well as reducing memory and computation footprints on device.\n",
"\n",
"TRTorch is a compiler that uses TensorRT to optimize TorchScript code, compiling standard TorchScript modules into ones that internally run with TensorRT optimizations. This enables you to continue to remain in the PyTorch ecosystem, using all the great features PyTorch has such as module composability, its flexible tensor implementation, data loaders and more. TRTorch is available to use with both PyTorch and LibTorch."
"Torch-TensorRT is a compiler that uses TensorRT to optimize TorchScript code, compiling standard TorchScript modules into ones that internally run with TensorRT optimizations. This enables you to continue to remain in the PyTorch ecosystem, using all the great features PyTorch has such as module composability, its flexible tensor implementation, data loaders and more. Torch-TensorRT is available to use with both PyTorch and LibTorch."
]
},
{
Expand All @@ -50,13 +50,13 @@
"source": [
"### Learning objectives\n",
"\n",
"This notebook demonstrates the steps for compiling a TorchScript module with TRTorch on a pretrained ResNet-50 network, and running it to test the speedup obtained.\n",
"This notebook demonstrates the steps for compiling a TorchScript module with Torch-TensorRT on a pretrained ResNet-50 network, and running it to test the speedup obtained.\n",
"\n",
"## Content\n",
"1. [Requirements](#1)\n",
"1. [ResNet-50 Overview](#2)\n",
"1. [Creating TorchScript modules](#3)\n",
"1. [Compiling with TRTorch](#4)\n",
"1. [Compiling with Torch-TensorRT](#4)\n",
"1. [Conclusion](#5)"
]
},
Expand Down Expand Up @@ -375,7 +375,7 @@
}
],
"source": [
"# Model benchmark without TRTorch/TensorRT\n",
"# Model benchmark without Torch-TensorRT\n",
"model = resnet50_model.eval().to(\"cuda\")\n",
"benchmark(model, input_shape=(128, 3, 224, 224), nruns=100)"
]
Expand All @@ -387,12 +387,12 @@
"<a id=\"3\"></a>\n",
"## 3. Creating TorchScript modules\n",
"\n",
"To compile with TRTorch, the model must first be in **TorchScript**. TorchScript is a programming language included in PyTorch which removes the Python dependency normal PyTorch models have. This conversion is done via a JIT compiler which given a PyTorch Module will generate an equivalent TorchScript Module. There are two paths that can be used to generate TorchScript: **Tracing** and **Scripting**. \n",
"To compile with Torch-TensorRT, the model must first be in **TorchScript**. TorchScript is a programming language included in PyTorch which removes the Python dependency normal PyTorch models have. This conversion is done via a JIT compiler which given a PyTorch Module will generate an equivalent TorchScript Module. There are two paths that can be used to generate TorchScript: **Tracing** and **Scripting**. \n",
"\n",
"- Tracing follows execution of PyTorch generating ops in TorchScript corresponding to what it sees. \n",
"- Scripting does an analysis of the Python code and generates TorchScript, this allows the resulting graph to include control flow which tracing cannot do. \n",
"\n",
"Tracing is more likely to compile successfully with TRTorch due to simplicity (though both systems are supported). We start with an example of the traced model in TorchScript."
"Tracing is more likely to compile successfully with Torch-TensorRT due to simplicity (though both systems are supported). We start with an example of the traced model in TorchScript."
]
},
{
Expand Down Expand Up @@ -470,7 +470,7 @@
"metadata": {},
"source": [
"<a id=\"4\"></a>\n",
"## 4. Compiling with TRTorch"
"## 4. Compiling with Torch-TensorRT"
]
},
{
Expand All @@ -479,7 +479,7 @@
"source": [
"TorchScript modules behave just like normal PyTorch modules and are intercompatible. From TorchScript we can now compile a TensorRT based module. This module will still be implemented in TorchScript but all the computation will be done in TensorRT.\n",
"\n",
"As mentioned earlier, we start with an example of TRTorch compilation with the traced model.\n",
"As mentioned earlier, we start with an example of Torch-TensorRT compilation with the traced model.\n",
"\n",
"Note that we show benchmarking results of two precisions: FP32 (single precision) and FP16 (half precision)."
]
Expand All @@ -497,12 +497,12 @@
"metadata": {},
"outputs": [],
"source": [
"import trtorch\n",
"import torch_tensorrt\n",
"\n",
"# The compiled module will have precision as specified by \"op_precision\".\n",
"# Here, it will have FP16 precision.\n",
"trt_model_fp32 = trtorch.compile(traced_model, {\n",
" \"inputs\": [trtorch.Input((128, 3, 224, 224))],\n",
"trt_model_fp32 = torch_tensorrt.compile(traced_model, {\n",
" \"inputs\": [torch_tensorrt.Input((128, 3, 224, 224))],\n",
" \"enabled_precisions\": {torch.float32}, # Run with FP32\n",
" \"workspace_size\": 1 << 20\n",
"})\n",
Expand Down Expand Up @@ -554,12 +554,12 @@
"metadata": {},
"outputs": [],
"source": [
"import trtorch\n",
"import torch_tensorrt\n",
"\n",
"# The compiled module will have precision as specified by \"op_precision\".\n",
"# Here, it will have FP16 precision.\n",
"trt_model = trtorch.compile(traced_model, {\n",
" \"inputs\": [trtorch.Input((128, 3, 224, 224))],\n",
"trt_model = torch_tensorrt.compile(traced_model, {\n",
" \"inputs\": [torch_tensorrt.Input((128, 3, 224, 224))],\n",
" \"enabled_precisions\": {torch.float, torch.half}, # Run with FP16\n",
" \"workspace_size\": 1 << 20\n",
"})\n"
Expand Down Expand Up @@ -604,18 +604,11 @@
"<a id=\"5\"></a>\n",
"## 5. Conclusion\n",
"\n",
"In this notebook, we have walked through the complete process of compiling TorchScript models with TRTorch for ResNet-50 model and test the performance impact of the optimization. With TRTorch, we observe a speedup of **1.4X** with FP32, and **3.0X** with FP16.\n",
"In this notebook, we have walked through the complete process of compiling TorchScript models with Torch-TensorRT for ResNet-50 model and test the performance impact of the optimization. With Torch-TensorRT, we observe a speedup of **1.4X** with FP32, and **3.0X** with FP16.\n",
"\n",
"### What's next\n",
"Now it's time to try TRTorch on your own model. Fill out issues at https://github.com/NVIDIA/TRTorch. Your involvement will help future development of TRTorch.\n"
"Now it's time to try Torch-TensorRT on your own model. Fill out issues at https://github.com/NVIDIA/Torch-TensorRT. Your involvement will help future development of Torch-TensorRT.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -634,7 +627,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.6.13"
}
},
"nbformat": 4,
Expand Down
7 changes: 3 additions & 4 deletions notebooks/WORKSPACE.notebook
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
workspace(name = "TRTorch")
workspace(name = "Torch-TensorRT")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
Expand Down Expand Up @@ -85,11 +85,11 @@ new_local_repository(
# Testing Dependencies (optional - comment out on aarch64)
#########################################################################
pip3_import(
name = "trtorch_py_deps",
name = "torch_tensorrt_py_deps",
requirements = "//py:requirements.txt"
)

load("@trtorch_py_deps//:requirements.bzl", "pip_install")
load("@torch_tensorrt_py_deps//:requirements.bzl", "pip_install")
pip_install()

pip3_import(
Expand All @@ -99,4 +99,3 @@ pip3_import(

load("@py_test_deps//:requirements.bzl", "pip_install")
pip_install()

32 changes: 16 additions & 16 deletions notebooks/lenet-getting-started.ipynb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"source": [
"<img src=\"http://developer.download.nvidia.com/compute/machine-learning/frameworks/nvidia_logo.png\" style=\"width: 90px; float: right;\">\n",
"\n",
"# TRTorch Getting Started - LeNet"
"# Torch-TensorRT Getting Started - LeNet"
]
},
{
Expand All @@ -41,7 +41,7 @@
"\n",
"When deploying on NVIDIA GPUs TensorRT, NVIDIA's Deep Learning Optimization SDK and Runtime is able to take models from any major framework and specifically tune them to perform better on specific target hardware in the NVIDIA family be it an A100, TITAN V, Jetson Xavier or NVIDIA's Deep Learning Accelerator. TensorRT performs a couple sets of optimizations to achieve this. TensorRT fuses layers and tensors in the model graph, it then uses a large kernel library to select implementations that perform best on the target GPU. TensorRT also has strong support for reduced operating precision execution which allows users to leverage the Tensor Cores on Volta and newer GPUs as well as reducing memory and computation footprints on device.\n",
"\n",
"TRTorch is a compiler that uses TensorRT to optimize TorchScript code, compiling standard TorchScript modules into ones that internally run with TensorRT optimizations. This enables you to continue to remain in the PyTorch ecosystem, using all the great features PyTorch has such as module composability, its flexible tensor implementation, data loaders and more. TRTorch is available to use with both PyTorch and LibTorch."
"Torch-TensorRT is a compiler that uses TensorRT to optimize TorchScript code, compiling standard TorchScript modules into ones that internally run with TensorRT optimizations. This enables you to continue to remain in the PyTorch ecosystem, using all the great features PyTorch has such as module composability, its flexible tensor implementation, data loaders and more. Torch-TensorRT is available to use with both PyTorch and LibTorch."
]
},
{
Expand All @@ -50,12 +50,12 @@
"source": [
"### Learning objectives\n",
"\n",
"This notebook demonstrates the steps for compiling a TorchScript module with TRTorch on a simple LeNet network. \n",
"This notebook demonstrates the steps for compiling a TorchScript module with Torch-TensorRT on a simple LeNet network. \n",
"\n",
"## Content\n",
"1. [Requirements](#1)\n",
"1. [Creating TorchScript modules](#2)\n",
"1. [Compiling with TRTorch](#3)"
"1. [Compiling with Torch-TensorRT](#3)"
]
},
{
Expand Down Expand Up @@ -423,7 +423,7 @@
"metadata": {},
"source": [
"<a id=\"3\"></a>\n",
"## 3. Compiling with TRTorch"
"## 3. Compiling with Torch-TensorRT"
]
},
{
Expand All @@ -432,7 +432,7 @@
"source": [
"### TorchScript traced model\n",
"\n",
"First, we compile the TorchScript traced model with TRTorch. Notice the performance impact."
"First, we compile the TorchScript traced model with Torch-TensorRT. Notice the performance impact."
]
},
{
Expand All @@ -441,11 +441,11 @@
"metadata": {},
"outputs": [],
"source": [
"import trtorch\n",
"import torch_tensorrt\n",
"\n",
"# We use a batch-size of 1024, and half precision\n",
"compile_settings = {\n",
" \"inputs\": [trtorch.Input(\n",
" \"inputs\": [torch_tensorrt.Input(\n",
" min_shape=[1024, 1, 32, 32],\n",
" opt_shape=[1024, 1, 33, 33],\n",
" max_shape=[1024, 1, 34, 34],\n",
Expand All @@ -454,7 +454,7 @@
" \"enabled_precisions\": {torch.float, torch.half} # Run with FP16\n",
"}\n",
"\n",
"trt_ts_module = trtorch.compile(traced_model, compile_settings)\n",
"trt_ts_module = torch_tensorrt.compile(traced_model, compile_settings)\n",
"\n",
"input_data = torch.randn((1024, 1, 32, 32))\n",
"input_data = input_data.half().to(\"cuda\")\n",
Expand Down Expand Up @@ -501,7 +501,7 @@
"source": [
"### TorchScript script model\n",
"\n",
"Next, we compile the TorchScript script model with TRTorch. Notice the performance impact."
"Next, we compile the TorchScript script model with Torch-TensorRT. Notice the performance impact."
]
},
{
Expand All @@ -510,11 +510,11 @@
"metadata": {},
"outputs": [],
"source": [
"import trtorch\n",
"import torch_tensorrt\n",
"\n",
"# We use a batch-size of 1024, and half precision\n",
"compile_settings = {\n",
" \"inputs\": [trtorch.Input(\n",
" \"inputs\": [torch_tensorrt.Input(\n",
" min_shape=[1024, 1, 32, 32],\n",
" opt_shape=[1024, 1, 33, 33],\n",
" max_shape=[1024, 1, 34, 34],\n",
Expand All @@ -523,7 +523,7 @@
" \"enabled_precisions\": {torch.float, torch.half} # Run with FP16\n",
"}\n",
"\n",
"trt_script_module = trtorch.compile(script_model, compile_settings)\n",
"trt_script_module = torch_tensorrt.compile(script_model, compile_settings)\n",
"\n",
"input_data = torch.randn((1024, 1, 32, 32))\n",
"input_data = input_data.half().to(\"cuda\")\n",
Expand Down Expand Up @@ -570,10 +570,10 @@
"source": [
"## Conclusion\n",
"\n",
"In this notebook, we have walked through the complete process of compiling TorchScript models with TRTorch and test the performance impact of the optimization.\n",
"In this notebook, we have walked through the complete process of compiling TorchScript models with Torch-TensorRT and test the performance impact of the optimization.\n",
"\n",
"### What's next\n",
"Now it's time to try TRTorch on your own model. Fill out issues at https://github.com/NVIDIA/TRTorch. Your involvement will help future development of TRTorch.\n"
"Now it's time to try Torch-TensorRT on your own model. Fill out issues at https://github.com/NVIDIA/Torch-TensorRT. Your involvement will help future development of Torch-TensorRT.\n"
]
}
],
Expand All @@ -593,7 +593,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.6.13"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 8274fd9

Please sign in to comment.