attributeError:can can get属性' geluactivation' on lt;模块'变形金刚。来自' c:\ ...变形金刚\ activations.py'>
我使用拥抱面模型训练了Parsbert模型,并将模型保存为“权重”。 pt'在Google合作中。我在合作中加载了权重,它运行良好,但是当我使用Pycharm加载模型并查看结果时,出现了上述错误。
parsebert模型
from transformers import AutoConfig, AutoTokenizer, AutoModel, TFAutoModel
# model_name_or_path = "HooshvareLab/bert-fa-base-uncased"
model_name_or_path = "HooshvareLab/bert-fa-zwnj-base"
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
bert = AutoModel.from_pretrained(model_name_or_path)
我的错误
Traceback (most recent call last):
File "C:.....\site-packages\flask\app.py", line 2091, in __call__
return self.wsgi_app(environ, start_response)
File "C:.....\python\Lib\site-packages\flask\app.py", line 2076, in wsgi_app
response = self.handle_exception(e)
File "C:.....\python\Lib\site-packages\flask\app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "C:.....\python\Lib\site-packages\flask\app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:.....\python\Lib\site-packages\flask\app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "C:.....\python\Lib\site-packages\flask\app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "C:\My_file\Collegue Project\bert\pycharm_exe\content\project\gui.py", line 136, in get_bot_response
result = get_response(message=userText, model_path=model_path,
File "C:\My_file\Collegue Project\bert\pycharm_exe\content\project\prediction.py", line 51, in get_response
intent = get_prediction(message, model_path, df_path)
File "C:\My_file\Collegue Project\bert\pycharm_exe\content\project\prediction.py", line 17, in get_prediction
model = torch.load(model_path, map_location ='cpu')
File "C:.....\python\Lib\site-packages\torch\serialization.py", line 607, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "C:.....\python\Lib\site-packages\torch\serialization.py", line 882, in _load
result = unpickler.load()
File "C:.....\python\Lib\site-packages\torch\serialization.py", line 875, in find_class
return super().find_class(mod_name, name)
AttributeError: Can't get attribute 'GELUActivation' on <module 'transformers.activations' from 'C:\\....\\python\\lib\\site-packages\\transformers\\activations.py'>
consop 中的工具版本:
python:3.7.13
pytorch:1.11.0+cu113
变形金刚:4.19.4
版本本地中的工具:
Python:3.9.8
Pytorch:1.10.1+CPU
变形金刚:4.12.5
I trained the ParsBERT model using HuggingFace models and saved the model as 'weights. pt' in google collab. I loaded the weights in collab and it worked fine but while I used Pycharm to load the model and see the results, the above error appeared.
ParseBERT model
from transformers import AutoConfig, AutoTokenizer, AutoModel, TFAutoModel
# model_name_or_path = "HooshvareLab/bert-fa-base-uncased"
model_name_or_path = "HooshvareLab/bert-fa-zwnj-base"
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
bert = AutoModel.from_pretrained(model_name_or_path)
My error
Traceback (most recent call last):
File "C:.....\site-packages\flask\app.py", line 2091, in __call__
return self.wsgi_app(environ, start_response)
File "C:.....\python\Lib\site-packages\flask\app.py", line 2076, in wsgi_app
response = self.handle_exception(e)
File "C:.....\python\Lib\site-packages\flask\app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "C:.....\python\Lib\site-packages\flask\app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:.....\python\Lib\site-packages\flask\app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "C:.....\python\Lib\site-packages\flask\app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "C:\My_file\Collegue Project\bert\pycharm_exe\content\project\gui.py", line 136, in get_bot_response
result = get_response(message=userText, model_path=model_path,
File "C:\My_file\Collegue Project\bert\pycharm_exe\content\project\prediction.py", line 51, in get_response
intent = get_prediction(message, model_path, df_path)
File "C:\My_file\Collegue Project\bert\pycharm_exe\content\project\prediction.py", line 17, in get_prediction
model = torch.load(model_path, map_location ='cpu')
File "C:.....\python\Lib\site-packages\torch\serialization.py", line 607, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "C:.....\python\Lib\site-packages\torch\serialization.py", line 882, in _load
result = unpickler.load()
File "C:.....\python\Lib\site-packages\torch\serialization.py", line 875, in find_class
return super().find_class(mod_name, name)
AttributeError: Can't get attribute 'GELUActivation' on <module 'transformers.activations' from 'C:\\....\\python\\lib\\site-packages\\transformers\\activations.py'>
Version of tools in Collab:
Python: 3.7.13
PyTorch: 1.11.0+cu113
Transformers: 4.19.4
Version of tools in local:
Python: 3.9.8
Pytorch: 1.10.1+cpu
Transformers: 4.12.5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论