Skip to content

Instantly share code, notes, and snippets.

@himaprasoon
Created March 22, 2019 10:52
Show Gist options
  • Save himaprasoon/7feca7c9e3e01554c0b104262c577170 to your computer and use it in GitHub Desktop.
Save himaprasoon/7feca7c9e3e01554c0b104262c577170 to your computer and use it in GitHub Desktop.
Test if Horovod is running in multiple machines
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