1

I used an example of using BERT to classify reviews, described at the link. The code is written for using the CPU and it works fine, but slowly. In Colab Google, with a multilingual model, one epoch is considered 4 hours for me. If I replace the CPU with the CUDA everywhere in the code, then the error that YOU met with appears. I followed the guidelines given in the link, but then another error appears:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-0b35a5f74768> in <module>()
    268                   'labels': batch[2],
    269                   }
--> 270         inputs.to(device)
    271         outputs = model(**inputs)
    272 

AttributeError: 'dict' object has no attribute 'to'

1 Answers1

0

Firstly you do not need to replace the CPU with the CUDA everywhere in the code. You should just add the following to the cell from which you import the libraries

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

By printing the device object, you can see the gpu that google colab assigned to you to use.

Coming to your question, I think instead of giving the dictionary itself, you just need to give values corresponding to the expected keys.