CuDNNLSTM: UnknownError: 找不到 dnn 实现

Fay*_*ang 15 lstm cudnn

我已经成功运行了以 LSTM 作为第一层的模型。但出于好奇,我用 CuDNNLSTM 替换了 LSTM。但是在model.fit之后,它回复了以下错误信息:

UnknownError: Fail to find the dnn implementation.
    [[{{node cu_dnnlstm_5/CudnnRNN}} = CudnnRNN[T=DT_FLOAT, _class=["loc:@training_2/Adam/gradients/cu_dnnlstm_5/CudnnRNN_grad/CudnnRNNBackprop"], direction="unidirectional", dropout=0, input_mode="linear_input", is_training=true, rnn_mode="lstm", seed=87654321, seed2=0, _device="/job:localhost/replica:0/task:0/device:GPU:0"](cu_dnnlstm_5/transpose, cu_dnnlstm_5/ExpandDims_1, cu_dnnlstm_5/ExpandDims_1, cu_dnnlstm_5/concat_1)]]
    [[{{node metrics_3/mean_squared_error/Mean_1/_1877}} = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_4852_metrics_3/mean_squared_error/Mean_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
Run Code Online (Sandbox Code Playgroud)

我在这个讨论中尝试了 TestCudnnLSTM()并成功通过了测试:

Keras 版本:2.2.4
Tensorflow 版本:1.12.0
创建模型
_______________________________________________________
层(类型)输出形状参数#   
================================================== ================
cu_dnnlstm_1 (CuDNNLSTM) (无, 1000, 1) 16        
================================================== ================
总参数:16
可训练参数:16
不可训练的参数:0
_______________________________________________________
没有任何
模型编译

看来问题是在模型拟合的时候出现的。但我不知道到底是什么问题?

Sad*_*lam 34

对于 TensorFlow v2,一种解决方案是 -

import tensorflow as tf
physical_devices = tf.config.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0], enable=True)
Run Code Online (Sandbox Code Playgroud)

然后你也可以使用 keras 模型 -

from tensorflow.keras.models import Model
Run Code Online (Sandbox Code Playgroud)

文档

这个解决方案对我有用,它只支持一个 GPU 的内存增长。

  • 谢谢,但对我来说它是 `physical_devices = tf.config.experimental.list_physical_devices('GPU')` (2认同)

小智 6

如果您在安装 Keras NN 时遇到此错误,请将此代码放在您的导入中

from keras.backend.tensorflow_backend import set_session
import tensorflow as tf
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
sess = tf.Session(config=config)
set_session(sess)
Run Code Online (Sandbox Code Playgroud)

信用

  • ModuleNotFoundError:没有名为“keras.backend.tensorflow_backend”的模块;“keras.backend”不是一个包。我想这个答案对于旧版本的 keras/tf 有效 (4认同)

Nis*_*an 1

确保您拥有适合您所使用的 CUDA 版本的 Nvidia 驱动程序版本。你可以在这里查看。https://docs.nvidia.com/deploy/cuda-compatibility/index.html#binary-compatibility

我使用的是 CUDA 9.0,但使用的 Nvidia 驱动程序小于 384.81。将 Nvidia 驱动程序更新到较新的驱动程序解决了我的问题。