无法在Pytorch 1.5.1中加载使用Pytorch 1.6.0训练的模型。

5

我最近在本地机器上将Pytorch版本升级到1.6.0,以使用混合精度训练,自那时以来,我一直遇到这个问题,我尝试了这里提到的解决方法,但仍然出现以下错误。

RuntimeError: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at /opt/conda/conda-bld/pytorch_1591914880026/work/caffe2/serialize/inline_container.cc:132, please report a bug to PyTorch. Attempted to read a PyTorch file with version 4, but the maximum supported version for reading is 3. Your PyTorch installation may be too old.

复现链接:https://www.kaggle.com/rohitsingh9990/error-reproducing-code?scriptVersionId=37468859

非常感谢您的任何帮助。


2
一种解决方法是在新版本的PyTorch中使用torch.load,然后重新保存时使用_use_new_zipfile_serialization=False - dashesy
1个回答

0

torch.__version__ == 1.6.0 中:

torch.save(model_.state_dict(), 'best_model.pth.tar', use_new_zipfile_serialization=False)

然后在 torch.__version__ == 1.5.1 中:

torch.load('best_model.pth.tar',map_location='cpu')


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接