Created
March 22, 2019 10:52
-
-
Save himaprasoon/7feca7c9e3e01554c0b104262c577170 to your computer and use it in GitHub Desktop.
Test if Horovod is running in multiple machines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import horovod.tensorflow as hvd | |
import tensorflow as tf | |
hvd.init() | |
hvd_r=int(hvd.rank()) | |
#each process compute a small part of something and then compute the average etc | |
#compute a small part | |
x= tf.random_uniform(shape=()) | |
#compute the average for all processes | |
y=hvd.allreduce(x) | |
tf.set_random_seed(hvd.rank()) | |
with tf.Session() as sess: | |
y=sess.run(y) | |
print(hvd.rank(), hvd.local_rank(),sess.run(x)) | |
#only one process print out the result | |
# if(hvd_r==0): | |
print(f"mean of the big array is {y}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment