11Loading 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
77As 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
288288Step 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
292292couple lines of code away from executing it! Let' s add those lines to our C++
293293application' 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
342342Looks 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+
344351Step 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
366373As 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