2017-06-12 125 views
0

我在tensorflow上使用多GPU。而且我对在相同范围内共享变量感到困惑。tensorflow多GPU共享变量

根据https://github.com/tensorflow/models/blob/master/tutorials/image/cifar10/cifar10_multi_gpu_train.py

最简单的方法是:

for i in xrange(FLAGS.num_gpus): 
    with tf.device('/gpu:%d' % i): 
     tf.get_variable_scope().reuse_variables() 
     // and do sth. 

但在我的理解,至少在第一GPU具有创建变量,因为它有它重用不变量。我还发现了一些代码,它为第一个GPU设置了reuse = False。

那么这样做的正确方法是什么?

回答

0

是的,你是对的。对于第一个设备,reuse标志应设置为False。在本教程中,tf.get_variable_scope().reuse_variables()construction of the network之后调用。你也可以这样做。

或者另一种可能的解决方案:

for i in xrange(FLAGS.num_gpus): 
     with tf.device('/gpu:%d' % i): 
      with tf.variable_scope(name, reuse= i>0): 
       // and do sth