Dear community,
I am working in the field of deploying PyTorch models. Our customers provide us models which have been jit.scipt(...)-ed and saved as *.pt files. This is the common model exchange interface they have defined for us.
The “unholy” thing that I’m trying to achieve now is to concatenate two such scripted models in form of RecursiveScriptModules.
model1 = torch.jit.load('customer_model1.pt')
model2 = torch.jit.load('customer_model2.pt')
print(type(model1) # Gives me <class 'torch.jit._script.RecursiveScriptModule'>
print(type(model2) # Gives me <class 'torch.jit._script.RecursiveScriptModule'>
# ???
The questions is whether I can somehow concatenate these two models? Every idea is highly appreciated…
Edit: maybe a side note: we use the models only for inference
Would you like to “concatenate” them such that the output of model1 would be passed to model2 in a sequential way? If so, then you might be able to create a new custom nn.Module, use both of the scripted models there, and script the new “parent model” again (if needed).
Let me know, if I misunderstood your question.
Dear @ptrblck,
thank you for your answer, yes that is exactly what I would like to achieve. However, I’m not sure how to convert even a single RecursiveScriptModule into an nn.Module without it’s original class definition available. I’d highly appreciate some hints please