【问题标题】:How to share a queue containing variable length sequences batches between multiple gpus?如何在多个 GPU 之间共享包含可变长度序列批次的队列?
【发布时间】:2017-06-09 08:54:18
【问题描述】:

根据Tensorflow: Multi-GPU single input queue,最好让多个 GPU 共享一个队列。 该链接建议我们可以增加批量大小,然后自己拆分批次。但是,当输入数据是可变长度序列时,增加批量大小可能会导致许多零填充值。

例如,如果我们创建一个 4-sequence 批次并拆分批次,它可能是

/gpu:0

  • x, x, x, 0, 0, 0, 0, 0, 0
  • x, x, x, x, x, x, x, x, x

/gpu:1

  • x, x, 0, 0, 0, 0, 0, 0, 0
  • x, x, x, x, x, 0, 0, 0, 0

我的问题是:如何生产批次:

/gpu:0

  • x, x, x, 0, 0, 0, 0, 0, 0
  • x, x, x, x, x, x, x, x, x

/gpu:1

  • x, x, 0, 0, 0
  • x, x, x, x, x

slim 之后,我尝试使用tf.train.batch(data, batch_size=2, dynamic_pad=True) 创建批次,将批次放入tf.PaddingFIFOQueue,然后在不同的GPU 上调用tf.PaddingFIFOQueue.dequeue()。但是,似乎所有 GPU 在最新的 tensorflow(master)上都获得了相同的数据。

以下代码演示了该问题:

import tensorflow as tf

capacity = 10
queue = tf.FIFOQueue(capacity, tf.int64)
enqueue = queue.enqueue_many((list(range(capacity)),))

def clone_fn():
    clone_data = queue.dequeue()
    return clone_data

num_gpus = 2
all_clones_data = []
for gpu_index in range(num_gpus):
    with tf.device('/gpu:{}'.format(gpu_index)):
        all_clones_data.append(clone_fn())

with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
    sess.run(enqueue)
    print(sess.run(all_clones_data))

在最新的tensorflow上,输出为 [0, 0]

在较旧的 tensorflow (0.11) 上,输出为 [1, 0] ,这就是我想要的。

似乎slim 也使用最新的 tensorflow 在所有 GPU 上获取相同的数据。

有没有更好的方法在多个 GPU 之间共享包含可变长度序列的队列?

【问题讨论】:

    标签: tensorflow tf-slim


    【解决方案1】:

    尝试运行

    config = tf.ConfigProto(graph_options=tf.GraphOptions(optimizer_options=tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0)))
    

    这有点违反直觉:提交7038

    【讨论】:

      猜你喜欢
      • 2012-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-12
      • 1970-01-01
      • 2017-07-25
      • 2012-12-26
      • 2018-06-25
      相关资源
      最近更新 更多