Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 365
Spartan 332 Avatar asked Mar 11 '21 21:03

Spartan 332


2 Answers

Change the torch version in colab by running this command

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

like image 197
Yashwanth Reddy Avatar answered Oct 02 '22 13:10

Yashwanth Reddy


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

!pip install transformers
like image 27
Prateek Saxena Avatar answered Oct 02 '22 14:10

Prateek Saxena