It's possible to send the Pytorch model file by (from official guide)
model = SomeModel()
torch.save(model, PATH)
# Model class must be defined somewhere
model = torch.load(PATH)
model.eval()
However, if through network with following assumptions (which is a quite common scenario I think)
- assume I am sending this model using a sender Python program and want to load it in a receiver Python program
SomeModel
is defined on sender program but not on receiver- receiver could not know this model in advance so that we could not define it before receiver program starts
In this case, this load method on the receiver side could not work (under the hood it is using pickle and it requires the class def is on both sides)
So how to send a model through network to another python program which does not have the model class def, but we can still load it there.