0

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.

Litchy
  • 623
  • 7
  • 23
  • 1
    Maybe this will help you ([Saving PyTorch model with no access to model class code](https://stackoverflow.com/questions/59287728/saving-pytorch-model-with-no-access-to-model-class-code)). – won5830 Jul 20 '22 at 03:59
  • @won5830 this is an eligible solution, I tried and it works! You can kindly add an answer of this. – Litchy Jul 21 '22 at 07:24

0 Answers0