Scott Bing
Scott Bing

Reputation: 125

ImportError: cannot import name 'SAVE_STATE_WARNING' from 'torch.optim.lr_scheduler'

I am attempting to issue this statement in a jupyter Notebook.

from transformers import BertForQuestionAnswering

I get the error:

ImportError: cannot import name 'SAVE_STATE_WARNING' from 'torch.optim.lr_scheduler' (C:\Users\sbing.conda\envs\Tensorflow\lib\site-packages\torch\optim\lr_scheduler.py)

Here is the complete stack:

ImportError Traceback (most recent call last) in ----> 1 from transformers import BertForQuestionAnswering

~.conda\envs\Tensorflow\lib\site-packages\transformers_init_.py in 624 625 # Trainer --> 626 from .trainer import Trainer 627 from .trainer_pt_utils import torch_distributed_zero_first 628 else:

~.conda\envs\Tensorflow\lib\site-packages\transformers\trainer.py in 67 TrainerState, 68 ) ---> 69 from .trainer_pt_utils import ( 70 DistributedTensorGatherer, 71 SequentialDistributedSampler,

~.conda\envs\Tensorflow\lib\site-packages\transformers\trainer_pt_utils.py in 38 SAVE_STATE_WARNING = "" 39 else: ---> 40 from torch.optim.lr_scheduler import SAVE_STATE_WARNING 41 42 logger = logging.get_logger(name)

ImportError: cannot import name 'SAVE_STATE_WARNING' from 'torch.optim.lr_scheduler' (C:\Users\sbing.conda\envs\Tensorflow\lib\site-packages\torch\optim\lr_scheduler.py)

Upvotes: 1

Views: 3594

Answers (1)

koushik
koushik

Reputation: 46

You need to update the transformer package to the latest version. You can achieve it by running this code:

!pip install transformers==4.11.3.

For me, there is no error after updating. Refer to these links official resource and this

Upvotes: 3

Related Questions