attributeError:can can get属性' geluactivation' on lt;模块'变形金刚。来自' c:\ ...变形金刚\ activations.py'>

发布于 2025-02-07 05:06:18 字数 2677 浏览 2 评论 0原文

我使用拥抱面模型训练了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文