16

I am working on a machine learning project on Google Colab, it seems recently there is an issue when trying to import packages from transformers. The error message says:

ImportError: cannot import name 'SAVE_STATE_WARNING' from 'torch.optim.lr_scheduler' (/usr/local/lib/python3.7/dist-packages/torch/optim/lr_scheduler.py)

The code is simple as follow:

!pip install transformers==3.5.1

from transformers import BertTokenizer

So far I've tried to install different versions of the transformers, and import some other packages, but it seems importing any package with:

from transformers import *Package

is not working, and will result in the same error. I wonder if anyone is running into the same issue as well? Screenshot of the error

Spartan 332
  • 221
  • 1
  • 2
  • 4

5 Answers5

19

Change the torch version in colab by running this command

!pip install torch==1.4.0. Then, It worked for me.

2

Just change the version of tranformers to the latest one (4.5.1 at this time). That worked in colab.

!pip install transformers
Buddy Bob
  • 5,829
  • 1
  • 13
  • 44
2

The same issue occurred to me with the PyTorch version after being upgraded. As for the solution downgrade Pytorch version to 1.4.0.

Use the below command to install


!pip install -q torch==1.4.0 -f https://download.pytorch.org/whl/cu101/torch_stable.html

It's solved a lot of problems with transformers also.

piet.t
  • 11,718
  • 21
  • 43
  • 52
udara vimukthi
  • 168
  • 1
  • 8
0

The above from udara vimukthi worked for me after trying a lot of different things, trying to get the code for "Getting started with Google BERT" to work after cloning the gitHub repository locally, so now ALL of the chapter code works while I'm showing my daughter the models.

Operating system - Windows. Running locally with GPU support, using Anaconda environment.

pip install -q --user torch==1.4.0 -f https://download.pytorch.org/whl/cu101/torch_stable.html

then I ran into some more issues and had to install the ipwidgets

pip install ipywidgets

Now it all works, as far as I've gotten. Thanks for the help with the above suggestion it saved me a lot of headaches. :)

0

Considering you have transformers installed and still its not working.

Go to menu and click

Runtime -> Restart runtime

Rerunning script after this worked for me.

shubham chouhan
  • 580
  • 7
  • 8