Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit efb8235

Browse files
goldsboroughsoumith
authored andcommitted
Some nits in TorchScript export tutorial + note about cuda (#349)
1 parent 9067093 commit efb8235

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

advanced_source/cpp_export.rst

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

4-
.. attention:: This tutorial requires PyTorch 1.0 (preview) or later.
4+
.. attention:: This tutorial requires PyTorch 1.0 (preview) or later.
55
For installation information visit http://pytorch.org/get-started.
66

77
As its name suggests, the primary interface to PyTorch is the Python
@@ -288,7 +288,7 @@ to the resulting ``example-app`` binary, we should be rewarded with a friendly
288288
Step 4: Executing the Script Module in C++
289289
----------------------------------------
290290
291-
Having succesfully loaded our serialized ``ResNet18`` in C++, we are now just a
291+
Having successfully loaded our serialized ``ResNet18`` in C++, we are now just a
292292
couple lines of code away from executing it! Let's add those lines to our C++
293293
application's ``main()`` function:
294294
@@ -299,7 +299,7 @@ application's ``main()`` function:
299299
inputs.push_back(torch::ones({1, 3, 224, 224}));
300300
301301
// Execute the model and turn its output into a tensor.
302-
auto output = module->forward(inputs).toTensor();
302+
at::Tensor output = module->forward(inputs).toTensor();
303303
304304
std::cout << output.slice(/*dim=*/1, /*start=*/0, /*end=*/5) << '\n';
305305
@@ -341,6 +341,13 @@ For reference, the output in Python previously was::
341341
342342
Looks like a good match!
343343
344+
.. tip::
345+
346+
To move your model to GPU memory, you can write ``model->to(at::kCUDA);``.
347+
Make sure the inputs to a model living in CUDA memory are also in CUDA memory
348+
by calling ``tensor.to(at::kCUDA)``, which will return a new tensor in CUDA
349+
memory.
350+
344351
Step 5: Getting Help and Exploring the API
345352
------------------------------------------
346353
@@ -361,7 +368,7 @@ the following links may be generally helpful:
361368
362369
- The Torch Script reference: https://pytorch.org/docs/master/jit.html
363370
- The PyTorch C++ API documentation: https://pytorch.org/cppdocs/
364-
- The Pytorch Python API documentation: https://pytorch.org/docs/
371+
- The PyTorch Python API documentation: https://pytorch.org/docs/
365372
366373
As always, if you run into any problems or have questions, you can use our
367374
`forum <https://discuss.pytorch.org/>`_ or `GitHub issues

0 commit comments

Comments
 (0)