question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Re-upload weights for old model with new serialization

See original GitHub issue

Some of the oldest models we have (including resnets) have been serialized with a legacy format which, while is mostly compatible with the current code, has some corner cases that do not work as expected anymore, see https://github.com/pytorch/pytorch/issues/31615 (basically, if the data is in a BytesIO object it doesn’t work).

Here is a snippet to reproduce the problem:

import urllib.request
import io

url = 'https://download.pytorch.org/models/resnet50-19c8e357.pth'
path = './tmp.pth'
urllib.request.urlretrieve(url, path)

with open(path, "rb") as fd:
    buf = io.BytesIO(fd.read())
    
state_dict = torch.load(buf, "cpu")

This fails. We should re-save those weights and re-upload them (while keeping the old files around for BC) and update the paths in the model files to use the new files. This code re-downloads the old files and re-serializes it with the new format

import urllib.request
import io

url = 'https://download.pytorch.org/models/resnet18-5c106cde.pth'
path = './tmp.pth'
urllib.request.urlretrieve(url, path)

torch.save(torch.load(path), path)

with open(path, "rb") as fd:
    buf = io.BytesIO(fd.read())

state_dict = torch.load(buf, "cpu")

One thing to keep in mind is if changing the default weights files (while being equivalent to the old models) won’t bring unexpected changes / issues to some users, as it will trigger a re-download of the file, which might fail because of many reasons (the server doesn’t have access to internet, files have been manually downloaded, etc).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
NicolasHugcommented, Mar 17, 2021

For ref, the following classifications model urls raise an UnpicklingError:

  • resnet34-333f7ec4.pth
  • alexnet-owt-4df8aa71.pth
  • squeezenet1_0-a815701f.pth
  • resnet152-b121ed2d.pth
  • squeezenet1_1-f364aa15.pth
  • resnet50-19c8e357.pth
  • resnet101-5d3b4d8f.pth
  • resnet18-5c106cde.pth
0reactions
BIGBALLONcommented, Jul 19, 2021

Thanks, @NicolasHug, the new weight can be loaded!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Saving and serializing models
The first part of this guide covers saving and serialization for Sequential models and models built using the Functional API. The saving and...
Read more >
Save your models for later with serialization
How to save and load model weights and architecture together. Keras can separate the concerns of saving your model architecture and saving your...
Read more >
Bubbet's Placeholder Mod(old) - Cosmoteer Official Forum
I get this message when i try to download it. Error loading mod bubbet.placeholdermod-0.0.5-2: System.IO.FileNotFoundException: Could not find file ...
Read more >
Make Y-Axis Inversion configurable - TypeScript OctoDash - GitAnswer
... Not clear how to apply themes - JavaScript codemirror.next · Re-upload weights for old model with new serialization - Python vision ...
Read more >
Untitled
Construction of new 3 storey wing June Feb. Screenshot Twitter Video TV m IMDb RATING 7.5 K YOUR RATING Rate POPULARITY Play trailer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found