Skip to content
Snippets Groups Projects
Commit efc3bd4a authored by Fahad Khalid's avatar Fahad Khalid
Browse files

Updated the course material so that the examples comply with TF2.

parent cc8ad9a9
No related branches found
No related tags found
1 merge request!4Updated to use Tensorflow2
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
# Version 2.0 (see the NOTICE file for details). # Version 2.0 (see the NOTICE file for details).
""" """
This program is an adaptation of the following code sample:
https://github.com/horovod/horovod/blob/master/examples/keras_mnist.py.
The program creates and trains a shallow ANN for handwritten digit The program creates and trains a shallow ANN for handwritten digit
classification using the MNIST dataset. classification using the MNIST dataset.
...@@ -13,14 +11,14 @@ ...@@ -13,14 +11,14 @@
example epochs are distributed across the Horovod ranks, not data. example epochs are distributed across the Horovod ranks, not data.
To run this sample use the following command on your To run this sample use the following command on your
workstation/laptop equipped with a GPU: workstation/laptop:
mpirun -np 1 python -u mnist_epoch_distributed.py mpirun -np 1 python -u mnist_epoch_distributed.py
If you have more than one GPU on your system, you can increase the If you have more than one GPU on your system, you can increase the
number of ranks accordingly. number of ranks accordingly.
The code has been tested with Python 3.7.5, tensorflow-gpu 1.13.1, and The code has been tested with Python 3.8.7, tensorflow 2.3.1, and
horovod 0.16.2. horovod 0.16.2.
Note: This code will NOT work on the supercomputers. Note: This code will NOT work on the supercomputers.
...@@ -30,16 +28,17 @@ ...@@ -30,16 +28,17 @@
import math import math
import tensorflow as tf import tensorflow as tf
import horovod.tensorflow.keras as hvd import horovod.tensorflow.keras as hvd
from tensorflow.python.keras import backend as K
# Horovod: initialize Horovod. # Horovod: initialize Horovod.
hvd.init() hvd.init()
# Horovod: pin GPU to be used to process local rank (one GPU per process) # Horovod: pin GPU to be used to process local rank (one GPU per process)
config = tf.ConfigProto() gpus = tf.config.experimental.list_physical_devices('GPU')
config.gpu_options.visible_device_list = str(hvd.local_rank()) if gpus:
K.set_session(tf.Session(config=config)) tf.config.experimental.set_visible_devices(gpus[hvd.local_rank()], 'GPU')
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
# Reference to the MNIST dataset # Reference to the MNIST dataset
mnist = tf.keras.datasets.mnist mnist = tf.keras.datasets.mnist
......
...@@ -4,17 +4,16 @@ ...@@ -4,17 +4,16 @@
# Version 2.0 (see the NOTICE file for details). # Version 2.0 (see the NOTICE file for details).
""" """
This program is an adaptation of the code sample available at This program is an adaptation of a previously available code sample
https://www.tensorflow.org/tutorials/. The program creates at https://www.tensorflow.org/tutorials/. The program creates and trains a
and trains a shallow ANN for handwritten digit classification shallow ANN for handwritten digit classification using the MNIST dataset.
using the MNIST dataset.
To run this sample use the following command on your To run this sample use the following command on your
workstation/laptop equipped with a GPU: workstation/laptop:
python -u mnist.py python -u mnist.py
The code has been tested with Python 3.7.5 and tensorflow-gpu 1.13.1. The code has been tested with Python 3.8.7 and tensorflow 2.3.1
Note: This code will NOT work on the supercomputers. Note: This code will NOT work on the supercomputers.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment