KeyError: 'GRU'

Using torch (1.1.0), flair (0.4.2) [1], I get the following error when I try to train a model.

  File "/home/foobar/github/cbd/venv/lib/python3.6/site-packages/torch/nn/modules/rnn.py", line 204, in forward
    _impl = _rnn_impls[self.mode]
KeyError: 'GRU'

Python interpeter

>>> import torch
>>> torch.version.cuda
'10.0.130'
>>> torch.cuda.is_available()
True

My understanding is a bit shaky. Should the version of nvcc compilation tools align with torch's cuda version? It doesn’t, but as you can see above, cuda is still available.

If there’s anything I’ve missed that might help diagnosing, please say.

Shell

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

[1] Flair NLP – https://github.com/zalandoresearch/flair

Full error

2019-08-12 17:49:33,828 Reading data from /home/foobar/tmp/splits
2019-08-12 17:49:33,828 Train: /home/foobar/tmp/splits/train.txt
2019-08-12 17:49:33,828 Dev: /home/foobar/tmp/splits/dev.txt
2019-08-12 17:49:33,828 Test: /home/foobar/tmp/splits/test.txt
2019-08-12 17:59:10,064 {'noncb', 'cb'}
2019-08-12 18:08:17,296 ----------------------------------------------------------------------------------------------------
2019-08-12 18:08:17,296 Evaluation method: MICRO_F1_SCORE
Traceback (most recent call last):
  File "/home/foobar/github/cbd/venv/bin/cbd-train", line 11, in <module>
    load_entry_point('cbd', 'console_scripts', 'cbd-train')()
  File "/home/foobar/github/cbd/cb/train.py", line 50, in train
    max_epochs=150)
  File "/home/foobar/github/cbd/venv/lib/python3.6/site-packages/flair/trainers/trainer.py", line 93, in train
    embeddings_in_memory,
  File "/home/foobar/github/cbd/venv/lib/python3.6/site-packages/flair/models/text_classification_model.py", line 177, in evaluate
    labels, loss = self.forward_labels_and_loss(batch)
  File "/home/foobar/github/cbd/venv/lib/python3.6/site-packages/flair/models/text_classification_model.py", line 108, in forward_labels_and_loss
    scores = self.forward(sentences)
  File "/home/foobar/github/cbd/venv/lib/python3.6/site-packages/flair/models/text_classification_model.py", line 70, in forward
    self.document_embeddings.embed(sentences)
  File "/home/foobar/github/cbd/venv/lib/python3.6/site-packages/flair/embeddings.py", line 2081, in embed
    rnn_out, hidden = self.rnn(packed)
  File "/home/foobar/github/cbd/venv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/foobar/github/cbd/venv/lib/python3.6/site-packages/torch/nn/modules/rnn.py", line 204, in forward
    _impl = _rnn_impls[self.mode]
KeyError: 'GRU'

You cuda version should match with what pytorch expects. Perhaps, you can try uninstalling pytorch and installing it again with correct cuda version. It seems that you have different cuda installations.

Getting same error with flair 0.4.3 and torch 1.2.0

System Cuda version

(py36) ➜  question_classifier_new_test nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130

Pytorch Cuda version

Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 19:07:31) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch 
>>> torch.version.cuda
'10.0.130'

I was working the other time, and now its not. anything missing.

version 1.1.0 works fine but in 1.2.0, GRU and LSTM are removed to add torchscript support, refer link https://pytorch.org/docs/stable/_modules/torch/nn/modules/rnn.html