failed to load binary files saved from nightly build in version 1.5

🐛 Bug

I am using both PyTorch 1.5 (stable) and nightly build (1.6.0.dev20200611).
Sometimes I need to run code in v1.5 and use files saved by torch.save from the nightly build.
However, PyTorch 1.5 fails to torch.load such files.

To Reproduce

Steps to reproduce the behavior:

  • PyTorch nightly
import torch
a = torch.randn(1)
torch.save(a, 'a.pt')
  • PyTorch 1.5
import torch
torch.load('a.pt')

Then it shows the following error message

Traceback (most recent call last):
File “”, line 1, in
File “/home/seungjun/local/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/serialization.py”, line 586, in load
with _open_zipfile_reader(f) as opened_zipfile:
File “/home/seungjun/local/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/serialization.py”, line 246, in init
super(_open_zipfile_reader, self).init(torch.C.PyTorchFileReader(name_or_buffer))
RuntimeError: version
<= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at /opt/conda/conda-bld/pytorch_1587428266983/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.

Expected behavior

I expect PyTorch 1.5 to load files without error.
Current behavior could be due to the update in PyTorchFileReader but I assume 1.5 and 1.6 should be compatible as their version number is close to each other.

Environment

Loading:

  • PyTorch Version (e.g., 1.0): 1.5.0
  • OS (e.g., Linux): Ubuntu 18.04.4 LTS
  • How you installed PyTorch (conda, pip, source): conda
  • Build command you used (if compiling from source):
    conda install pytorch torchvision cudatoolkit=10.2 -c pytorch
  • Python version: 3.7
  • CUDA/cuDNN version: 10.2.89, 7.6.5

Saving:

  • PyTorch Version (e.g., 1.0): 1.6.0.dev20200611 for saving
  • OS (e.g., Linux): Ubuntu 18.04.4 LTS
  • How you installed PyTorch (conda, pip, source): conda
  • Build command you used (if compiling from source):
    conda install pytorch torchvision cudatoolkit=10.2 -c pytorch-nightly
  • Python version: 3.8
  • CUDA/cuDNN version: 10.2.89, 7.6.5

cc @ezyang @gchanan @zou3519

1 possible answer(s) on “failed to load binary files saved from nightly build in version 1.5

  1. The serialization in 1.6 uses a different format that should be load-able in 1.5 if not for that version check assert you are hitting. But regardless, you can use the old serialization format by doing

    torch.save(a, 'a.pt', _use_new_zipfile_serialization=False)