conda环境下cannot import name ‘dispatch_model‘ from ‘accelerate‘ 问题解决

1 程序运行报错的错误输出

错误信息显示如下:

File "D:\git\voice-transeformer\text\ty_pinyin.py", 
line 9, in  from bert import TTSProsody File "D:\git\voice-transeformer\bert\__init__.py",
line 1, in  from .ProsodyModel import TTSProsody File "D:\git\voice-transeformer\bert\ProsodyModel.py", 
line 7, in  from transformers import BertModel, BertConfig, BertTokenizer File "", 
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 问题分析与解决

从报错信息来看,大概率是transformers与accelerate的版本不匹配的所致,更新两个组件的版本如下:

pip install transformers==4.28.1

pip install accelerate==0.20.3

再次运行程序,不再报错,问题解决。

你可能感兴趣的:(AI运行环境,conda,transeformer,accelerate)