How to cache Pytorch models for use when not connected to the internet?
I'm using vgg19 in a classification problem. I have access to the campus research computer to train on, but the nodes where the computation is done don't have access to the internet. So running a line of code like self.net = models.vgg19(pretrained=True) fails with the error urllib.error.URLError: &lt;urlopen error [Errno 101] Network is unreachable&gt;

Is there a way I could cache the model on the head node (where I have internet access), and load the model from the cache instead of the internet on the compute node?

If you just save the weights of pretrained networks somewhere, you can load them just like you can load any other network weights.

Saving:

import torchvision

#  I am assuming we have internet access here
model = torchvision.models.vgg16(pretrained=True)
torch.save(model.state_dict(), "Somewhere")


Loading:

import torchvision

def create_vgg16(dict_path=None):
    model = torchvision.models.vgg16(pretrained=False)
    if (dict_path != None):
        model.load_state_dict(torch.load(dict_path))
    return model

model = create_vgg16("Somewhere")

