【问题标题】:MirroredStrategy doesn't use GPUsMirroredStrategy 不使用 GPU
【发布时间】:2019-02-19 12:41:36
【问题描述】:

我想在我的多 GPU 系统上使用 tf.contrib.distribute.MirroredStrategy(),但它不使用 GPU 进行训练(请参阅下面的输出)。我也在运行 tensorflow-gpu 1.12。

我确实尝试直接在 MirroredStrategy 中指定 GPU,但出现了同样的问题。

model = models.Model(inputs=input, outputs=y_output)
optimizer = tf.train.AdamOptimizer(LEARNING_RATE)
model.compile(loss=lossFunc, optimizer=optimizer)

NUM_GPUS = 2
strategy = tf.contrib.distribute.MirroredStrategy(num_gpus=NUM_GPUS)
config = tf.estimator.RunConfig(train_distribute=strategy)
estimator = tf.keras.estimator.model_to_estimator(model,
                                              config=config)

这些是我得到的结果:

INFO:tensorflow:Device is available but not used by distribute strategy: /device:CPU:0
INFO:tensorflow:Device is available but not used by distribute strategy: /device:GPU:0
INFO:tensorflow:Device is available but not used by distribute strategy: /device:GPU:1
WARNING:tensorflow:Not all devices in DistributionStrategy are visible to TensorFlow session.

预期的结果显然是在多 GPU 系统上运行训练。这些是已知问题吗?

【问题讨论】:

标签: tensorflow tensorflow-estimator


【解决方案1】:

我一直面临 MirroredStrategy 在 tensorflow 1.13.1 上失败的类似问题,其中 2x RTX2080 运行 Estimator。

故障似乎在 NCCL all_reduce 方法中(错误消息 - 没有为 NCCL AllReduce 注册 OpKernel)。

我通过从 NCCL 更改为 hierarchy_copy 来运行它,这意味着使用 contrib cross_device_ops 方法如下:

命令失败:

mirrored_strategy = tf.distribute.MirroredStrategy(devices=["/gpu:0","/gpu:1"])

成功的命令:

mirrored_strategy = tf.distribute.MirroredStrategy(devices=["/gpu:0","/gpu:1"],
                      cross_device_ops=tf.contrib.distribute.AllReduceCrossDeviceOps(
                         all_reduce_alg="hierarchical_copy")
                                                   )

【讨论】:

  • 太酷了!如果我有机会回来找你,我会去看看:)
  • @craft 那么结果如何?
【解决方案2】:

在 TensorFlow 新版本中,AllReduceCrossDeviceOps 不存在。您可以改用distribute.HierarchicalCopyAllReduce()

mirrored_strategy = tf.distribute.MirroredStrategy(devices= ["/gpu:0","/gpu:1"],cross_device_ops=tf.distribute.HierarchicalCopyAllReduce())

【讨论】:

    猜你喜欢
    • 2020-11-13
    • 1970-01-01
    • 2020-08-15
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多