当前位置:   article > 正文

报错AttributeError: Can‘t get attribute ‘GELUActivation‘ on <module ‘transformers.activations‘ from原因_attributeerror: can't get attribute 'geluactivatio

attributeerror: can't get attribute 'geluactivation' on
报错

使用torch.load()方法加载自己训练保存的模型时报错,详细错误信息如下:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_18208\466081345.py in <module>
----> 1 model = torch.load("../user_data/model_data/bert_0.pth")
      2 print(model)

F:\Anaconda3\envs\pytorch37\lib\site-packages\torch\serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    710                     opened_file.seek(orig_position)
    711                     return torch.jit.load(opened_file)
--> 712                 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
    713         return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
    714 
F:\Anaconda3\envs\pytorch37\lib\site-packages\torch\serialization.py in _load(zip_file, map_location, pickle_module, pickle_file, **pickle_load_args)
   1044     unpickler = UnpicklerWrapper(data_file, **pickle_load_args)
   1045     unpickler.persistent_load = persistent_load
-> 1046     result = unpickler.load()
   1047 
   1048     torch._utils._validate_loaded_sparse_tensors()

F:\Anaconda3\envs\pytorch37\lib\site-packages\torch\serialization.py in find_class(self, mod_name, name)
   1037                     pass
   1038             mod_name = load_module_mapping.get(mod_name, mod_name)
-> 1039             return super().find_class(mod_name, name)
   1040 
   1041     # Load the data (which may in turn use `persistent_load` to load tensors)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

主要错误

AttributeError: Can't get attribute 'GELUActivation' on <module 'transformers.activations' from 'F:\\Anaconda3\\envs\\pytorch37\\lib\\site-packages\\transformers\\activations.py'>
  • 1
出现的原因可能是因为训练时用到的transfromers与加载时transfromers的版本不同或者存在差异

参考问题:AttributeError: Can’t get attribute ‘LearnedPositionalEmbedding’ on <module ‘transformers.models.bart.modeling_bart’ from…

我的问题在于:我训练时是在远程gpu上运行的,与我本地环境存在差异,所以只要都在远程gpu上操作就行了。

换句话说要保证训练保存模型的环境加载模型的环境一致。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/622360
推荐阅读
相关标签