Fix PytorchStreamReader failed reading zip archive: failed finding central directory – PyTorch Tutorial

By | February 13, 2023

When we are using torch.load() to load some variables or torch model, we may get this error: PytorchStreamReader failed reading zip archive: failed finding central directory. In this tutorial, we will introduce you how to fix it.

If you plan to know how to save or load a torch model, you can read:

Save and Load Model in PyTorch: A Completed Guide – PyTorch Tutorial

This error looks like below:

fix PytorchStreamReader failed reding zip archive

In order to fix this error, we should add _use_new_zipfile_serialization=False when using torch.save()

For example:

torch.save(spec, spec_filename, _use_new_zipfile_serialization=False)

Then, we can use torch.load() as follows:

spec = torch.load(spec_filename)

Finally, we will find this error is fixed.