Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError("{} is a zip archive (did you mean to use torch.jit.load()?)".format(f.name)) when loading model weights #43766

Closed
feiyangsuo opened this issue Aug 28, 2020 · 8 comments
Labels
oncall: jit Add this issue/PR to JIT oncall triage queue
Projects

Comments

@feiyangsuo
Copy link

feiyangsuo commented Aug 28, 2020

I'm using pytorch 1.5. There's a weight file "best.pt" which is trained within pytorch 1.6. When I try to load the weights the error raises as RuntimeError: best.pt is a zip archive (did you mean to use torch.jit.load()?).

The file can be naomally loaded in pytorch 1.6 using torch.load().

It doesn't work if I use torch.jit.load() to load the file. In this circumstance there's another error: RuntimeError: version_number <= kMaxSupportedFileFormatVersion ASSERT FAILED at ..\caffe2\serialize\inline_container.cc:131, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 1. Your PyTorch installation may be too old. (init at ..\caffe2\serialize\inline_container.cc:131) (no backtrace available)

I followed this conversation which suggests to manually implement is_zipfile, but the new function still judges "best.pt" as a zip file. In debug mode I saw it's true that the "magic number" appears in the first 4 bytes. So does it mean that this weight file is truely a zip file?

Then I wonder if the problem is caused by version confliction? Like, I should upgrade my pytorch version to 1.6 so that the problem is naturally gone?

cc @gmagogsfm

@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Aug 28, 2020
@github-actions github-actions bot added this to Need triage in JIT Triage Aug 28, 2020
@gmagogsfm
Copy link
Contributor

Hi feiyangsuo,

You are right that it is indeed a zip file. See PyTorch 1.6 release notes about the change (search for "zip" in the linked webpage). I would suggest upgrading to 1.6 and the issue should be gone. If that's not the case, please update the bug and we will investigate. Or if you have reasons to not upgrade to 1.6, let us know and we will see what we can do.

Thanks,

@feiyangsuo
Copy link
Author

@ gmagogsfm
Thanks, that's the case. :)

@Lilyjjo
Copy link
Contributor

Lilyjjo commented Aug 31, 2020

good to hear! :)

@Lilyjjo Lilyjjo closed this as completed Aug 31, 2020
JIT Triage automation moved this from Need triage to Done Aug 31, 2020
@YangAzure
Copy link

I have an exactly same issue, except that my model is trained on torch version 1.6.0, and I tried to load in version 1.6.0 as well. Requesting for an reopen.

RuntimeError: ./model.bin is a zip archive (did you mean to use torch.jit.load()?)

Triggered by

model = torch.load("./model.bin"))

@brando90
Copy link

Hi feiyangsuo,

You are right that it is indeed a zip file. See PyTorch 1.6 release notes about the change (search for "zip" in the linked webpage). I would suggest upgrading to 1.6 and the issue should be gone. If that's not the case, please update the bug and we will investigate. Or if you have reasons to not upgrade to 1.6, let us know and we will see what we can do.

Thanks,

@gmagogsfm

I cannot update due to hardware reasons (using ibm ppc64le architecture).

What is the solution?

@anbai106
Copy link

anbai106 commented Jan 28, 2021

I have the same issue with 1.7.0 by using torch.save and torch.load.
Do not we have option to specify which format to read, pickle or zip, when using torch.load?

The error message suggests to use torch.jit.load(), but this function does not exist in 1.7.0.

Any updates?

@Dawn-LX
Copy link

Dawn-LX commented Oct 11, 2022

pytorch1.6 and later change the save file to zip file, you can use a higher version (>=1.6) to load the weight.pt and re-save by using _use_new_zipfile_serialization=False

import torch
state_dict = torch.load('model_weight.pt', map_location="cpu")
torch.save(state_dict, 'model_weight.pt', _use_new_zipfile_serialization=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
oncall: jit Add this issue/PR to JIT oncall triage queue
Projects
JIT Triage
  
Done
Development

No branches or pull requests

8 participants