My goal is simply to load a
.pt model saved in Python into a
nn::Module in libtorch. Is this impossible to do programmatically?
I work on a libtorch-based application in which I can load HDF5 models from Keras. Since the HDF5 contains both the network graph (as a json string) and the weights, I can programmatically construct the
nn::Module and populate its trainable parameters. All without going through any format conversion! And, ironically, I cannot do the same with a model saved from Pytorch itself in python?
Am I correct in concluding that I must use
jit::script::Module instead for that task, and that there’s no conversion between that and
nn::Module? Can any Pytorch dev explain why not go the much easier route used by Keras to save/load models, toss
jit::script altogether and keep only
@ptrblck , @glaringlee , @tom , @yf225 : please help out here! I’ve struggled with this issue for months, and any pointer will be greatly appreciated. Thanks!
Please don’t tag specific users as it can be demotivating for others to answer your question and you might also tag users unfamiliar with your use case.
Also, this seems to be a double post from here, where other users are already responding, or what is the difference between these topics?
Thank you, @ptrblck Won’t tag specific users in the future. The reason I did is because I’m interested specifically in feedback from Pytorch developers regarding this design decision, and ways to work around it. In particular, the question is:
Is it impossible to load a python model directly into
nn::Module? If so, why did you guys decide to go this way, and develop an orthogonal API for it (