Skip to content

Commit 44eeb9c

Browse files
vellamikenarendasan
authored andcommitted
Made getting started example more comprehensive
Signed-off-by: Mike Vella <[email protected]>
1 parent fe0a9aa commit 44eeb9c

File tree

7 files changed

+79
-35
lines changed

7 files changed

+79
-35
lines changed

docs/_cpp_api/structtrtorch_1_1ExtraInfo.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,10 @@ <h2 id="struct-documentation">
946946
<a class="reference internal" href="classtrtorch_1_1ExtraInfo_1_1DataType.html#_CPPv4N7trtorch9ExtraInfo8DataTypeE" title="trtorch::ExtraInfo::DataType">
947947
DataType
948948
</a>
949-
::kFloat
949+
::
950+
<a class="reference internal" href="classtrtorch_1_1ExtraInfo_1_1DataType.html#_CPPv4N7trtorch9ExtraInfo8DataType5Value6kFloatE" title="trtorch::ExtraInfo::DataType::kFloat">
951+
kFloat
952+
</a>
950953
<a class="headerlink" href="#_CPPv4N7trtorch9ExtraInfo12op_precisionE" title="Permalink to this definition">
951954
952955
</a>
@@ -1082,7 +1085,10 @@ <h2 id="struct-documentation">
10821085
<a class="reference internal" href="classtrtorch_1_1ExtraInfo_1_1DeviceType.html#_CPPv4N7trtorch9ExtraInfo10DeviceTypeE" title="trtorch::ExtraInfo::DeviceType">
10831086
DeviceType
10841087
</a>
1085-
::kGPU
1088+
::
1089+
<a class="reference internal" href="classtrtorch_1_1ExtraInfo_1_1DeviceType.html#_CPPv4N7trtorch9ExtraInfo10DeviceType5Value4kGPUE" title="trtorch::ExtraInfo::DeviceType::kGPU">
1090+
kGPU
1091+
</a>
10861092
<a class="headerlink" href="#_CPPv4N7trtorch9ExtraInfo6deviceE" title="Permalink to this definition">
10871093
10881094
</a>

docs/_sources/tutorials/getting_started.rst.txt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ For example, we can define a LeNet module like this:
2121
.. code-block:: python
2222
:linenos:
2323
24+
import torch.nn as nn
25+
import torch.nn.functional as F
26+
2427
class LeNetFeatExtractor(nn.Module):
2528
def __init__(self):
2629
super(LeNetFeatExtractor, self).__init__()
@@ -56,6 +59,7 @@ For example, we can define a LeNet module like this:
5659
x = self.feat(x)
5760
x = self.classifer(x)
5861
return x
62+
5963
.
6064

6165
Obviously you may want to consolidate such a simple model into a single module but we can see the composability of PyTorch here
@@ -67,15 +71,20 @@ To trace an instance of our LeNet module, we can call ``torch.jit.trace`` with a
6771

6872
.. code-block:: python
6973
74+
import torch.jit
75+
7076
model = LeNet()
71-
traced_model = torch.jit.trace(model, torch.empty([1,1,32,32]))
77+
input_data = torch.empty([1,1,32,32])
78+
traced_model = torch.jit.trace(model, input_data)
7279
7380
Scripting actually inspects your code with a compiler and generates an equivalent TorchScript program. The difference is that since tracing
7481
is following the execution of your module, it cannot pick up control flow for instance. By working from the Python code, the compiler can
7582
include these components. We can run the script compiler on our LeNet module by calling ``torch.jit.script``
7683

7784
.. code-block:: python
7885
86+
import torch.jit
87+
7988
model = LeNet()
8089
script_model = torch.jit.script(model)
8190
@@ -138,20 +147,23 @@ to load in a deployment application. In order to load a TensorRT/TorchScript mod
138147
import trtorch
139148
140149
...
150+
151+
script_model.eval() # torch module needs to be in eval (not training) mode
152+
141153
compile_settings = {
142154
"input_shapes": [
143155
{
144-
"min": [1, 3, 224, 224],
145-
"opt": [1, 3, 512, 512],
146-
"max": [1, 3, 1024, 1024]
147-
}, # For static size [1, 3, 224, 224]
156+
"min": [1, 1, 32, 32],
157+
"opt": [1, 1, 32, 32],
158+
"max": [1, 1, 32, 32]
159+
},
148160
],
149-
"op_precision": torch.half # Run with FP16
161+
"op_precision": torch.half # Run with fp16
150162
}
151163
152-
trt_ts_module = trtorch.compile(torch_script_module, compile_settings)
164+
trt_ts_module = trtorch.compile(script_model, compile_settings)
153165
154-
input_data = input_data.half()
166+
input_data = input_data.to('cuda').half()
155167
result = trt_ts_module(input_data)
156168
torch.jit.save(trt_ts_module, "trt_ts_module.ts")
157169
@@ -162,7 +174,7 @@ to load in a deployment application. In order to load a TensorRT/TorchScript mod
162174
import trtorch
163175
164176
trt_ts_module = torch.jit.load("trt_ts_module.ts")
165-
input_data = input_data.half()
177+
input_data = input_data.to('cuda').half()
166178
result = trt_ts_module(input_data)
167179
168180
.. _ts_in_cc:

docs/objects.inv

46 Bytes
Binary file not shown.

docs/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/sitemap.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/class_view_hierarchy.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/classtrtorch_1_1ExtraInfo_1_1DataType.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/classtrtorch_1_1ExtraInfo_1_1DeviceType.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/classtrtorch_1_1ptq_1_1Int8CacheCalibrator.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/classtrtorch_1_1ptq_1_1Int8Calibrator.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1a18d295a837ac71add5578860b55e5502.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1a20c1fbeb21757871c52299dc52351b5f.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1a25ee153c325dfc7466a33cbd5c1ff055.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1a48d6029a45583a06848891cb0e86f7ba.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1a71b02dddfabe869498ad5a88e11c440f.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1a9d31d0569348d109b1b069b972dd143e.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1abe87b341f562fd1cf40b7672e4d759da.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1ae1c56ab8a40af292a9a4964651524d84.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/dir_cpp.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/dir_cpp_api.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/dir_cpp_api_include.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/dir_cpp_api_include_trtorch.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/enum_logging_8h_1a5f612ff2f783ff4fbe89d168f0d817d4.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/file_cpp_api_include_trtorch_logging.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/file_cpp_api_include_trtorch_macros.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/file_cpp_api_include_trtorch_ptq.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/file_cpp_api_include_trtorch_trtorch.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/file_view_hierarchy.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1a118d65b179defff7fff279eb9cd126cb.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1a396a688110397538f8b3fb7dfdaf38bb.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1a9b420280bfacc016d7e36a5704021949.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1aa533955a2b908db9e5df5acdfa24715f.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1abc57d473f3af292551dee8b9c78373ad.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1adf5435f0dbb09c0d931a1b851847236b.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1aef44b69c62af7cf2edc8875a9506641a.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_ptq_8h_1a4422781719d7befedb364cacd91c6247.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_ptq_8h_1a5f33b142bc2f3f2aaf462270b3ad7e31.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_trtorch_8h_1a2cf17d43ba9117b3b4d652744b4f0447.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_trtorch_8h_1a536bba54b70e44554099d23fa3d7e804.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_trtorch_8h_1a726f6e7091b6b7be45b5a4275b2ffb10.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_trtorch_8h_1ab01696cfe08b6a5293c55935a9713c25.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_trtorch_8h_1ae38897d1ca4438227c970029d0f76fb5.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/namespace_trtorch.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/namespace_trtorch__logging.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/namespace_trtorch__ptq.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/program_listing_file_cpp_api_include_trtorch_logging.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/program_listing_file_cpp_api_include_trtorch_macros.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/program_listing_file_cpp_api_include_trtorch_ptq.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/program_listing_file_cpp_api_include_trtorch_trtorch.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/structtrtorch_1_1ExtraInfo.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/structtrtorch_1_1ExtraInfo_1_1InputRange.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/trtorch_cpp.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/unabridged_api.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/unabridged_orphan.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/index.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/py_api/logging.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/py_api/trtorch.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/tutorials/installation.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/genindex.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/search.html</loc></url></urlset>
1+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/class_view_hierarchy.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/classtrtorch_1_1ExtraInfo_1_1DataType.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/classtrtorch_1_1ExtraInfo_1_1DeviceType.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/classtrtorch_1_1ptq_1_1Int8CacheCalibrator.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/classtrtorch_1_1ptq_1_1Int8Calibrator.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1a18d295a837ac71add5578860b55e5502.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1a20c1fbeb21757871c52299dc52351b5f.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1a25ee153c325dfc7466a33cbd5c1ff055.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1a48d6029a45583a06848891cb0e86f7ba.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1a71b02dddfabe869498ad5a88e11c440f.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1a9d31d0569348d109b1b069b972dd143e.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1abe87b341f562fd1cf40b7672e4d759da.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/define_macros_8h_1ae1c56ab8a40af292a9a4964651524d84.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/dir_cpp.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/dir_cpp_api.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/dir_cpp_api_include.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/dir_cpp_api_include_trtorch.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/enum_logging_8h_1a5f612ff2f783ff4fbe89d168f0d817d4.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/file_cpp_api_include_trtorch_logging.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/file_cpp_api_include_trtorch_macros.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/file_cpp_api_include_trtorch_ptq.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/file_cpp_api_include_trtorch_trtorch.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/file_view_hierarchy.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1a118d65b179defff7fff279eb9cd126cb.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1a396a688110397538f8b3fb7dfdaf38bb.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1a9b420280bfacc016d7e36a5704021949.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1aa533955a2b908db9e5df5acdfa24715f.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1abc57d473f3af292551dee8b9c78373ad.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1adf5435f0dbb09c0d931a1b851847236b.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_logging_8h_1aef44b69c62af7cf2edc8875a9506641a.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_ptq_8h_1a4422781719d7befedb364cacd91c6247.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_ptq_8h_1a5f33b142bc2f3f2aaf462270b3ad7e31.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_trtorch_8h_1a2cf17d43ba9117b3b4d652744b4f0447.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_trtorch_8h_1a536bba54b70e44554099d23fa3d7e804.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_trtorch_8h_1a726f6e7091b6b7be45b5a4275b2ffb10.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_trtorch_8h_1ab01696cfe08b6a5293c55935a9713c25.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/function_trtorch_8h_1ae38897d1ca4438227c970029d0f76fb5.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/namespace_trtorch.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/namespace_trtorch__logging.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/namespace_trtorch__ptq.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/program_listing_file_cpp_api_include_trtorch_logging.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/program_listing_file_cpp_api_include_trtorch_macros.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/program_listing_file_cpp_api_include_trtorch_ptq.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/program_listing_file_cpp_api_include_trtorch_trtorch.h.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/structtrtorch_1_1ExtraInfo.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/structtrtorch_1_1ExtraInfo_1_1InputRange.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/trtorch_cpp.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/unabridged_api.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/_cpp_api/unabridged_orphan.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/contributors/conversion.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/contributors/execution.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/contributors/lowering.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/contributors/phases.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/contributors/system_overview.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/contributors/useful_links.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/contributors/writing_converters.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/index.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/py_api/logging.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/py_api/trtorch.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/tutorials/getting_started.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/tutorials/installation.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/tutorials/ptq.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/tutorials/trtorchc.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/genindex.html</loc></url><url><loc>https://nvidia.github.io/TRTorch/search.html</loc></url></urlset>

0 commit comments

Comments
 (0)