Is it possible to instantiate a model from its repr output?

I wonder is it possible to instantiate a model from its repr output in Pytprch?

No. It might work if its only classes from the standard library (they (roughly?) advertise the parameters you could instantiate them with), but the moment you have anything custom, the lack of code for the forward would seem to hit you. You would need the state dict, too.
Currently the main way to save models with complete information is via the JIT. If you stare down the git tree hard enough, you see that something is in the works that would allow to save models with source code and data, but it’s not ready yet, i.e. the state is described as follows and it won’t be in PyTorch 1.7:

This module is a prototype and should not be used for anything real. The
APIs and package format are subject to change without warning. Issues filed
against this module may not receive support.

Best regards

Thomas

1 Like

Thanks a lot tom. really appreciate it. Yes I know about the jit. but this is a pruned model, so I was kind of searching to see if I could avoid a retraining from scratch or manually creating a custom model definition for it.