152152
153153.. code-block :: cpp
154154
155- #include <torch/op .h> // One-stop header.
155+ #include <torch/script .h> // One-stop header.
156156
157157 #include <iostream>
158158 #include <memory>
@@ -170,10 +170,10 @@ do:
170170 std::cout << "ok\n";
171171 }
172172
173- The ``<torch/op .h> `` header encompasses all relevant includes from the LibTorch
174- library necessary to run the example. Our application accepts the file path to
175- a serialized PyTorch ``ScriptModule `` as its only command line argument and
176- then proceeds to deserialize the module using the ``torch::jit::load() ``
173+ The ``<torch/script .h> `` header encompasses all relevant includes from the
174+ LibTorch library necessary to run the example. Our application accepts the file
175+ path to a serialized PyTorch ``ScriptModule `` as its only command line argument
176+ and then proceeds to deserialize the module using the ``torch::jit::load() ``
177177function, which takes this file path as input. In return we receive a shared
178178pointer to a ``torch::jit::script::Module ``, the equivalent to a
179179``torch.jit.ScriptModule `` in C++. For now, we only verify that this pointer is
@@ -193,15 +193,13 @@ minimal ``CMakeLists.txt`` to build it could look as simple as:
193193 find_package(Torch REQUIRED)
194194
195195 add_executable(example-app example-app.cpp)
196- target_include_directories(example-app PRIVATE "${TORCH_INCLUDE_DIRS}")
197196 target_link_libraries(example-app "${TORCH_LIBRARIES}")
198- target_compile_definitions(example-app PRIVATE -D_GLIBCXX_USE_CXX11_ABI=0)
199197 set_property(TARGET example-app PROPERTY CXX_STANDARD 11)
200198
201199 The last thing we need to build the example application is the LibTorch
202- distribution. You can always grab the latest stable release from the `PyTorch
203- website <https://pytorch.org/> `_. If you download and unzip the latest archive
204- from that page , you should receive a folder with the following directory
200+ distribution. You can always grab the latest stable release from the `download
201+ page <https://pytorch.org/> `_ on the PyTorch website . If you download and unzip
202+ the latest archive , you should receive a folder with the following directory
205203structure:
206204
207205.. code-block :: sh
@@ -307,12 +305,15 @@ The first two lines set up the inputs to our model. We create a vector of
307305accept and return) and add a single input. To create the input tensor, we use
308306` ` torch::ones()` ` , the equivalent to ` ` torch.ones` ` in the C++ API. We then
309307run the ` ` script::Module` ` 's ` ` forward` ` method, passing it the input vector we
310- created. In return we get a new ` ` IValue` ` , which we convert to a tensor.
308+ created. In return we get a new ` ` IValue` ` , which we convert to a tensor by
309+ calling ` ` toTensor()` ` .
311310
312311.. tip::
313312
314313 To learn more about functions like ` ` torch::ones` ` and the PyTorch C++ API in
315- general, refer to its documentation at https://pytorch.org/cppdocs.
314+ general, refer to its documentation at https://pytorch.org/cppdocs. The
315+ PyTorch C++ API provides near feature parity with the Python API, allowing
316+ you to further manipulate and process tensors just like in Python.
316317
317318In the last line, we print the first five entries of the output. Since we
318319supplied the same input to our model in Python earlier in this tutorial, we
0 commit comments