1

我在张量流上使用多 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 设置了重用 = False。

那么正确的方法是什么?

4

1 回答 1

1

是的你是对的。对于第一个设备,reuse标志应设置为False。在教程中,在网络构建tf.get_variable_scope().reuse_variables()后调用。你也可以这样做。

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

    for i in xrange(FLAGS.num_gpus):
        with tf.device('/gpu:%d' % i):
            with tf.variable_scope(name, reuse= i>0):
                 // and do sth
于 2017-06-15T16:02:18.893 回答