【问题标题】:System hangs when computing gradients on GPU with TensorFlow使用 TensorFlow 在 GPU 上计算梯度时系统挂起
【发布时间】:2017-09-11 00:46:16
【问题描述】:

问题描述

当我在 GPU 上计算梯度时,我的系统挂起。我能够毫无问题地在我的 CPU 上计算梯度。我可以在我的 GPU 上毫无问题地计算我的图表中的所有节点,包括我的损失函数。无论我使用哪种优化器,当我在 GPU 上计算梯度时,我的系统都会挂起。产生此问题的代码是:

sess = tf.Session()

# ...

cnn = CNNClass()

#...

step_size = tf.placeholder(tf.float32, name="step_size") 
global_step = tf.Variable(0, name="global_step", trainable=False) 
optimizer = tf.train.MomentumOptimizer(step_size, 0.9)

#...

# CRASHES WHEN I RUN THIS
grads_and_vars = optimizer.compute_gradients(cnn.loss)
sess.run([grads_and_vars], feed_dict)

# DOES NOT CRASH WHEN I RUN THIS
sess.run([cnn.loss])

更多详情

我尝试在我的 ConfigProto 中设置 gpu_options=tf.GPUOptions(per_process_gpu_memory_fraction=0.333) 但这没有帮助。

在运行代码之前启动 watch -n 0.1 nvidia-smi 显示 Volatile GPU-Util 在挂起之前达到 100%。

在我的 CPU 上计算梯度并将它们打印出来显示正常输出(我没有得到任何 NaN 或 0 或类似的东西)。

系统信息

  • 系统:Ubuntu 16.04
  • TensorFlow 安装自:二进制
  • TensorFlow 版本:v1.0.0-65-g4763edf-dirty 1.0.1
  • CUDA 版本:8.0、V8.0.61
  • cuDNN 版本:5.1
  • GPU 型号和内存:NVidia GeForce GTX TITAN X (12GB)
  • 显卡驱动:375.39

编辑 1:更新

代码在缩小模型后在 GPU 上运行。

在 GPU 上启动计算似乎有很大的开销。当我训练一个中等大小的模型时,我可以看到这一点:Volatile GPU-Util 在没有完成任何评估的情况下达到 100% 一段时间,然后 Volatile GPU-Util 下降到 %30 左右,并且评估循环开始运行得相当快。这不是问题,除非我的系统几乎完全无法使用,直到 Volatile GPU-Util 回落到 30%。

我假设开销与将数据放在 GPU 上有关。有人可以解释为什么会这样吗?有没有办法防止 TensorFlow 在新贵阶段占用所有的 Volatile GPU?

【问题讨论】:

    标签: tensorflow nvidia ubuntu-16.04


    【解决方案1】:

    TensorFlow 在完全控制 GPU 时效果最佳。为避免系统在完全使用时挂起,最简单的方法是在使用 GPU 进行训练时不要将其用于图形。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 2019-11-16
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多