diff --git a/course_material/examples/mnist_epoch_distributed.py b/course_material/examples/mnist_epoch_distributed.py index 7c9080e63af23eabeb6a6b47c8e89edf26e7190f..504b2a8b99f2bcc1206159a9314806890dd2c682 100644 --- a/course_material/examples/mnist_epoch_distributed.py +++ b/course_material/examples/mnist_epoch_distributed.py @@ -4,8 +4,6 @@ # 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 classification using the MNIST dataset. @@ -13,14 +11,14 @@ example epochs are distributed across the Horovod ranks, not data. 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 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. Note: This code will NOT work on the supercomputers. @@ -30,16 +28,17 @@ import math import tensorflow as tf import horovod.tensorflow.keras as hvd -from tensorflow.python.keras import backend as K # Horovod: initialize Horovod. hvd.init() # Horovod: pin GPU to be used to process local rank (one GPU per process) -config = tf.ConfigProto() -config.gpu_options.visible_device_list = str(hvd.local_rank()) -K.set_session(tf.Session(config=config)) +gpus = tf.config.experimental.list_physical_devices('GPU') +if gpus: + 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 mnist = tf.keras.datasets.mnist diff --git a/course_material/examples/mnist_single_gpu.py b/course_material/examples/mnist_single_gpu.py index 794150fe230348b0001d86158d32a9a9e5e52cbd..2918cd027cb8b5c88d49ba0c83eaa4944f8aa8f4 100644 --- a/course_material/examples/mnist_single_gpu.py +++ b/course_material/examples/mnist_single_gpu.py @@ -4,17 +4,16 @@ # Version 2.0 (see the NOTICE file for details). """ - This program is an adaptation of the code sample available at - https://www.tensorflow.org/tutorials/. The program creates - and trains a shallow ANN for handwritten digit classification - using the MNIST dataset. + This program is an adaptation of a previously available code sample + at https://www.tensorflow.org/tutorials/. The program creates and trains a + shallow ANN for handwritten digit classification using the MNIST dataset. 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.