1

Please I tried importing CuDnnLSTM from tensorflow.keras.layers to increase my training speed but got this error. I know similar question has been asked by a user with Keras 2.0.8 and python 3.5.

My configuration is tensorflow version 2.0.0-beta1 and Python 3.6.10.

This is what I tried: from tensorflow.keras.layers import CuDNNLSTM

And I got this error, ImportError: cannot import name 'CuDNNLSTM'

Please any one has idea on how to fix this error? Thanks in advance!

Complex1234
  • 11
  • 1
  • 2
  • 1
    Does this answer your question? [Keras - ImportError: cannot import name 'CuDNNLSTM'](https://stackoverflow.com/questions/47857437/keras-importerror-cannot-import-name-cudnnlstm) – Abdul Aziz Barkat Jan 18 '21 at 06:49
  • I tried the solution suggested at https://stackoverflow.com/questions/47857437/keras-importerror-cannot-import-name-cudnnlstm: THIS IS WHAT I DID, !pip install --upgrade keras on colab. still got: (ImportError: cannot import name 'CuDNNLSTM') – Complex1234 Jan 18 '21 at 09:52

1 Answers1

5

Instead of from tensorflow.keras.layers import CuDNNLSTM you can use from tensorflow.compat.v1.keras.layers import CuDNNLSTM.

Please refer working code as shown below

import tensorflow as tf
print(tf.__version__)
from tensorflow.keras.models import Sequential
from tensorflow.compat.v1.keras.layers import CuDNNLSTM

model = Sequential()
model.add(CuDNNLSTM(1, return_sequences=0, input_shape=(1, 1)))
print(model.summary())

Output:

2.0.0-beta1
Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
cu_dnnlstm (CuDNNLSTM)       (None, 1)                 16        
=================================================================
Total params: 16
Trainable params: 16
Non-trainable params: 0
_________________________________________________________________
None
  • @Complex1234, Can you please accept and upvote the answer if it answers your question. Thank You –  Feb 22 '21 at 04:14