Skip to content

Commit 867acf2

Browse files
authored
Merge pull request #609 from Krovatkin/krovatkin/seth_feedback
fix confusion w.r.t. which model to serialize and use in cpp_export tutorial
2 parents 4174b21 + 06343d7 commit 867acf2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

advanced_source/cpp_export.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Loading a PyTorch Model in C++
22
==============================
33

4+
**This tutorial was updated to work with PyTorch 1.2**
5+
46
As its name suggests, the primary interface to PyTorch is the Python
57
programming language. While Python is a suitable and preferred language for
68
many scenarios requiring dynamism and ease of iteration, there are equally many
@@ -129,10 +131,11 @@ earlier in the tracing example. To perform this serialization, simply call
129131
`save <https://pytorch.org/docs/master/jit.html#torch.jit.ScriptModule.save>`_
130132
on the module and pass it a filename::
131133

132-
traced_script_module.save("model.pt")
134+
traced_script_module.save("traced_resnet_model.pt")
133135

134-
This will produce a ``model.pt`` file in your working directory. We have now
135-
officially left the realm of Python and are ready to cross over to the sphere
136+
This will produce a ``traced_resnet_model.pt`` file in your working directory.
137+
If you also would like to serialize ``my_module``, call ``my_module.save("my_module_model.pt")``
138+
We have now officially left the realm of Python and are ready to cross over to the sphere
136139
of C++.
137140

138141
Step 3: Loading Your Script Module in C++
@@ -285,13 +288,14 @@ distribution. If all goes well, it will look something like this:
285288
[100%] Linking CXX executable example-app
286289
[100%] Built target example-app
287290
288-
If we supply the path to the serialized ``ResNet18`` model we created earlier
291+
If we supply the path to the traced ``ResNet18`` model ``traced_resnet_model.pt`` we created earlier
289292
to the resulting ``example-app`` binary, we should be rewarded with a friendly
290-
"ok":
293+
"ok". Please note, if try to run this example with ``my_module_model.pt`` you will get an error saying that
294+
your input is of an incompatible shape. ``my_module_model.pt`` expects 1D instead of 4D.
291295
292296
.. code-block:: sh
293297
294-
root@4b5a67132e81:/example-app/build# ./example-app model.pt
298+
root@4b5a67132e81:/example-app/build# ./example-app <path_to_model>/traced_resnet_model.pt
295299
ok
296300
297301
Step 4: Executing the Script Module in C++
@@ -338,7 +342,7 @@ application and running it with the same serialized model:
338342
[ 50%] Building CXX object CMakeFiles/example-app.dir/example-app.cpp.o
339343
[100%] Linking CXX executable example-app
340344
[100%] Built target example-app
341-
root@4b5a67132e81:/example-app/build# ./example-app model.pt
345+
root@4b5a67132e81:/example-app/build# ./example-app traced_resnet_model.pt
342346
-0.2698 -0.0381 0.4023 -0.3010 -0.0448
343347
[ Variable[CPUFloatType]{1,5} ]
344348

0 commit comments

Comments
 (0)