AttributeError:无法从'xxx/torch/\u C.cpython37mx86\u 64linuxgnu.so'>'获取<module'torch.\u C'上的属性'\u VariableFunctionClass'

2024-09-28 22:30:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我训练了一个模型,并把它和pickle放在一起。但是当我尝试在另一个ubuntu上加载它时,它显示了错误

AttributeError: Can't get attribute '_VariableFunctionClass' on <module 'torch._C' from 'xxx/torch/_C.cpython-37m-x86_64-linux-gnu.so'>' 

我尝试了以下方法,但不起作用:

    class CustomUnpickler(pickle.Unpickler):

    def find_class(self, module, name):
        try:
            return super().find_class(__name__, name)
        except AttributeError:
            return super().find_class(module, name)

pickle_data = CustomUnpickler(open(path, 'rb')).load()

我还尝试了用cpu训练的pickle,它不会触发那个错误。所以我想知道是否是GPU依赖性导致了这个问题

提前谢谢


Tags: name模型getreturnubuntu错误torchfind