Transformer: Error importing packages. "ImportError: cannot import name 'SAVE_STATE_WARNING' from 'torch.optim.lr_scheduler'"

Viewed 25426

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

4 Answers

Change the torch version in colab by running this command

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

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

!pip install transformers

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.

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. :)

Related