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: docs/_sources/tutorials/ptq.rst.txt
+70-5Lines changed: 70 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,14 +14,17 @@ the TensorRT calibrator. With TRTorch we look to leverage existing infrastructur
14
14
calibrators easier.
15
15
16
16
LibTorch provides a ``DataLoader`` and ``Dataset`` API which steamlines preprocessing and batching input data.
17
-
This section of the PyTorch documentation has more information https://pytorch.org/tutorials/advanced/cpp_frontend.html#loading-data.
17
+
These APIs are exposed via both C++ and Python interface which makes it easier for the end user.
18
+
For C++ interface, we use ``torch::Dataset`` and ``torch::data::make_data_loader`` objects to construct and perform pre-processing on datasets.
19
+
The equivalent functionality in python interface uses ``torch.utils.data.Dataset`` and ``torch.utils.data.DataLoader``.
20
+
This section of the PyTorch documentation has more information https://pytorch.org/tutorials/advanced/cpp_frontend.html#loading-data and https://pytorch.org/tutorials/recipes/recipes/loading_data_recipe.html.
18
21
TRTorch uses Dataloaders as the base of a generic calibrator implementation. So you will be able to reuse or quickly
19
22
implement a ``torch::Dataset`` for your target domain, place it in a DataLoader and create a INT8 Calibrator
20
23
which you can provide to TRTorch to run INT8 Calibration during compliation of your module.
21
24
22
-
.. _writing_ptq:
25
+
.. _writing_ptq_cpp:
23
26
24
-
How to create your own PTQ application
27
+
How to create your own PTQ application in C++
25
28
----------------------------------------
26
29
27
30
Here is an example interface of a ``torch::Dataset`` class for CIFAR10:
@@ -132,14 +135,76 @@ Then all thats required to setup the module for INT8 calibration is to set the f
132
135
auto trt_mod = trtorch::CompileGraph(mod, compile_spec);
133
136
134
137
If you have an existing Calibrator implementation for TensorRT you may directly set the ``ptq_calibrator`` field with a pointer to your calibrator and it will work as well.
135
-
136
138
From here not much changes in terms of how to execution works. You are still able to fully use LibTorch as the sole interface for inference. Data should remain
137
139
in FP32 precision when it's passed into `trt_mod.forward`. There exists an example application in the TRTorch demo that takes you from training a VGG16 network on
138
140
CIFAR10 to deploying in INT8 with TRTorch here: https://github.com/NVIDIA/TRTorch/tree/master/cpp/ptq
139
141
142
+
.. _writing_ptq_python:
143
+
144
+
How to create your own PTQ application in Python
145
+
----------------------------------------
146
+
147
+
TRTorch Python API provides an easy and convenient way to use pytorch dataloaders with TensorRT calibrators. ``DataLoaderCalibrator`` class can be used to create
148
+
a TensorRT calibrator by providing desired configuration. The following code demonstrates an example on how to use it
In the cases where there is a pre-existing calibration cache file that users want to use, ``CacheCalibrator`` can be used without any dataloaders. The following example demonstrates how
If you already have an existing calibrator class (implemented directly using TensorRT API), you can directly set the calibrator field to your class which can be very convenient.
202
+
For a demo on how PTQ can be performed on a VGG network using TRTorch API, you can refer to https://github.com/NVIDIA/TRTorch/blob/master/tests/py/test_ptq_dataloader_calibrator.py
203
+
and https://github.com/NVIDIA/TRTorch/blob/master/tests/py/test_ptq_trt_calibrator.py
204
+
140
205
Citations
141
206
^^^^^^^^^^^
142
207
143
208
Krizhevsky, A., & Hinton, G. (2009). Learning multiple layers of features from tiny images.
144
209
145
-
Simonyan, K., & Zisserman, A. (2014). Very deep convolutional networks for large-scale image recognition. arXiv preprint arXiv:1409.1556.
210
+
Simonyan, K., & Zisserman, A. (2014). Very deep convolutional networks for large-scale image recognition. arXiv preprint arXiv:1409.1556.
0 commit comments