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

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

我正在尝试在 jupyter Notebook 中发布此声明。

from transformers import BertForQuestionAnswering

我收到错误:

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)

这是完整的堆栈:

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)

您需要将转换器包更新到最新版本。你可以通过运行这个代码来实现它:

!pip install transformers==4.11.3.

对我来说,更新后没有报错。请参阅这些链接 official resource and this