Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取以多节点方法分布的Tensorflow中使用的GPU数量_Python_Tensorflow_Nvidia_Distributed - Fatal编程技术网

Python 获取以多节点方法分布的Tensorflow中使用的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分布式API

使用Horovod时,我能够访问当前使用的GPU总数,如下所示:

导入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是否正在运行
    tf.distribute.has_strategy()=>True/False
    (与上面的注释相同,否则您只能得到False)

    • 回答我问题的一些发现:

      • 等价于
        hvd.size()
        ==>
        tf.distribute.get_strategy().num_replications_in_sync

      • 等价于
        hvd.rank()

      • TF是否正在运行
        tf.distribute.has_strategy()=>True/False
        (与上面的注释相同,否则您只能得到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