如何检查keras / tensorflow是否正在使用cuDNN?

问题描述 投票:2回答:2

我已经安装了CUDA和cuDNN,但是最后一个没有用,在theano中提供了很多错误消息。现在我在Keras / Tensorflow中训练中等大小的深度网络,没有收到任何cuDNN错误消息。如何检查cuDNN现在是否正在使用?

tensorflow keras cudnn
2个回答
7
投票

tl; dr:如果tensorflow-gpu有效,则使用CuDNN。

TensorFlow的预构建二进制文件(至少从版本1.3开始)链接到CuDNN库。如果缺少CuDNN,则会显示一条错误消息,告知您ImportError: Could not find 'cudnn64_7.dll'. TensorFlow requires that this DLL be installed...

根据TensorFlow install documentation for version 1.5,即使您从源代码构建它,也必须安装CuDNN以支持GPU。对于CuDNN无法使用的情况,TensorFlow代码中仍有很多回退 - 据我所知,它在以前的版本中曾经是可选的。

Here are two lines from the TensorFlow source that explicitly tell and force that CuDNN is required for gpu acceleration

有一个特殊的GPU版本的TensorFlow需要安装才能使用GPU(和CuDNN)。确保安装的python包是tensorflow-gpu而不仅仅是tensorflow

您可以使用conda list tensorflow列出包含“tensorflow”的软件包(如果您不使用anaconda,则只列出pip list),但请确保已激活正确的环境。

当您使用GPU支持运行脚本时,它们将如下所示:

Using TensorFlow backend.

2018- ... C:\tf_jenkins\...\gpu\gpu_device.cc:1105] Found device 0 with properties:
name: GeForce GTX 1080 major: 6 minor: 1 memoryClockRate(GHz): 1.7845

要测试它,只需键入控制台:

import tensorflow as tf
tf.Session()

要检查您是否从python环境“看到”CuDNN并随之验证了正确的PATH变量,您可以尝试这样做:

import ctypes
ctypes.WinDLL("cudnn64_7.dll") # use the file name of your cudnn version here.

1
投票

您可能还想查看GPU优化的Keras图层。

  • CuDNNLSTM
  • CuDNNGRU

它们明显更快:https://keras.io/layers/recurrent/#cudnnlstm

我们看到从LSTM到CuDNNLSTM Keras层的改进了10倍。

注意:我们还发现计算机上的VMS(虚拟内存)使用量增加了10倍。所以需要考虑权衡。

© www.soinside.com 2019 - 2024. All rights reserved.