Python 获取以多节点方法分布的Tensorflow中使用的GPU数量
我目前正在尝试比较Horovod和Tensorflow分布式API 使用Horovod时,我能够访问当前使用的GPU总数,如下所示:Python 获取以多节点方法分布的Tensorflow中使用的GPU数量,python,tensorflow,nvidia,distributed,Python,Tensorflow,Nvidia,Distributed,我目前正在尝试比较Horovod和Tensorflow分布式API 使用Horovod时,我能够访问当前使用的GPU总数,如下所示: 导入horovod.tensorflow作为hvd size=hvd.size() 使用PyTorch分布式API时,也有类似的概念: size=int(os.environ[“世界大小”]) 我希望执行相同的操作,并获取当前使用TF分布式官方API的多GPU/节点使用的GPU数量 我不能使用CUDA\u VISIBLE\u DEVICES环境变量,因为它只
导入horovod.tensorflow作为hvd
size=hvd.size()
使用PyTorch分布式API时,也有类似的概念:
size=int(os.environ[“世界大小”])
我希望执行相同的操作,并获取当前使用TF分布式官方API的多GPU/节点使用的GPU数量
我不能使用
CUDA\u VISIBLE\u DEVICES
环境变量,因为它只能在单个节点上工作。一些发现回答了我的问题:
- 等价于
hvd.size() ==>
tf.distribute.get_strategy().num_replications_in_sync
- 等价于
hvd.rank()
- TF是否正在运行
(与上面的注释相同,否则您只能得到False)tf.distribute.has_strategy()=>True/False
- 等价于
hvd.size() ==>
tf.distribute.get_strategy().num_replications_in_sync
- 等价于
hvd.rank()
- TF是否正在运行
(与上面的注释相同,否则您只能得到False)tf.distribute.has_strategy()=>True/False
- 回答我问题的一些发现:
def get_rank():
replica_id = tf.distribute.get_replica_context().replica_id_in_sync_group
if isinstance(replica_id, tf.Tensor):
return tf.get_static_value(replica_id) != 0)
else:
return 0