2017-06-12 126 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