MadryLab / robustness

A library for experimenting with, training and evaluating neural networks, with a focus on adversarial robustness.
MIT License
903 stars 181 forks source link

import load_state_dict_from_url from torch.hub #106

Closed kaczmarj closed 2 years ago

kaczmarj commented 2 years ago

This replaces

from torchvision.models.utils import load_state_dict_from_url

with

from torch.hub import load_state_dict_from_url

Recent versions of torchvision no longer have that namespace, and a ModuleNotFoundError is raised.

I considered using a try-except block to try loading from one of those imports and then fallback to the other import. But I chose not to do that because other files already use the torch.hub.load_state_dict_from_url function. Those lines were added 2 years ago (eg https://github.com/MadryLab/robustness/commit/52a345bd46e09fc1f79a926048a40d6bf150618d). Because the torch.hub namespace has been used in other parts of the project for so long, it seems reasonable to me to simply replace torchvision.models.utils with torch.hub.

andrewilyas commented 2 years ago

Thanks!

cassidylaidlaw commented 2 years ago

@andrewilyas would it be possible to release a new version of the package on PyPI with this fix? Otherwise, the package can't be installed via PyPI for torchvision >=0.11.

kaczmarj commented 2 years ago

@cassidylaidlaw - i agree that a new version should be uploaded but in the meantime you can install the project from github

pip install https://github.com/MadryLab/robustness/tarball/4033befe273b29f7b6dc36c30aa40696ed8fae96

that url returns a .tar.gz file of the repository at the latest commit (4033befe273b29f7b6dc36c30aa40696ed8fae96), and pip can install that.