Tensorflow Inception 多 GPU 训练损失未求和?

2024-04-28

我正在尝试检查多个 GPU(在一台机器上)的 Tensorflow 初始代码。我很困惑,因为据我所知,我们从不同的塔(又名 GPU)中得到了多次损失,但是loss评估的变量似乎只是最后一个塔的变量,而不是所有塔的损失之和:

for step in xrange(FLAGS.max_steps):
  start_time = time.time()
  _, loss_value = sess.run([train_op, loss])
  duration = time.time() - start_time

Where loss最后专门为每个塔定义:

for i in xrange(FLAGS.num_gpus):
  with tf.device('/gpu:%d' % i):
    with tf.name_scope('%s_%d' % (inception.TOWER_NAME, i)) as scope:
      # Force all Variables to reside on the CPU.
      with slim.arg_scope([slim.variables.variable], device='/cpu:0'):
        # Calculate the loss for one tower of the ImageNet model. This
        # function constructs the entire ImageNet model but shares the
        # variables across all towers.
        loss = _tower_loss(images_splits[i], labels_splits[i], num_classes,
                           scope)

有人可以解释一下合并不同塔的损失的步骤在哪里吗?或者我们只是用一个塔的损失来代表另一个塔的损失?

这是代码的链接:https://github.com/tensorflow/models/blob/master/inception/inception/inception_train.py#L336 https://github.com/tensorflow/models/blob/master/inception/inception/inception_train.py#L336


出于监控目的,考虑到所有塔均按预期工作,单个塔的损耗与所有塔损耗的平均值一样具有代表性。这是因为批次和分配到的塔之间没有关系。

But the train_op使用所有塔的梯度,按照line 263 https://github.com/tensorflow/models/blob/master/inception/inception/inception_train.py#L263, 278 https://github.com/tensorflow/models/blob/master/inception/inception/inception_train.py#L278因此,从技术上讲,培训应考虑所有塔的批次。

请注意,平均损失的方差将低于单塔损失的方差,但它们将具有相同的期望。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Tensorflow Inception 多 GPU 训练损失未求和? 的相关文章

随机推荐