【问题标题】:Default Tensorflow device on multi-GPUs多 GPU 上的默认 TensorFlow 设备
【发布时间】:2017-03-21 22:21:24
【问题描述】:

如果我在多 GPU 平台上使用一个 GPU 运行 tensorflow 模型(例如 cifar10),则 tensorflow 会在所有可用的 GPU 上创建和广播(训练/推理)数据。由于我将 num_gpus 设置为 1,因此它仅在一个 GPU 上运行。但是,我也可以在其他 gpus 上看到相同的进程。是有意的吗?这有什么理由吗?我很快检查了其他 DL 框架,如 Caffe,但设计/操作有所不同。当然,我可以在代码级别指定device,但我很好奇。此外,如果机器是共享的,这种默认设计可能会让其他用户感到厌烦。

tensorflow/core/common_runtime/gpu/gpu_device.cc:977] Creating TensorFlow device (/gpu:0) -> (device: 0, name:

tensorflow/core/common_runtime/gpu/gpu_device.cc:977] Creating TensorFlow device (/gpu:1) -> (device: 1, name: 

tensorflow/core/common_runtime/gpu/gpu_device.cc:977] Creating TensorFlow device (/gpu:2) -> (device: 2, name: 

tensorflow/core/common_runtime/gpu/gpu_device.cc:977] Creating TensorFlow device (/gpu:3) -> (device: 3, name: ...



+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    0     67056    C   python                                       15623MiB |
|    1     67056    C   python                                       15499MiB |
|    2     67056    C   python                                       15499MiB |
|    3     67056    C   python                                       15499MiB |
|    4     67056    C   python                                       15499MiB |

【问题讨论】:

    标签: tensorflow multi-gpu


    【解决方案1】:

    默认情况下,TensorFlow 在启动时会在对其可见的所有设备上分配几乎所有的 GPU 内存。但是,除非您另外指定(在 with tf.device(): 块中,它只会将操作放在已知(对于 TensorFlow)为 "/gpu:0" 的设备上,而其他 GPU 将处于空闲状态。

    有几种解决方法:

    1. 在启动python 之前设置环境变量CUDA_VISIBLE_DEVICES=0(或12 等)以控制哪些设备对TensorFlow 可见。这也可以在创建您的第一个tf.Session 时使用tf.ConfigProto 选项visible_device_list 进行配置。

    2. 在创建您的第一个tf.Session 时设置tf.ConfigProto 选项allow_growth=True。这将阻止 TensorFlow 预分配所有 GPU 内存。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-28
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 2021-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多