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

报错

使用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)

主要错误

AttributeError: Can't get attribute 'GELUActivation' on 

出现的原因可能是因为训练时用到的transfromers与加载时transfromers的版本不同或者存在差异

参考问题:AttributeError: Can’t get attribute ‘LearnedPositionalEmbedding’ on

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

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

你可能感兴趣的:(pytorch,深度学习,python)