4. PyTorch application¶
This section describes how to run a simple MNIST training application. You can find the source code and a description of the application in the tutorials repository.
This quick start describes how to run the application from the command line. This application can also be run as a Jupyter notebook. Refer to the Graphcloud Jupyter Notebook Quick Start for how to set up Graphcloud to run Jupyter notebooks and then follow the instructions given in the tutorial README.
Install required packages
You can now install the packages that the application requires.
Run application
You run the application with the command:
$ python3 mnist_poptorch.py
There are some command line options for the application. You can change the following:
--batch-size
,--device-iterations
,--test-batch-size
,--epochs
and-lr
(learning rate).
If the application has run successfully, you should see output similar to that in Listing 4.1.
$ python3 mnist_poptorch.py Epoch 1/10 0%| | 0/150 [00:00<00:00] Graph compilation: 100%| | 100/100 [00:36<00:00] Loss:1.4709 | Accuracy:100.00%: 100%| | 150/150 [00:52<00:00, 2.88it/s] Epoch 2/10 Loss:1.4612 | Accuracy:100.00%: 100%| | 150/150 [00:12<00:00, 12.42it/s] Epoch 3/10 Loss:1.5861 | Accuracy:87.50%: 100%| | 150/150 [00:11<00:00, 13.08it/s] Epoch 4/10 Loss:1.4973 | Accuracy:100.00%: 100%| | 150/150 [00:11<00:00, 12.94it/s] Epoch 5/10 Loss:1.4612 | Accuracy:100.00%: 100%| | 150/150 [00:11<00:00, 12.74it/s] Epoch 6/10 Loss:1.4745 | Accuracy:100.00%: 100%| | 150/150 [00:11<00:00, 12.73it/s] Epoch 7/10 Loss:1.5811 | Accuracy:87.50%: 100%|| 150/150 [00:11<00:00, 13.04it/s] Epoch 8/10 Loss:1.5861 | Accuracy:87.50%: 100%|| 150/150 [00:12<00:00, 12.40it/s] Epoch 9/10 Loss:1.4612 | Accuracy:100.00%: 100%|| 150/150 [00:11<00:00, 12.81it/s] Epoch 10/10 Loss:1.4612 | Accuracy:100.00%: 100%|| 150/150 [00:11<00:00, 12.91it/s] Graph compilation: 100%| | 100/100 [00:22<00:00] 100%| | 125/125 [00:30<00:00, 4.03it/s] Accuracy on test set: 98.58%
You have run an application that demonstrates how to use the IPU to train a neural network for classification on the MNIST dataset using PyTorch.