question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Integrated gradient for LSTM shows 'cudnn RNN backward can only be called in training mode'

See original GitHub issue

Hi all,

I have a trained LSTM model and the output is a time series. I tried to apply integrated gradient but got the error showing ‘cudnn RNN backward can only be called in training mode’. Any ideas how to solve it? Here is the code.

def forward_fun(x_d, x_s, x_one_hot):
    out = lstm(x_d, x_s, x_one_hot)[0][:,-1]  #0 is for the cell output and -1 is for the last index in the ouput series
    return out
ig = IntegratedGradients(forward_fun) 

attrs = []
for i in range(x_d.shape[0]):
    attr = ig.attribute(inputs=(x_d[i:i+1]), additional_forward_args=(x_s[i:i+1], x_one_hot)).cpu().data.numpy()
    attrs.append(attr)
attrs = np.concatenate(attrs, axis=0)

Then I tried to move all the model and data to CPU and it is working now (slowly). How can I make it on the GPU??

Thanks all!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
NarineKcommented, Dec 18, 2020

@ShihengDuan , I saw similar problem too and setting the following flag helped to fix the problem:

torch.backends.cudnn.enabled=False
1reaction
NarineKcommented, Dec 19, 2020

@ShihengDuan, CuDNN with RNN doesn’t support gradient computation in eval mode that’s why we need to disable cudnn for RNN in eval mode. I do not know the exact reasons. That would be a good question for pytorch discussion forum.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cudnn RNN backward can only be called in training mode ...
Your model needs to be in train mode throughout the the whole training. And you never set your model back to train after...
Read more >
Cudnn RNN backward can only be called in training mode
I write a code but it has a error, I can not fix it my environment is : cuda9 + cudnn 7.1 python=3.6.6...
Read more >
Sequence Classification with LSTM Recurrent Neural ...
In this post, you will discover how you can develop LSTM recurrent neural network models for sequence classification problems in Python using ...
Read more >
TensorFlow RNN models - Jonathan Hui - Medium
The following diagram shows a bidirectional RNN which contains a forward LSTM and a backward LSTM. For each timestep, we merge the result...
Read more >
Use of cudnn rnn forwardtraining and backwardtraining
I want to train a recurrent neural network with outputs that don't occur at every time step. It is a many-to-one RNN. I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found