Skip to content

Commit 1862f3d

Browse files
jbschlosserjafraustro
authored andcommitted
Update C++ frontend tutorial with template, working MNIST download link, and newer C++ / CMake versions (pytorch#3570)
[T237454564](https://www.internalfb.com/intern/tasks/?t=237454564) ## Description Updated the tutorial: * Added template header with clear prerequisites * Updated C++ version to 17 * Updated CMake to >= 3.5 from https://github.com/pytorch/examples/blob/main/cpp/dcgan/CMakeLists.txt * Fixed the link in the referenced `download_mnist.py` script to use the mirror at https://github.com/fgnt/mnist ## Checklist <!--- Make sure to add `x` to all items in the following checklist: --> - [x] The issue that is being fixed is referred in the description (see above "Fixes #ISSUE_NUMBER") - [x] Only one issue is addressed in this pull request - [x] Labels from the issue that this PR is fixing are added to this pull request - [x] No unnecessary issues are included into this pull request.
1 parent 96e1b18 commit 1862f3d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

advanced_source/cpp_frontend.rst

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1+
.. _cpp-frontend-tutorial:
2+
13
Using the PyTorch C++ Frontend
24
==============================
35

6+
**Author:** `Peter Goldsborough <https://github.com/goldsborough>`_
7+
8+
.. grid:: 2
9+
10+
.. grid-item-card:: :octicon:`mortar-board;1em;` What you will learn
11+
:class-card: card-prerequisites
12+
13+
* How to build a C++ application that utilizes the PyTorch C++ frontend
14+
* How to define and train neural networks from C++ using PyTorch abstractions
15+
16+
.. grid-item-card:: :octicon:`list-unordered;1em;` Prerequisites
17+
:class-card: card-prerequisites
18+
19+
* PyTorch 1.5 or later
20+
* Basic understanding of C++ programming
21+
* Basic Ubuntu Linux environment with CMake >= 3.5; similar commands will work in a MacOS / Windows environment
22+
* (Optional) A CUDA-based GPU for the GPU training sections
23+
424
The PyTorch C++ frontend is a pure C++ interface to the PyTorch machine learning
525
framework. While the primary interface to PyTorch naturally is Python, this
626
Python API sits atop a substantial C++ codebase providing foundational data
727
structures and functionality such as tensors and automatic differentiation. The
8-
C++ frontend exposes a pure C++11 API that extends this underlying C++ codebase
28+
C++ frontend exposes a pure C++17 API that extends this underlying C++ codebase
929
with tools required for machine learning training and inference. This includes a
1030
built-in collection of common components for neural network modeling; an API to
1131
extend this collection with custom modules; a library of popular optimization
@@ -137,14 +157,14 @@ on we'll use this ``CMakeLists.txt`` file:
137157

138158
.. code-block:: cmake
139159
140-
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
160+
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
141161
project(dcgan)
142162
143163
find_package(Torch REQUIRED)
144164
145165
add_executable(dcgan dcgan.cpp)
146166
target_link_libraries(dcgan "${TORCH_LIBRARIES}")
147-
set_property(TARGET dcgan PROPERTY CXX_STANDARD 14)
167+
set_property(TARGET dcgan PROPERTY CXX_STANDARD 17)
148168
149169
.. note::
150170

@@ -859,7 +879,7 @@ stacks them into a single tensor along the first dimension:
859879
860880
Note that the MNIST dataset should be located in the ``./mnist`` directory
861881
relative to wherever you execute the training binary from. You can use `this
862-
script <https://gist.github.com/goldsborough/6dd52a5e01ed73a642c1e772084bcd03>`_
882+
script <https://gist.github.com/jbschlosser/94347505df6188f8764793ee29fd1bdd>`_
863883
to download the MNIST dataset.
864884
865885
Next, we create a data loader and pass it this dataset. To make a new data

0 commit comments

Comments
 (0)