如何检查 keras/tensorflow 是否正在使用 cuDNN?
How can I check if keras/tensorflow is using cuDNN?
我已经安装了CUDA和cuDNN,但是最后一个没有用,在theano中给出了很多错误信息。现在我正在 Keras/Tensorflow 中训练中等大小的深度转换网络,但没有收到任何 cuDNN 错误消息。如何检查现在是否正在使用 cuDNN?
tl;dr: 如果 tensorflow-gpu 有效,则使用 CuDNN。
TensorFlow 的预构建二进制文件(至少从 1.3 版开始)link 到 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 代码中仍然有很多回退——据我所知,它在以前的版本中是可选的。
需要安装 TensorFlow 的特殊 GPU 版本才能使用 GPU(和 CuDNN)。确保安装的 python 包是 tensorflow-gpu
而不仅仅是 tensorflow
.
您可以列出包含 "tensorflow" 和 conda list 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()
要检查您是否 "see" 来自 python 环境的 CuDNN 并由此验证正确的 PATH 变量,您可以试试这个:
import ctypes
ctypes.WinDLL("cudnn64_7.dll") # use the file name of your cudnn version here.
您可能还想查看 GPU 优化的 Keras 图层。
- CuDNNLSTM
- CuDNNGRU
它们明显更快:
https://keras.io/layers/recurrent/#cudnnlstm
我们看到从 LSTM 到 CuDNNLSTM Keras 层有 10 倍的改进。
注意:
我们还看到机器上的 VMS(虚拟内存)使用量增加了 10 倍。所以需要权衡取舍。
我已经安装了CUDA和cuDNN,但是最后一个没有用,在theano中给出了很多错误信息。现在我正在 Keras/Tensorflow 中训练中等大小的深度转换网络,但没有收到任何 cuDNN 错误消息。如何检查现在是否正在使用 cuDNN?
tl;dr: 如果 tensorflow-gpu 有效,则使用 CuDNN。
TensorFlow 的预构建二进制文件(至少从 1.3 版开始)link 到 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 代码中仍然有很多回退——据我所知,它在以前的版本中是可选的。
需要安装 TensorFlow 的特殊 GPU 版本才能使用 GPU(和 CuDNN)。确保安装的 python 包是 tensorflow-gpu
而不仅仅是 tensorflow
.
您可以列出包含 "tensorflow" 和 conda list 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()
要检查您是否 "see" 来自 python 环境的 CuDNN 并由此验证正确的 PATH 变量,您可以试试这个:
import ctypes
ctypes.WinDLL("cudnn64_7.dll") # use the file name of your cudnn version here.
您可能还想查看 GPU 优化的 Keras 图层。
- CuDNNLSTM
- CuDNNGRU
它们明显更快: https://keras.io/layers/recurrent/#cudnnlstm
我们看到从 LSTM 到 CuDNNLSTM Keras 层有 10 倍的改进。
注意: 我们还看到机器上的 VMS(虚拟内存)使用量增加了 10 倍。所以需要权衡取舍。