The problem of cannot import name 'dispatch_model' from 'accelerate' in conda environment is solved

1 The error output of the program running error report

The error message is displayed as follows:

File "D:\git\voice-transeformer\text\ty_pinyin.py", 
line 9, in <module> from bert import TTSProsody File "D:\git\voice-transeformer\bert\__init__.py",
line 1, in <module> from .ProsodyModel import TTSProsody File "D:\git\voice-transeformer\bert\ProsodyModel.py", 
line 7, in <module> from transformers import BertModel, BertConfig, BertTokenizer File "<frozen importlib._bootstrap>", 
line 1032, in _handle_fromlist File "C:\Users\lishu\anaconda3\envs\pt\lib\site-packages\transformers\utils\import_utils.py", 
line 1137, in __getattr__ value = getattr(module, name) File "C:\Users\lishu\anaconda3\envs\pt\lib\site-packages\transformers\utils\import_utils.py", 
line 1136, in __getattr__ module = self._get_module(self._class_to_module[name]) File "C:\Users\lishu\anaconda3\envs\pt\lib\site-packages\transformers\utils\import_utils.py", line 1151, in _get_module ) from e RuntimeError: Failed to import transformers.models.bert.modeling_bert because of the following error (look up to see its traceback): cannot import name 'dispatch_model' from 'accelerate' (C:\Users\lishu\anaconda3\envs\pt\lib\site-packages\accelerate\__init__.py) Process finished with exit code 1

2 Problem analysis and solution

Judging from the error message, the high probability is that the versions of transformers and accelerate do not match. Update the versions of the two components as follows:

pip install transformers==4.28.1

pip install accelerate==0.20.3

Run the program again, no error is reported, and the problem is solved.

Guess you like

Origin blog.csdn.net/lsb2002/article/details/131601986
Recommended