【问题标题】:TensorFlow-Slim Multi-GPU trainingTensorFlow-Slim 多 GPU 训练
【发布时间】:2017-09-10 08:22:14
【问题描述】:

我正在使用 TensorFlow-Slim。我的目标是在多 GPU 模式下运行给定的标准脚本(位于 /models/slim/scripts)。我已经测试了finetune_resnet_v1_50_on_flowers.sh 脚本(克隆于 2017 年 4 月 12 日)。我刚刚在训练部分的末尾添加了 --num_clones=2 (灵感来自 /slim/deployment/model_deploy_test.py 和以前的 StackOverflow 答案):

python train_image_classifier.py \
  --train_dir=${TRAIN_DIR} \
  --dataset_name=flowers \
  --dataset_split_name=train \
  --dataset_dir=${DATASET_DIR} \
  --model_name=resnet_v1_50 \
  --checkpoint_path=${PRETRAINED_CHECKPOINT_DIR}/resnet_v1_50.ckpt \
  --checkpoint_exclude_scopes=resnet_v1_50/logits \
  --trainable_scopes=resnet_v1_50/logits \
  --max_number_of_steps=3000 \
  --batch_size=32 \
  --learning_rate=0.01 \
  --save_interval_secs=60 \
  --save_summaries_secs=60 \
  --log_every_n_steps=100 \
  --optimizer=rmsprop \
  --weight_decay=0.00004 \
  --num_clones=2

deployment/model_deploy_test.py 中的代码:

def testMultiGPU(self):
    deploy_config = model_deploy.DeploymentConfig(num_clones=2)

我收到一条警告(“忽略设备规范”):

I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Tesla P100-SXM2-16GB, pci bus id: 0000:85:00.0)
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:1) -> (device: 1, name: Tesla P100-SXM2-16GB, pci bus id: 0000:86:00.0)
I tensorflow/core/common_runtime/simple_placer.cc:669] Ignoring device specification /GPU:1 for node 'clone_1/fifo_queue_Dequeue' because the input edge from 'prefetch_queue/fifo_queue' is a reference connection and already has a device field set to /CPU:0
I tensorflow/core/common_runtime/simple_placer.cc:669] Ignoring device specification /GPU:0 for node 'clone_0/fifo_queue_Dequeue' because the input edge from 'prefetch_queue/fifo_queue' is a reference connection and already has a device field set to /CPU:0

GPU 运行正常(内存使用率和 GPU 利用率),但训练速度并不比单 GPU 训练快。

此问题可能与:https://github.com/tensorflow/tensorflow/issues/8061

我很高兴收到您对此问题的回答、意见或具体建议。

CUDA 版本:发布 8.0、V8.0.53

TensorFlow 从二进制安装,经过测试的版本:1.0.1 和 1.1.0rc

GPU:NVIDIA Tesla P100 (SXM2)

【问题讨论】:

    标签: tensorflow gpu multi-gpu tf-slim


    【解决方案1】:

    即使这个答案可能会迟到,训练也不应该更快(以每步的秒数为单位)。而是创建了另一个模型,使用您的参数导致有效批量大小为 64,因此您可以将最大步数减半。

    【讨论】:

    • 正在使用两个批次大小为 32 的 gpu 与单个批次大小为 64 的 gpu 相同吗?
    • 否,因为您需要调整学习率和学习率衰减。您还需要调整每次衰减的时期数。
    • 我的意思是如果我们只考虑批量大小。我还发现,使用多 GPU 时,它变得越来越慢。在那之前,我以为bath size会除以gpus的数量,而且越来越快了。据我了解您的评论,它乘以批量大小。我说的对吗?
    【解决方案2】:

    请关注本文档 https://github.com/tensorflow/tensorflow/issues/12689 为了确保变量存储在 CPU 中,我们需要使用上下文管理器 slim.arg_scope([slim.model_variable, slim.variable], device='/cpu:0'):

    它解决了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-30
      • 1970-01-01
      • 2017-06-10
      • 2017-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多